#!/bin/bash
# Hermes Node Protocol
# Copyright (c) 2026 Stefy (nextime) Lanza <stefy@nexlab.net>
# All rights reserved.
# 
# This software is released under the MIT License with a copyleft clause.
# See the LICENSE file for full terms.
set -e

echo "=== Building Windows Distribution ==="

# Check if running on Windows or if we can build Windows artifacts
if ! command -v python3 &> /dev/null; then
    echo "ERROR: python3 not found"
    exit 1
fi

# Create dist directory
mkdir -p dist

# Create temporary build directory
BUILD_DIR=$(mktemp -d)
PACKAGE_DIR="$BUILD_DIR/hermes-node-agent-windows"
mkdir -p "$PACKAGE_DIR"

echo "Copying files to $PACKAGE_DIR..."

# Copy core files
cp hermes_node_agent.py "$PACKAGE_DIR/"
cp browser_controller.py "$PACKAGE_DIR/"
cp requirements.txt "$PACKAGE_DIR/"
cp install-windows.ps1 "$PACKAGE_DIR/"

# Copy Windows-specific files
cp -r windows "$PACKAGE_DIR/"

# Copy documentation
cp README.md "$PACKAGE_DIR/"
cp LICENSE "$PACKAGE_DIR/"
cp WINDOWS_DEPLOYMENT.md "$PACKAGE_DIR/"
cp PROTOCOL.md "$PACKAGE_DIR/"
cp BROWSER_PROTOCOL.md "$PACKAGE_DIR/"

# Create zip archive
cd "$BUILD_DIR"
zip -r hermes-node-agent-windows.zip hermes-node-agent-windows/
mv hermes-node-agent-windows.zip "$OLDPWD/dist/"
cd "$OLDPWD"

# Cleanup
rm -rf "$BUILD_DIR"

echo "✅ Windows package created: dist/hermes-node-agent-windows.zip"
echo ""
echo "To build the Windows installer (.exe):"
echo "  1. Extract dist/hermes-node-agent-windows.zip on a Windows machine"
echo "  2. Install Python 3.8+ and Inno Setup"
echo "  3. Run: python windows\\build.py"
echo "  4. Installer will be in windows\\Output\\hermes-node-agent-installer.exe"
