# Docker Compose Deployment Management
.PHONY: help dev-up dev-down dev-logs dev-restart homelab-secure-up homelab-secure-down prod-up prod-down status clean

# Default target
help: ## Show this help message
	@echo "Available commands:"
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

# Development environment
dev-up: ## Start development environment
	@echo "Starting development environment..."
	docker-compose -f deployments/docker-compose.dev.yml up -d
	@echo "Services: Caddy (8080/8443), Redis (6379), Prometheus (9090), Grafana (3000)"

dev-down: ## Stop development environment
	@echo "Stopping development environment..."
	docker-compose -f deployments/docker-compose.dev.yml down

dev-logs: ## Show development logs
	docker-compose -f deployments/docker-compose.dev.yml logs -f

dev-restart: ## Restart development environment
	@echo "Restarting development environment..."
	docker-compose -f deployments/docker-compose.dev.yml restart


# Homelab environment
homelab-secure-up: ## Start secure homelab environment
	@echo "Starting secure homelab environment..."
	docker-compose -f deployments/docker-compose.homelab-secure.yml up -d

homelab-secure-down: ## Stop secure homelab environment
	@echo "Stopping secure homelab environment..."
	docker-compose -f deployments/docker-compose.homelab-secure.yml down

# Production environment
prod-up: ## Start production environment
	@echo "Starting production environment..."
	docker-compose -f deployments/docker-compose.prod.yml up -d

prod-down: ## Stop production environment
	@echo "Stopping production environment..."
	docker-compose -f deployments/docker-compose.prod.yml down

# Utility commands
status: ## Show status of all environments
	@echo "=== Development Status ==="
	@if [ -f deployments/docker-compose.dev.yml ]; then \
		docker-compose -f deployments/docker-compose.dev.yml ps; \
	fi
	@echo ""
	@echo "=== Homelab Secure Status ==="
	@if [ -f deployments/docker-compose.homelab-secure.yml ]; then \
		docker-compose -f deployments/docker-compose.homelab-secure.yml ps 2>/dev/null || echo "Not running"; \
	fi
	@echo ""
	@echo "=== Production Status ==="
	@if [ -f deployments/docker-compose.prod.yml ]; then \
		docker-compose -f deployments/docker-compose.prod.yml ps 2>/dev/null || echo "Not running"; \
	fi

clean: ## Clean up all containers and volumes
	@echo "Cleaning up all Docker resources..."
	@echo "This will remove all containers and volumes. Continue? [y/N]"
	@read -r confirm && [ "$$confirm" = "y" ] || exit 1
	docker-compose -f deployments/docker-compose.dev.yml down -v 2>/dev/null || true
	docker-compose -f deployments/docker-compose.homelab-secure.yml down -v 2>/dev/null || true
	docker-compose -f deployments/docker-compose.prod.yml down -v 2>/dev/null || true
	docker system prune -f
	@echo "Cleanup complete."

# Quick aliases
up: dev-up ## Alias for dev-up
down: dev-down ## Alias for dev-down
logs: dev-logs ## Alias for dev-logs
restart: dev-restart ## Alias for dev-restart
