#!/bin/bash
set -e

# Coolify setup script for sbsports
# Prerequisites: Coolify API token

COOLIFY_API_TOKEN="${COOLIFY_API_TOKEN:-}"
COOLIFY_API="https://panel.thax.es/api/v1"

if [ -z "$COOLIFY_API_TOKEN" ]; then
    echo "Error: COOLIFY_API_TOKEN not set"
    echo "Usage: COOLIFY_API_TOKEN=your_token ./scripts/coolify-setup.sh"
    exit 1
fi

echo "=== sbsports Coolify Setup ==="
echo ""

# 1. List existing projects
echo "1. Listing existing projects..."
curl -sSLk "$COOLIFY_API/projects" \
  -H "Authorization: Bearer $COOLIFY_API_TOKEN" | jq '.'

echo ""
echo "2. Create a Docker Compose service in Coolify:"
echo "   - Go to: https://panel.thax.es"
echo "   - Create a new project (or use existing)"
echo "   - Add a new Docker Compose service"
echo "   - Paste the contents of coolify/docker-compose.yml"
echo "   - Deploy"
echo ""
echo "3. After creation, get the UUID from the service details"
echo "   - Set SBSPORTS_COOLIFY_UUID environment variable"
echo "   - Add it to Woodpecker secrets"
echo ""
echo "4. To activate the repo in Woodpecker (optional):"
echo "   SBSPORTS_REPO_ID=your_gitea_remote_id ./scripts/activate-woodpecker.sh"
