# ============================================
# TRON Parity Ladder — Docker Makefile
# ============================================
# Quick shortcuts for Docker-based operations
# ============================================

IMAGE_NAME := tron-parity-ladder
IMAGE_TAG  := latest

.PHONY: help build up down logs restart clean shell health

help: ## Show this help
	@echo "TRON Parity Ladder — Docker Commands"
	@echo ""
	@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "  \033[36m%-12s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

build: ## Build the Docker image (multi-stage)
	docker compose build --no-cache

up: ## Build (if needed) and start the container in background
	docker compose up --build -d
	@echo ""
	@echo "✅  Dashboard running at: http://localhost:$${PORT:-8080}"
	@echo "   Health check:         http://localhost:$${PORT:-8080}/health"

down: ## Stop and remove the container
	docker compose down

logs: ## Tail container logs (Ctrl+C to stop)
	docker compose logs -f

restart: down up ## Restart the container

clean: down ## Stop container and remove image + volumes
	docker rmi $(IMAGE_NAME):$(IMAGE_TAG) 2>/dev/null || true
	docker system prune -f

shell: ## Open a shell inside the running container
	docker compose exec web sh

health: ## Query the health endpoint
	@curl -s http://localhost:$${PORT:-8080}/health && echo

status: ## Show container status and resource usage
	docker compose ps
	@echo ""
	docker stats --no-stream $(IMAGE_NAME) 2>/dev/null || true
