const DFS_LOGIN = process.env.COOLIFY_API_TOKEN;

async function checkDeployment() {
  const url = `${process.env.COOLIFY_URL}/api/v1/deployments?resource_uuid=y4cscsc8s08c8808go0448s0&per_page=1`;
  console.log(`Pinging Coolify API at ${url}...`);

  const response = await fetch(url, {
    headers: {
      "Authorization": `Bearer ${DFS_LOGIN}`
    }
  });

  const data = await response.json();
  if (data && data.length > 0) {
    const deploy = data[0];
    console.log(`\nDeployment UUID: ${deploy.deployment_uuid}`);
    console.log(`Status: ${deploy.status}`);
    console.log(`Created At: ${deploy.created_at}`);
    
    // Parse the logs array to see what it's currently doing
    try {
      const logs = JSON.parse(deploy.logs);
      if (logs && logs.length > 0) {
        console.log("\nLast 5 log lines from the build container:");
        logs.slice(-5).forEach(log => {
          console.log(`[${log.timestamp}] ${log.type}: ${log.output.substring(0, 100)}`);
        });
      }
    } catch(e) {
      console.log("Could not parse logs array.");
    }
  } else {
    console.log("No deployments found.");
  }
}
checkDeployment().catch(console.error);
