	# === OWS UNUSED ENDPOINTS MAKEFILE === #

.PHONY: help install install-dev fmt format lint lint-fix type-check check test clean build update update-service sync-frontend frontend-dev frontend-build all

# === HELP === #

help: ## Show this help message
	@echo "OWS Unused Endpoints - Available Commands"
	@echo ""
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
		awk 'BEGIN {FS = ":.*?## "}; {printf "  %-20s %s\n", $$1, $$2}'

# === SETUP COMMANDS === #

install: ## Install the package (production dependencies only)
	uv sync --no-dev

install-dev: ## Install the package with development dependencies
	uv sync

# === CODE QUALITY === #

fmt: format ## Format code with ruff (alias)

format: ## Format code with ruff
	uv run ruff format .

lint: ## Lint code with ruff
	uv run ruff check .

lint-fix: ## Lint and fix code with ruff
	uv run ruff check --fix .

type-check: ## Run type checking with mypy
	uv run mypy src/

check: lint type-check ## Run all checks (lint and type-check)

# === BUILD & TEST === #

test: ## Run tests (placeholder)
	@echo "No tests configured yet"

clean: ## Clean build artifacts
	rm -rf build/
	rm -rf dist/
	rm -rf *.egg-info/
	find . -type f -name "*.pyc" -delete
	find . -type d -name "__pycache__" -delete

build: ## Build the package
	uv run python -m build

# === PIPELINE === #

update: ## Fetch Datadog data + analyze all services
	uv run python -m src.orchestrator --env prod

update-service: ## Analyze a single service (usage: make update-service SERVICE=ows-users)
	uv run python -m src.orchestrator --env prod --service $(SERVICE)

update-services: ## Analyze services from a file (usage: make update-services FILE=services.txt)
	uv run python -m src.orchestrator --env prod --services $(FILE)

build-dashboard: ## Build dashboard JSON from existing CSV analysis data
	uv run python src/build_dashboard_from_csv.py

sync-frontend: ## Copy dashboard data to frontend
	cp data/dashboard-data.json ../frontend/data/

pipeline: update sync-frontend ## Full pipeline: update data + sync to frontend

# === DEFAULT TARGET === #

all: install-dev format lint type-check ## Install dependencies, format, lint, and type-check
