# QwenClaw Complete Startup Script (PowerShell)
# Starts both Rig service and QwenClaw daemon

$ErrorActionPreference = "Stop"

$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $ScriptDir/..

Write-Host "🐾 Starting QwenClaw with Rig Integration..." -ForegroundColor Cyan

# Start Rig service in background
Write-Host "🦀 Starting Rig service..." -ForegroundColor Yellow
Start-Process powershell -ArgumentList "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", ".\scripts\start-rig.ps1"

# Wait for Rig to start
Write-Host "⏳ Waiting for Rig service to be ready..." -ForegroundColor Yellow
Start-Sleep -Seconds 5

# Check if Rig is healthy
try {
    $response = Invoke-WebRequest -Uri "http://127.0.0.1:8080/health" -TimeoutSec 2 -UseBasicParsing
    if ($response.StatusCode -eq 200) {
        Write-Host "✅ Rig service is ready!" -ForegroundColor Green
    }
} catch {
    Write-Host "⚠️  Rig service may not be ready yet, continuing anyway..." -ForegroundColor Yellow
}

# Start QwenClaw daemon
Write-Host "🐾 Starting QwenClaw daemon..." -ForegroundColor Cyan
bun run start --web
