# deploy_to_nas.ps1 — Kopieer project naar Synology NAS en start Docker
# Gebruik:  powershell -ExecutionPolicy Bypass -File deploy_to_nas.ps1

param(
    [string]$NasHost = "192.168.1.211",
    [string]$NasUser = "mo",
    [string]$NasPath = "/volume1/docker/ha-voice-control"
)

$ErrorActionPreference = "Stop"
$localDir = Split-Path -Parent $MyInvocation.MyCommand.Path

Write-Host "=== Deploy HA Voice Control naar Synology NAS ===" -ForegroundColor Cyan
Write-Host ""

# Bestanden die mee moeten naar de NAS
$files = @(
    "Dockerfile",
    "docker-compose.yml",
    ".dockerignore",
    "config.py",
    "requirements.txt",
    "requirements-neo4j.txt"
)

$dirs = @(
    "src",
    "static"
)

# 1. Maak target directory op NAS
Write-Host "[1/4] Directory aanmaken op NAS..." -ForegroundColor Yellow
ssh "${NasUser}@${NasHost}" "mkdir -p ${NasPath}"

# 2. Kopieer losse bestanden
Write-Host "[2/4] Bestanden kopieren..." -ForegroundColor Yellow
foreach ($file in $files) {
    $src = Join-Path $localDir $file
    if (Test-Path $src) {
        scp $src "${NasUser}@${NasHost}:${NasPath}/"
        Write-Host "  OK: $file" -ForegroundColor Green
    } else {
        Write-Host "  SKIP: $file (niet gevonden)" -ForegroundColor Gray
    }
}

# 3. Kopieer mappen
Write-Host "[3/4] Mappen kopieren..." -ForegroundColor Yellow
foreach ($dir in $dirs) {
    $src = Join-Path $localDir $dir
    if (Test-Path $src) {
        scp -r $src "${NasUser}@${NasHost}:${NasPath}/"
        Write-Host "  OK: $dir/" -ForegroundColor Green
    } else {
        Write-Host "  SKIP: $dir/ (niet gevonden)" -ForegroundColor Gray
    }
}

# 4. Bouwen en starten
Write-Host "[4/4] Docker bouwen en starten..." -ForegroundColor Yellow
Write-Host ""
Write-Host "Nu op de NAS (ssh):"
Write-Host "  cd ${NasPath}"
Write-Host "  docker-compose up -d --build"
Write-Host ""
Write-Host "Dashboard wordt bereikbaar op: http://192.168.1.211:8765/dashboard" -ForegroundColor Cyan
Write-Host ""

$sshCmd = Read-Host "Wil je direct verbinden met SSH? (y/n)"
if ($sshCmd -eq "y") {
    ssh -t "${NasUser}@${NasHost}" "cd ${NasPath} && docker-compose up -d --build && echo '' && echo 'Dashboard: http://192.168.1.211:8765/dashboard' && docker-compose logs --tail=10"
}
