$ErrorActionPreference = 'Stop'

$root = Split-Path -Parent $PSScriptRoot
$php = Join-Path $root 'runtime\php\php.exe'
$apiRoot = Join-Path $root 'api'
$apiPort = if ($env:CIOT_API_FOLDER_PORT) { $env:CIOT_API_FOLDER_PORT } else { '8091' }

$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' }

Write-Host "API CIOT pasta /api: http://127.0.0.1:$apiPort"
Write-Host "Teste: http://127.0.0.1:$apiPort/teste.html"

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