# Test script to verify no EF Core warnings
Write-Host "Starting API to check for EF Core warnings..." -ForegroundColor Cyan

$apiProcess = Start-Process -FilePath "dotnet" `
    -ArgumentList "run --project C:\Users\yaoji\git\ColaCoder\product-master\colaflow-api\src\ColaFlow.API\ColaFlow.API.csproj" `
    -WorkingDirectory "C:\Users\yaoji\git\ColaCoder\product-master\colaflow-api" `
    -RedirectStandardOutput "api-output.log" `
    -RedirectStandardError "api-errors.log" `
    -PassThru `
    -NoNewWindow

Write-Host "Waiting 15 seconds for API to start..." -ForegroundColor Yellow
Start-Sleep -Seconds 15

# Check for warnings
$warnings = Select-String -Path "api-errors.log" -Pattern "(ProjectId1|EpicId1|StoryId1|shadow state.*conflicting)" -Context 1,1

if ($warnings) {
    Write-Host "`nERROR: EF Core warnings found!" -ForegroundColor Red
    $warnings | ForEach-Object { Write-Host $_.Line -ForegroundColor Red }
    $exitCode = 1
} else {
    Write-Host "`nSUCCESS: No EF Core warnings found!" -ForegroundColor Green
    $exitCode = 0
}

# Stop API
Stop-Process -Id $apiProcess.Id -Force
Write-Host "`nAPI stopped." -ForegroundColor Cyan

# Show last 20 lines of logs
Write-Host "`nLast 20 lines of error log:" -ForegroundColor Yellow
Get-Content "api-errors.log" -Tail 20

exit $exitCode
