$ErrorActionPreference = "Stop"

$root = $PSScriptRoot
$envFile = Join-Path $root ".env"
$envExample = Join-Path $root ".env.example"

Push-Location $root
try {
    if (-not (Test-Path $envFile)) {
        Copy-Item $envExample $envFile
        Write-Host "[prod-local] .env not found, copied from .env.example"
    }

    Write-Host "[prod-local] starting root docker-compose.yml ..."
    docker compose up -d --build

    Write-Host ""
    Write-Host "[prod-local] stable local deployment environment"
    Write-Host "  mysql      : localhost:23306"
    Write-Host "  redis      : localhost:26379"
    Write-Host "  frontend   : http://localhost:3000"
    Write-Host "  admin-web  : http://localhost:3001"
    Write-Host "  backend    : http://localhost:28081"
    Write-Host "  swagger    : http://localhost:28081/swagger-ui/index.html"
    Write-Host ""
    Write-Host "[prod-local] if you need different ports, edit .env before running this script."
    Write-Host "[prod-local] do not run 'docker compose down -v' unless you really want to delete prod-local data."
}
finally {
    Pop-Location
}
