#!/bin/bash
# DanceLessonsCoach CI/CD Management Script
# Unified interface for all CI/CD operations

set -e

SCRIPTS_DIR="$(dirname "$0")/cicd"

echo "🚀 DanceLessonsCoach CI/CD Management"
echo "===================================="
echo ""

if [ $# -eq 0 ]; then
    echo "Available commands:"
    echo "  validate       - Validate CI/CD workflow structure"
    echo "  test-simple    - Test workflow locally without Gitea"
    echo "  test-local    - Test local setup with Gitea configuration"
    echo "  test-docker   - Test with docker compose (requires Gitea runner)"
    echo "  check-status   - Check pipeline status on Gitea"
    echo "  help          - Show this help message"
    echo ""
    echo "Usage: $0 <command>"
    exit 1
fi

COMMAND="$1"
shift

case "$COMMAND" in
    validate)
        echo "🔍 Validating CI/CD workflow..."
        "$SCRIPTS_DIR/validate-workflow.sh"
        ;;
    
    test-simple)
        echo "🧪 Running simple CI/CD test (no Gitea required)..."
        "$SCRIPTS_DIR/test-cicd-simple.sh"
        ;;
    
    test-local)
        echo "🧪 Testing local CI/CD setup..."
        "$SCRIPTS_DIR/test-cicd-local.sh"
        ;;
    
    test-docker)
        echo "🐳 Testing with docker compose..."
        "$SCRIPTS_DIR/test-cicd-docker.sh"
        ;;
    
    test-act)
        echo "🎭 Testing Gitea workflows with GitHub Actions runner..."
        "$SCRIPTS_DIR/test-act-local.sh"
        ;;
    
    check-status)
        echo "🔍 Checking pipeline status..."
        "$SCRIPTS_DIR/check-pipeline-status.sh"
        ;;
    
    help|--help|-h)
        echo "Available commands:"
        echo "  validate       - Validate CI/CD workflow structure"
        echo "  test-simple    - Test workflow locally without Gitea"
        echo "  test-local    - Test local setup with Gitea configuration"
        echo "  test-docker   - Test with docker compose (requires Gitea runner)"
        echo "  test-act      - Test Gitea workflows with GitHub Actions runner"
        echo "  check-status   - Check pipeline status on Gitea"
        echo "  help          - Show this help message"
        ;;
    
    *)
        echo "❌ Unknown command: $COMMAND"
        echo "Run '$0 help' for available commands"
        exit 1
        ;;
esac