# Data Engineer Doctor — single authoritative verification pipeline.
# CI and local development must run the same command: `make verify`.

VENV ?= .venv
PYTHON := $(VENV)/bin/python
UV := $(shell command -v uv 2>/dev/null || echo $(HOME)/.local/bin/uv)

.DEFAULT_GOAL := help

.PHONY: help setup format format-check lint typecheck test validate evaluate benchmark examples link-check docs audit build verify clean

help:
	@echo "Targets:"
	@echo "  setup        Create the virtualenv and install dev dependencies"
	@echo "  format       Auto-format with ruff"
	@echo "  format-check Check formatting (ruff)"
	@echo "  lint         Lint (ruff)"
	@echo "  typecheck    Type check (mypy, strict)"
	@echo "  test         Unit, integration, regression, fixture tests (pytest)"
	@echo "  validate     Validate all diagnosis YAML definitions"
	@echo "  evaluate     Grade the pipeline against the fixtures corpus (§19)"
	@echo "  benchmark    Write benchmark results + regression baseline to benchmarks/"
	@echo "  examples     Diagnose every sample input in examples/logs"
	@echo "  link-check   HTTP-check every reference URL in diagnosis YAMLs"
	@echo "  docs         Build the MkDocs site (strict)"
	@echo "  audit        Dependency security audit (pip-audit)"
	@echo "  build        Build sdist + wheel"
	@echo "  verify       Run the full verification pipeline (authoritative)"

setup:
	@if command -v uv >/dev/null 2>&1 || [ -x "$(HOME)/.local/bin/uv" ]; then \
		"$(UV)" sync; \
	else \
		python3 -m venv "$(VENV)" && "$(VENV)/bin/pip" install -e ".[dev]"; \
	fi

format:
	"$(PYTHON)" -m ruff format .
	"$(PYTHON)" -m ruff check --fix .

format-check:
	"$(PYTHON)" -m ruff format --check .

lint:
	"$(PYTHON)" -m ruff check .

typecheck:
	"$(PYTHON)" -m mypy

test:
	"$(PYTHON)" -m pytest

validate:
	"$(PYTHON)" -m dedoc.diagnosis.validate

evaluate:
	"$(PYTHON)" -m dedoc.evaluation --strict --baseline benchmarks/baseline.json

benchmark:
	"$(PYTHON)" -m dedoc.evaluation --output benchmarks/results.json --write-baseline benchmarks/baseline.json

examples:
	@for f in examples/logs/*; do \
		echo "==> $$f"; \
		"$(PYTHON)" -m dedoc.cli.main diagnose "$$f" || true; \
	done

link-check:
	"$(PYTHON)" -m dedoc.diagnosis.validate --links

docs:
	"$(PYTHON)" -m mkdocs build --strict

audit:
	"$(PYTHON)" -m pip_audit

build:
	"$(PYTHON)" -m build

verify: format-check lint typecheck test validate evaluate link-check docs audit build
	@echo "verify: PASSED"

clean:
	rm -rf dist build .pytest_cache .mypy_cache .ruff_cache
	find . -type d -name __pycache__ -prune -exec rm -rf {} +
