PowerCraft.Notion.psm1

# PowerCraft.Notion: thin PowerShell shell over the PowerCraft.Notion.Core kernel.
# The shell owns binding, confirmation and output shaping; every algorithm lives in the kernel.
# lib/ is populated by build.ps1 from the kernel build and shipped inside the module.

$script:ModuleRoot = $PSScriptRoot

$libDir = Join-Path $PSScriptRoot 'lib'
$kernelDll = Join-Path $libDir 'PowerCraft.Notion.Core.dll'
if (-not (Test-Path -LiteralPath $kernelDll)) {
    throw "PowerCraft.Notion kernel not found at '$kernelDll'. Run build.ps1 at the repository root to populate module/lib/."
}

foreach ($dll in Get-ChildItem -Path $libDir -Filter '*.dll' | Sort-Object Name) {
    try {
        Add-Type -Path $dll.FullName -ErrorAction Stop
    }
    catch {
        if ($_.Exception -is [System.IO.FileLoadException] -or $_.Exception.Message -match 'already (been )?loaded') {
            Write-Verbose "Skipped $($dll.Name): already provided by the runtime."
        }
        else {
            throw
        }
    }
}

foreach ($function in Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') -Filter '*.ps1' -ErrorAction SilentlyContinue | Sort-Object Name) {
    . $function.FullName
}
foreach ($function in Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') -Filter '*.ps1' | Sort-Object Name) {
    . $function.FullName
}

Export-ModuleMember -Function @(
    'Test-PCNotionConnection', 'Get-PCNotionPage', 'Register-PCNotionPage',
    'Approve-PCNotionSet', 'Approve-PCNotionItem', 'Revoke-PCNotionItem',
    'Sync-PCNotionSet', 'Test-PCNotionSet', 'Resolve-PCNotionPending',
    'Set-PCNotionAnchor', 'Get-PCNotionAnchor'
)