# CNPERP on-premise license heartbeat (Windows Task Scheduler)
# Register once, then ping cloud every run.
#
# Setup:
#   1. Copy license-node.example.json to license-node.json in this folder
#   2. Edit license_key, cloud_url, node_name, public_base_url
#   3. Test:  powershell -File deploy\local_license_heartbeat.ps1
#   4. Schedule: every 5 minutes (see deploy\SCHEDULED_TASK_SETUP.md pattern)
#
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
$ConfigPath = Join-Path $Root "deploy\license-node.json"
$Python = "python"

if (-not (Test-Path $ConfigPath)) {
    Write-Host "Missing $ConfigPath — copy from deploy\license-node.example.json" -ForegroundColor Yellow
    exit 1
}

$Script = Join-Path $Root "scripts\heartbeat_license.py"
& $Python $Script --config $ConfigPath
exit $LASTEXITCODE
