.PHONY: help run-0 run-1 run-2 clean-1 clean-2

.DEFAULT_GOAL := help

help:
	@echo ""
	@echo "╔════════════════════════════════════════════════════╗"
	@echo "║          Backend Development                        ║"
	@echo "╚════════════════════════════════════════════════════╝"
	@echo ""
	@echo "🚀 Run:"
	@echo ""
	@echo "  make run-0         Hot reload + Mock"
	@echo "                     • No dependencies"
	@echo "                     • Ctrl+C to stop"
	@echo ""
	@echo "  make run-1         Hot reload + Deps in container"
	@echo "                     • Real PostgreSQL (Docker)"
	@echo "                     • Ctrl+C to stop backend"
	@echo ""
	@echo "  make run-2         All in container (background)"
	@echo "                     • Everything in Docker"
	@echo "                     • Use 'docker compose down' to stop"
	@echo ""
	@echo "🧹 Clean:"
	@echo ""
	@echo "  make clean-1       Clean run-1 artifacts"
	@echo "                     (deps containers + volumes + tmp/)"
	@echo ""
	@echo "  make clean-2       Clean run-2 artifacts"
	@echo "                     (all containers + volumes + bin/)"
	@echo ""

# ============================================
# Run Commands
# ============================================

run-0:
	@echo "🎭 Run-0: Hot reload + Mock"
	@echo "────────────────────────────────"
	ADAPTER_MODE=mock air -c .air.toml

run-1:
	@echo "🔥 Run-1: Hot reload + Deps in container"
	@echo "────────────────────────────────"
	@docker compose up -d postgres
	@sleep 5
	@echo "✅ Dependencies ready, starting backend..."
	@echo ""
	ADAPTER_MODE=production \
	DATABASE_URL=postgresql://postgres:postgres@localhost:5432/ocdp?sslmode=disable \
	air -c .air.toml

run-2:
	@echo "⚡ Run-2: All in container (background)"
	@echo "────────────────────────────────"
	@echo "→ Starting backend stack via Docker Compose (postgres + backend)"
	ADAPTER_MODE=production docker compose --profile backend up -d
	@echo ""
	@echo "✅ Backend stack running in Docker (use 'docker compose --profile backend down' to stop)"

# ============================================
# Clean Commands
# ============================================

clean-1:
	@echo "🧹 Cleaning run-1 artifacts..."
	@docker compose down -v
	@rm -rf tmp/
	@echo "✅ run-1 cleaned"

clean-2:
	@echo "🧹 Cleaning run-2 artifacts..."
	@docker compose --profile backend down -v
	@rm -rf bin/ dist/
	@echo "✅ run-2 cleaned"
