#!/bin/bash
# Simple CI/CD validation for new contributors
# Works without Docker - just validates the essentials

set -e

echo "🚀 DanceLessonsCoach Contributor Quick Start"
echo "=========================================="
echo ""
echo "This script helps you validate your changes before submitting a PR."
echo "It doesn't require Docker or complex setup."
echo ""

# 1. Check Go is installed
echo "1. Checking Go installation..."
if ! command -v go >/dev/null 2>&1; then
    echo "❌ Go is not installed. Please install Go 1.26.1+"
    echo "   Download: https://go.dev/dl/"
    exit 1
fi
go_version=$(go version | grep -o 'go[0-9.]*')
echo "✅ Go $go_version found"

# 2. Run Go tests
echo ""
echo "2. Running Go tests..."
if go test ./...; then
    echo "✅ All Go tests passed"
else
    echo "❌ Some tests failed. Please fix and try again."
    exit 1
fi

# 3. Check formatting
echo ""
echo "3. Checking code formatting..."
if [ -n "$(go fmt ./...)" ]; then
    echo "❌ Code formatting issues found"
    echo "   Run: go fmt ./..."
    exit 1
fi
echo "✅ Code is properly formatted"

# 4. Run Go vet
echo ""
echo "4. Running Go vet..."
if go vet ./...; then
    echo "✅ Go vet passed"
else
    echo "❌ Go vet found issues"
    exit 1
fi

# 5. Validate workflows (no Docker required)
echo ""
echo "5. Validating CI/CD workflows..."
if [ -f "scripts/cicd/validate-workflow.sh" ]; then
    if ./scripts/cicd/validate-workflow.sh; then
        echo "✅ Workflow validation passed"
    else
        echo "⚠️  Workflow validation issues (not critical)"
    fi
else
    echo "ℹ️  Workflow validation script not found"
fi

echo ""
echo "🎉 All checks passed!"
echo "=========================================="
echo ""
echo "Your changes are ready to submit! 🚀"
echo ""
echo "Next steps:"
echo "  1. Commit your changes: git commit -m 'feat: your feature'"
echo "  2. Push to your branch: git push origin your-branch"
echo "  3. Create a Pull Request"
echo ""
echo "The CI/CD pipeline will run automatically on your PR!"
