$ErrorActionPreference = 'Stop'

$root = Split-Path -Parent $PSScriptRoot
$php = Join-Path $root 'runtime\php\php.exe'

$env:CIOT_PROVIDER_TOKEN = if ($env:CIOT_PROVIDER_TOKEN) { $env:CIOT_PROVIDER_TOKEN } else { 'token-homologacao-local' }
$env:CIOT_ENV = if ($env:CIOT_ENV) { $env:CIOT_ENV } else { 'homologation' }
$env:CIOT_HOMOLOGATION_URL = if ($env:CIOT_HOMOLOGATION_URL) { $env:CIOT_HOMOLOGATION_URL } else { 'http://127.0.0.1:8081/api/v1' }
$apiPort = if ($env:CIOT_API_PORT) { $env:CIOT_API_PORT } else { '8090' }

Write-Host "API CIOT: http://127.0.0.1:$apiPort"
Write-Host 'Ambiente:' $env:CIOT_ENV
Write-Host 'Homologacao URL:' $env:CIOT_HOMOLOGATION_URL

& $php -S "127.0.0.1:$apiPort" -t (Join-Path $root 'public') (Join-Path $root 'public\index.php')
