PYTHON := python
PIP := pip

.PHONY: help install dev format fix check lint typecheck test run quality ci doctor clean

help:
	@echo "Available commands:"
	@echo "  make install     Install project with development dependencies"
	@echo "  make dev         Create local dev environment and install tools"
	@echo "  make format      Format source code with Black"
	@echo "  make fix         Auto-fix code issues (Black + Ruff)"
	@echo "  make check       Check formatting with Black"
	@echo "  make lint        Run Ruff"
	@echo "  make typecheck   Run MyPy"
	@echo "  make test        Run pytest"
	@echo "  make run         Run the application"
	@echo "  make quality     Run all quality checks"
	@echo "  make ci          Run CI-style validation checks"
	@echo "  make doctor      Show environment and tool versions"
	@echo "  make clean       Remove cache files"

install:
	$(PIP) install --upgrade pip
	$(PIP) install -e '.[dev]'

dev:
	$(PYTHON) -m venv .venv
	. .venv/bin/activate && pip install --upgrade pip
	. .venv/bin/activate && pip install -e '.[dev]'
	. .venv/bin/activate && pre-commit install

format:
	black src tests

fix:
	black src tests
	ruff check --fix src tests

check:
	black --check src tests

lint:
	ruff check src tests

typecheck:
	mypy src

test:
	pytest

run:
	$(PYTHON) -m app.main

quality: check lint typecheck test

ci: check lint typecheck test

doctor:
	@echo "Python:"
	@$(PYTHON) --version
	@echo ""
	@echo "Tool versions:"
	@black --version
	@ruff --version
	@mypy --version
	@pytest --version

clean:
	find . -type d \( -name "__pycache__" -o -name ".pytest_cache" -o -name ".mypy_cache" -o -name ".ruff_cache" \) -exec rm -rf {} +
	find . -type f \( -name "*.pyc" -o -name "*.pyo" \) -delete
