Private/Resolve-SqlSpnLogPath.ps1

# =============================================================================
# Script : Resolve-SqlSpnLogPath.ps1
# Author : Keith Ramsey
# =============================================================================
# Change Log
# -----------------------------------------------------------------------------
# 2026-05-09 Keith Ramsey Phase 2 release polish - DR-202 standard header applied.
# =============================================================================
function Resolve-SqlSpnLogPath {
    <#
    .SYNOPSIS
        Resolves the directory where SPN audit logs are written.
    .DESCRIPTION
        Precedence: explicit -Path argument > $env:SQLSPN_LOG_DIR > user-profile default.
        The directory is created on first call if it doesn't exist.
    #>

    [CmdletBinding()]
    param([string]$Path)

    $resolved = if ($Path) { $Path }
        elseif ($env:SQLSPN_LOG_DIR) { $env:SQLSPN_LOG_DIR }
        else { Join-Path $env:USERPROFILE '.sqlspnmanager\Logs' }

    if (-not (Test-Path $resolved)) {
        New-Item -ItemType Directory -Path $resolved -Force | Out-Null
    }
    return $resolved
}