$token = Get-Content 'c:\Users\Administrator\.ssh\coolify-redbull-token'
$baseUrl = "https://redbull.rede5.com.br/api/v1"
$backendUuid = "eosgwscc4g044c884k0ws4gc"

Write-Host "Buscando deployments do backend..."
$deps = Invoke-RestMethod -Uri "$baseUrl/applications/$backendUuid/deployments?per_page=1" -Headers @{Authorization = "Bearer $token" } -Method Get

if ($deps -and $deps.Length -gt 0) {
    $lastDepId = $deps[0].deployment_uuid
    Write-Host "Ultimo deploy: $lastDepId"
    Write-Host "Status: $($deps[0].status)"
    
    # Get logs
    $logsUrl = "$baseUrl/deployments/$lastDepId"
    $logResponse = Invoke-RestMethod -Uri $logsUrl -Headers @{Authorization = "Bearer $token" } -Method Get
    Write-Host "Logs:"
    $logResponse.logs | Select-Object -Last 20
}
else {
    Write-Host "Nenhum deploy encontrado."
}
