# Goaly MCP Development Tasks
# Run 'just' to see available commands

# Import modular justfiles
import 'just/common.just'
import 'just/dev.just'
import 'just/quality.just'
import 'just/database.just'
import 'just/docker.just'
import 'just/test.just'
import 'just/utils.just'
import 'just/devcontainer.just'
# import? 'just/legacy.just'  # Uncomment to enable backward compatibility aliases

# Default recipe - show detailed help
default:
    @just help

# =============================================================================
# 🚀 QUICK START WORKFLOWS
# =============================================================================

# Complete project setup for new developers
[group: 'quickstart']
quickstart: setup install db-init
    @echo "✅ Project setup complete!"
    @echo "📝 Edit .env with your settings"
    @echo "🚀 Run 'just dc-up' to start DevContainer development"

# Run all checks before committing (includes security audit)
[group: 'quickstart']
pre-commit: format lint type-check audit
    @echo "✅ All checks passed! Ready to commit."
    @echo "💡 Run 'just pre-commit-hooks' for complete validation with pre-commit hooks"

# Run actual pre-commit hooks (exact CI validation)
[group: 'quickstart']
pre-commit-hooks:
    @just _run "Running pre-commit hooks" "uv run pre-commit run --all-files"

# Simulate full CI pipeline locally (includes all tests)
[group: 'quickstart']
ci-local: lint type-check audit test build-validated
    @echo "✅ CI simulation complete! All checks passed."

# Start full development environment
[group: 'quickstart']
start: dev-all
    #!/usr/bin/env bash
    echo "🚀 Development environment running!"
    echo "📊 Dashboard: $(just _get-dashboard-url)"
    echo "🔧 API: $(just _get-api-url)"
    echo "🧩 MCP: $(just _get-mcp-url)"
    echo "📚 Docs: $(just _get-docs-url)"

# =============================================================================
# 🔧 CORE RECIPES
# =============================================================================

# Build project (moved to dev.just)
# Use 'just build' to build the universal wheel

# Build project with validation (recommended)
[group: 'core']
build-validated: build-check build build-validate
    @just _success "Validated build completed successfully"

# Setup project environment
[group: 'core']
setup:
    @sh -c 'if [ ! -f .env ]; then echo "Creating .env file..."; cat > .env << "EOF"\n# Goaly MCP Environment Variables\nDATABASE_URL=sqlite+aiosqlite:///./goaly.db\nGOALY_DEBUG=true\nGOALY_HOST=127.0.0.1\nGOALY_PORT=8000\nGOALY_MCP_SERVER_API_KEY=your-secret-key-here\nEOF\necho "✅ .env file created! Please edit it with your settings."; else echo "✅ .env file already exists"; fi'

# Install dependencies
[group: 'core']
install target="all":
    @just install-{{target}}

# Clean build artifacts
[group: 'core']
clean target="all":
    @just clean-{{target}}

# =============================================================================
# 📚 HELP & DOCUMENTATION
# =============================================================================

# Show detailed help
[group: 'help']
help:
    #!/usr/bin/env bash
    PORT=$(just _get-port)
    HOST=$(just _get-host)
    echo "🚀 Goaly MCP Development Commands"
    echo "=================================="
    echo ""
    echo "🎯 QUICK START:"
    echo "  just quickstart      - Complete setup for new developers"
    echo "  just start           - Start full dev environment"
    echo "  just pre-commit      - Quick checks before committing"
    echo "  just pre-commit-hooks - Full validation with pre-commit hooks"
    echo "  just ci-local        - Complete CI simulation locally"
    echo ""
    echo "🔧 DEVELOPMENT (DevContainer):"
    echo "  just dc-up         - Start DevContainer development environment"
    echo "  just dc-exec       - Open shell in DevContainer"
    echo "  just dc-test       - Run tests in DevContainer"
    echo "  just dev [mode]    - Start dev server locally (backend|frontend|all)"
    echo "  just test [type]   - Run tests locally (all|fast|integration|frontend)"
    echo "  just build         - Build project"
    echo ""
    echo "📋 CODE QUALITY:"
    echo "  just format        - Format all code"
    echo "  just lint          - Lint all code"
    echo "  just type-check    - Type check all code"
    echo ""
    echo "🗄️ DATABASE:"
    echo "  just db-init       - Initialize database"
    echo "  just db-migrate    - Run migrations"
    echo "  just db-reset      - Reset database (DESTRUCTIVE)"
    echo ""
    echo "🐳 DOCKER COMMANDS:"
    echo "  just docker-build        - Build production Docker image (buildx bake)"
    echo "  just docker-build-local  - Build local Docker image"
    echo "  just docker-build-dev    - Build development Docker image"
    echo "  just docker-test-prod    - Test production environment"
    echo "  just docker-run          - Run production container"
    echo ""
    echo "📋 DEVCONTAINER COMMANDS:"
    echo "  just dc-help       - Show all DevContainer commands"
    echo ""
    echo "🌐 CURRENT CONFIGURATION:"
    echo "  Server: $HOST:$PORT"
    echo "  Dashboard: $(just _get-dashboard-url)"
    echo "  API: $(just _get-api-url)"
    echo "  MCP: $(just _get-mcp-url)"
    echo "  Docs: $(just _get-docs-url)"
    echo ""
    echo "🔍 DISCOVERY & NAVIGATION:"
    echo "  just --list              - List all recipes organized by groups"
    echo "  just --groups            - List all recipe groups"
    echo "  just --summary           - Compact list of recipe names only"
    echo "  just --show <recipe>     - Show recipe source code"
    echo "  just --choose            - Interactive recipe picker (requires fzf)"
    echo ""
    echo "💡 TIPS:"
    echo "  🚀 Primary development: Use DevContainer (just dc-up)"
    echo "  🐳 Production testing: Use Docker commands"
    echo "  📋 Local development: Use dev/test commands without containers"
    echo "  🔍 Use 'just --show <recipe>' to see how recipes work"
    echo "  📊 Recipes are organized by logical groups (dev, test, build, etc.)"

# Show recipe groups
[group: 'help']
groups:
    @just --groups

# Show recipe list
[group: 'help']
list:
    @just --list
