.PHONY: help install init doctor validate validate-config scan test test-unit lint typecheck check clean check-installed

VENV_PYTHON := $(shell test -x .venv/bin/python && .venv/bin/python -c "import pytest,ruff,mypy" >/dev/null 2>&1 && echo .venv/bin/python)
PYTHON ?= $(if $(VENV_PYTHON),$(VENV_PYTHON),python3)
SCOPE ?= examples/scope.yaml
PROFILE ?= standard
WORKSPACE ?= $(HOME)/matrixrecon-workspace

help:
	@echo "MatrixRecon"
	@echo "  make install | init | doctor | validate | scan | test | test-unit | check"

install:
	$(PYTHON) -m pip install -e '.[dev]'

check-installed:
	@$(PYTHON) -c "import recon" 2>/dev/null || { \
		echo "MatrixRecon n'est pas installé dans $(PYTHON)."; \
		echo "Exécutez './install.sh', puis relancez cette commande."; \
		exit 1; \
	}

init: check-installed
	$(PYTHON) -m recon init $(WORKSPACE)

doctor: check-installed
	$(PYTHON) -m recon doctor

validate: check-installed
	$(PYTHON) -m recon scope validate $(SCOPE)

validate-config: check-installed
	$(PYTHON) -m recon config validate config/default.yaml

scan: check-installed
	$(PYTHON) -m recon scan --scope $(SCOPE) --profile $(PROFILE) --dry-run

test:
	$(PYTHON) -m pytest

test-unit:
	$(PYTHON) -m pytest -m unit

lint:
	$(PYTHON) -m ruff check .

typecheck:
	$(PYTHON) -m mypy src

check: lint typecheck test-unit

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