Envoke.psm1

#Requires -Version 5.1
<#
.SYNOPSIS
    Module loader for Envoke.
 
.DESCRIPTION
    Dot-sources all Public and Private function files, initializes module-scoped
    state, and exports only the Public API surface.
 
.NOTES
    Author: Aaron AlAnsari
    Created: 2026-02-24
#>


# ---------------------------------------------------------------------------
# Module-scoped state initialization
# ---------------------------------------------------------------------------

# Default config — EnableDebug controls Write-EnvkLog DEBUG gate.
$script:Config = @{
    EnableDebug = $false
}

# Log file path — Windows-conventional LOCALAPPDATA location.
# Directory is created here so all consumers (Write-EnvkLog, Backup-LogFile) can assume it exists.
$script:LogFilePath = Join-Path $env:LOCALAPPDATA 'Envoke\Logs\ApplicationStartup.log'

$logDirectory = Split-Path -Path $script:LogFilePath -Parent
if (-not (Test-Path -Path $logDirectory)) {
    New-Item -ItemType Directory -Path $logDirectory -Force | Out-Null
}

# ---------------------------------------------------------------------------
# Dot-source Private functions (internal helpers, not exported)
# ---------------------------------------------------------------------------

$Private = Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') -Filter '*.ps1' -ErrorAction SilentlyContinue

foreach ($file in $Private) {
    try {
        . $file.FullName
    }
    catch {
        Write-Error "Failed to import private function file '$($file.FullName)': $_"
    }
}

# ---------------------------------------------------------------------------
# Dot-source Public functions (exported)
# ---------------------------------------------------------------------------

$Public = Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') -Filter '*.ps1' -ErrorAction SilentlyContinue

foreach ($file in $Public) {
    try {
        . $file.FullName
    }
    catch {
        Write-Error "Failed to import public function file '$($file.FullName)': $_"
    }
}

# ---------------------------------------------------------------------------
# Export only Public function names
# Phase 1 has no public functions; array will be empty.
# ---------------------------------------------------------------------------

Export-ModuleMember -Function $Public.BaseName