#!/usr/bin/env bash
# Build SirayaPrinter.Sync.exe (win-x64 single-file) for release zip.
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
PROJECT="${ROOT}/updater/SirayaPrinter.Sync/SirayaPrinter.Sync.csproj"
OUT_DIR="${ROOT}/dist/release"

if ! command -v dotnet >/dev/null 2>&1; then
  echo "WARN: dotnet SDK not found — skipping Sync.exe build" >&2
  exit 0
fi

echo "==> Building SirayaPrinter.Sync (win-x64)…"
dotnet publish "$PROJECT" \
  -c Release \
  -r win-x64 \
  --self-contained true \
  -p:PublishSingleFile=true \
  -p:IncludeNativeLibrariesForSelfExtract=true \
  -o "${ROOT}/dist/sync-publish"

cp -f "${ROOT}/dist/sync-publish/Sync.exe" "${OUT_DIR}/Sync.exe"
echo "==> Sync.exe → ${OUT_DIR}/Sync.exe"
