# ─────────────────────────────────────────────────────────────────────────────
# test_mock.ps1 — HUTAMS MOCK 오디오 시뮬레이터 테스트 스크립트
# 사용법: .\test_mock.ps1
# ─────────────────────────────────────────────────────────────────────────────

Write-Host "=================================" -ForegroundColor Cyan
Write-Host "  HUTAMS MOCK Test Mode" -ForegroundColor Cyan
Write-Host "=================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Enforcing AUDIO_SOURCE=mock in .env file and starting server."
Write-Host ""

$envFile = ".\app\.env"

if (-not (Test-Path $envFile)) {
    Write-Host "Creating new .env file." -ForegroundColor Yellow
    "LLM_ENABLED=true`nLLM_MODEL_PATH=./Qwen3.5-0.8B-Q4_K_M.gguf`nAUDIO_SOURCE=mock`nMOCK_AUDIO_PATH=./sample1.m4a" | Out-File -Encoding UTF8 $envFile
}
else {
    $content = Get-Content $envFile
    $newContent = @()
    $found = $false
    foreach ($line in $content) {
        if ($line -match "^AUDIO_SOURCE=") {
            $newContent += "AUDIO_SOURCE=mock"
            $found = $true
        }
        else {
            $newContent += $line
        }
    }
    if (-not $found) {
        $newContent += "AUDIO_SOURCE=mock"
        $newContent += "MOCK_AUDIO_PATH=./sample1.m4a"
    }
    $newContent | Out-File -Encoding ASCII $envFile -Force
    Write-Host ".env configuration applied." -ForegroundColor Green
}

Write-Host "Restarting server..." -ForegroundColor Yellow
Write-Host ""

.\run_server.ps1
