#!/bin/bash
# Quick start script for SAMI-CLOUD API Server (Linux/macOS)

echo "===================================="
echo "SAMI-CLOUD API Server"
echo "===================================="
echo ""

# Check if Node.js is installed
if ! command -v node &> /dev/null; then
    echo "Error: Node.js is not installed or not in PATH"
    echo "Please install Node.js from https://nodejs.org/"
    exit 1
fi

# Check if node_modules exists
if [ ! -d "node_modules" ]; then
    echo "Installing dependencies..."
    npm install
    echo ""
fi

# Check environment variables
if [ -z "$CADDY_ADMIN_API" ]; then
    echo "Warning: CADDY_ADMIN_API not set, using default: http://localhost:2019"
    export CADDY_ADMIN_API="http://localhost:2019"
fi

if [ -z "$DNS_SERVER_API" ]; then
    echo "Warning: DNS_SERVER_API not set, using default: http://192.168.254.204:5380"
    export DNS_SERVER_API="http://192.168.254.204:5380"
fi

if [ -z "$TECHNITIUM_API_TOKEN" ]; then
    echo "Warning: TECHNITIUM_API_TOKEN not set - DNS operations will fail"
    echo "Set it with: export TECHNITIUM_API_TOKEN=your_token"
    echo ""
fi

echo "Starting API server..."
echo ""
node caddy-api.js
