.PHONY: help lint format format-check fix test test-cov run migrations migrate clean precommit-install precommit-run precommit-update

# Default target
help:
	@echo "Available targets:"
	@echo "  lint          - Run ruff linter"
	@echo "  format        - Format code with ruff"
	@echo "  format-check  - Check code formatting without changes"
	@echo "  fix           - Auto-fix linting issues and format code"
	@echo "  test          - Run tests with pytest"
	@echo "  test-cov      - Run tests with coverage report"
	@echo "  run           - Run the FastAPI development server"
	@echo "  migrations    - Create database migrations"
	@echo "  migrate       - Apply database migrations"
	@echo "  clean         - Remove cache files and build artifacts"
	@echo "  precommit-install - Install pre-commit git hooks"
	@echo "  precommit-run     - Run pre-commit on all files"
	@echo "  precommit-update  - Update pre-commit hook versions"

# Code quality
lint:
	uv run ruff check .

format:
	uv run ruff format .

format-check:
	uv run ruff format --check .

fix:
	uv run ruff check . --fix
	uv run ruff format .

# Testing
test:
	uv run pytest tests/ -v

test-cov:
	uv run pytest tests/ --cov=core --cov-report=html --cov-report=term

# Development
run:
	uv run uvicorn main_app.main:app --reload

# Database
migrations:
	uv run alembic revision --autogenerate -m "$(message)"

migrate:
	uv run alembic upgrade head

# Cleanup
clean:
	find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete 2>/dev/null || true
	find . -type f -name "*.pyo" -delete 2>/dev/null || true
	find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
	find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
	find . -type d -name ".ruff_cache" -exec rm -rf {} + 2>/dev/null || true
	rm -rf htmlcov/ .coverage

# Pre-commit hooks
precommit-install:
	uv run pre-commit install

precommit-run:
	uv run pre-commit run --all-files

precommit-update:
	uv run pre-commit autoupdate
