[CmdletBinding()]
param(
    [string]$SeedHost,
    [uint16]$Port = 4001,
    [string]$Bind = "0.0.0.0",
    [switch]$Quiet
)

$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest

$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$hostExe = Join-Path $scriptRoot "ghostterm_host.exe"

if (-not (Test-Path $hostExe)) {
    throw "ghostterm_host.exe was not found next to run_bootstrap_node.ps1."
}

if ([string]::IsNullOrWhiteSpace($SeedHost)) {
    throw "SeedHost is required. Example: -SeedHost seed1.imagine-freedom.net"
}

$logDir = Join-Path $scriptRoot "logs"
New-Item -ItemType Directory -Force -Path $logDir | Out-Null

$args = @(
    "bootstrap-node",
    "serve",
    "--bind", $Bind,
    "--port", [string]$Port,
    "--seed-host", $SeedHost,
    "--seed-port", [string]$Port
)

if ($Quiet) {
    $args += "--quiet"
}

& $hostExe @args
