# ─────────────────────────────────────────────────────────────────────────────
# Veille législative Guadeloupe — commandes du projet
#
#   make install     installe le pipeline Python et l'application web
#   make db-init     crée ou migre la base SQLite
#   make seed        remplit la base depuis data/input/ (lecture seule)
#   make update-dry  collecte réelle sans écriture, rapport des différences
#   make update      collecte réelle et mise à jour de la base
#   make test        pytest avec couverture du pipeline
#   make dev         serveur de développement SvelteKit
#   make build       build de production
#   make verifier    contrôles de conformité (§3bis et §8 du cahier des charges)
# ─────────────────────────────────────────────────────────────────────────────

PY      := .venv/bin/python
PYTEST  := .venv/bin/pytest
RUFF    := .venv/bin/ruff
WEB     := web

.DEFAULT_GOAL := aide
.PHONY: aide install install-py install-web db-init seed reseed update update-dry \
        test couverture lint format dev build check verifier propre

aide:
	@grep -E '^#   make' Makefile | sed 's/^#   /  /'

# ── Installation ─────────────────────────────────────────────────────────────
install: install-py install-web

install-py:
	uv venv --python 3.12
	uv pip install -e ".[dev]"

install-web:
	cd $(WEB) && npm ci || (cd $(WEB) && npm install)

# ── Pipeline ─────────────────────────────────────────────────────────────────
db-init:
	$(PY) -m pipeline.db

seed:
	$(PY) -m pipeline.seed_from_research

reseed:
	$(PY) -m pipeline.seed_from_research --repartir-de-zero

update:
	$(PY) -m pipeline.update

update-dry:
	$(PY) -m pipeline.update --dry-run

# ── Qualité ──────────────────────────────────────────────────────────────────
test:
	$(PYTEST) --cov=pipeline --cov-report=term-missing

couverture:
	$(PYTEST) --cov=pipeline --cov-report=html
	@echo "Rapport : htmlcov/index.html"

lint:
	$(RUFF) check pipeline tests

format:
	$(RUFF) format pipeline tests
	$(RUFF) check --fix pipeline tests

# ── Application web ──────────────────────────────────────────────────────────
dev:
	cd $(WEB) && npm run dev

build:
	cd $(WEB) && npm run build

check:
	cd $(WEB) && npm run check

# ── Conformité ───────────────────────────────────────────────────────────────
verifier:
	@bash scripts/verifier-conformite.sh

propre:
	rm -rf .pytest_cache htmlcov .coverage $(WEB)/.svelte-kit $(WEB)/build
	find . -name __pycache__ -type d -prune -exec rm -rf {} +
