<#
.SYNOPSIS
    Zoth Studio PowerShell Entrypoint (Windows 10/11)
#>
[CmdletBinding()]
param(
    [switch]$Hub,
    [switch]$Help,
    [switch]$Version
)

$AppDir = $PSScriptRoot
$env:PYTHONPATH = "$AppDir\orchestrator;$env:PYTHONPATH"

Write-Host "============================================================" -ForegroundColor Cyan
Write-Host "⚡ ZOTH STUDIO v2.6.0 (Windows Edition)" -ForegroundColor Cyan
Write-Host "Local-First Sovereign AI Agent Stack & WebGL Omniverse" -ForegroundColor DarkGray
Write-Host "============================================================" -ForegroundColor Cyan

if ($Help) {
    Write-Host "Usage:" -ForegroundColor Yellow
    Write-Host "  .\zoth.ps1         # Launch Operator Deck (:8484)"
    Write-Host "  .\zoth.ps1 -Hub    # Launch Operator Deck and Public Hub (:8088)"
    exit 0
}

if ($Version) {
    Write-Host "zoth-studio 2.6.0 (Windows x86_64)" -ForegroundColor Green
    exit 0
}

$pythonCmd = if (Get-Command python -ErrorAction SilentlyContinue) { "python" } elseif (Get-Command py -ErrorAction SilentlyContinue) { "py" } else { $null }

if (-not $pythonCmd) {
    Write-Error "Python 3 was not found on this system. Please install Python 3.10+ from https://python.org/"
    exit 1
}

Write-Host "✓ Python runtime located: $pythonCmd" -ForegroundColor Green
Write-Host "🚀 Launching Operator Deck on http://127.0.0.1:8484/..." -ForegroundColor Cyan
Start-Process "http://127.0.0.1:8484/"

if ($Hub) {
    Write-Host "🌐 Launching Public Hub on http://127.0.0.1:8088/..." -ForegroundColor Cyan
    Start-Job -ScriptBlock {
        param($dir, $py)
        Set-Location $dir
        & $py -m http.server 8088 --directory "$dir\public" --bind 127.0.0.1
    } -ArgumentList $AppDir, $pythonCmd | Out-Null
    Start-Process "http://127.0.0.1:8088/"
}

& $pythonCmd "$AppDir\orchestrator\orchestrator.py" serve --host 127.0.0.1 --port 8484
