# Test properties encryption functionality
param(
    [string]$MigrationDirectory = "C:\AxiUmDatabaseMigration"
)

# Import required modules
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$global:ScriptDirectory = $scriptDir
$global:MigrationDirectory = $MigrationDirectory

# Define mock functions for testing
function Show-Info {
    param([string]$Message, [string]$LogPrefix = "Test")
    Write-Host "INFO: $Message"
}

function Show-Warning {
    param([string]$Message, [string]$LogPrefix = "Test")
    Write-Host "WARNING: $Message"
}

function Show-Error {
    param([string]$Message, [string]$LogPrefix = "Test")
    Write-Host "ERROR: $Message"
}

function Show-Success {
    param([string]$Message, [string]$LogPrefix = "Test")
    Write-Host "SUCCESS: $Message"
}

function Get-HelperScriptPath {
    param([string]$ScriptFileName)
    return Join-Path $scriptDir "helper\$ScriptFileName"
}

# Import utility module
$utilityPath = Join-Path $scriptDir "helper\Helper-Utilities.psm1"
if (Test-Path $utilityPath) {
    Import-Module $utilityPath -Force
    Write-Host "Imported utility module"
} else {
    Write-Host "Warning: Helper utility module not found - using mock functions"
}

# Import encryption module
$encryptionPath = Join-Path $scriptDir "helper\Helper-Encryption.psm1"
if (Test-Path $encryptionPath) {
    Import-Module $encryptionPath -Force
    Write-Host "Imported encryption module"
} else {
    Write-Host "Error: Encryption module not found"
    exit 1
}

# Create test properties file
$testFile = Join-Path $scriptDir "test_properties.txt"
@"
ORACLE_PASSWORD=testpassword
POSTGRES_USER_PASSWORD=anotherpassword
ORACLE_TNS=test:1521/test
"@ | Out-File -FilePath $testFile -Encoding UTF8

Write-Host "Created test properties file with plaintext passwords"
Write-Host "Original file contents:"
Get-Content $testFile

# Test Read-Properties function
$script:Properties = @{}
$result = Read-Properties -PropertiesFile $testFile

Write-Host ""
Write-Host "Properties loaded into memory:"
foreach ($key in $script:Properties.Keys) {
    if ($key -match 'PASSWORD') {
        Write-Host "  $key=[DECRYPTED]"
    } else {
        Write-Host "  $key=$($script:Properties[$key])"
    }
}

Write-Host ""
Write-Host "File contents after loading (should be encrypted):"
Get-Content $testFile

# Clean up
Remove-Item $testFile -Force
Write-Host ""
Write-Host "Test completed successfully!"
