# Makefile pour EzQt Widgets
# Usage: make <target>

.PHONY: help install install-dev format lint test test-cov clean pre-commit setup-hooks docs docs-build docs-deploy

# Configuration
PYTHON := uv run python
PACKAGE := ezqt_widgets

# Couleurs pour l'affichage
BLUE := \033[34m
GREEN := \033[32m
YELLOW := \033[33m
RED := \033[31m
RESET := \033[0m

# Aide par défaut
help:
	@echo "$(BLUE)EzQt Widgets - Commandes de développement$(RESET)"
	@echo ""
	@echo "$(GREEN)Installation:$(RESET)"
	@echo "  install      - Installer le package"
	@echo "  install-dev  - Installer les dépendances de développement"
	@echo ""
	@echo "$(GREEN)Formatage et qualité:$(RESET)"
	@echo "  format       - Formater le code (ruff format)"
	@echo "  lint         - Vérifier la qualité du code"
	@echo "  fix          - Corriger automatiquement les problèmes"
	@echo ""
	@echo "$(GREEN)Tests:$(RESET)"
	@echo "  test         - Lancer les tests unitaires"
	@echo "  test-cov     - Tests avec couverture"
	@echo "  test-fast    - Tests rapides (sans les lents)"
	@echo ""
	@echo "$(GREEN)Hooks et outils:$(RESET)"
	@echo "  setup-hooks  - Installer les hooks pre-commit"
	@echo "  pre-commit   - Lancer les vérifications pre-commit"
	@echo ""
	@echo "$(GREEN)Documentation:$(RESET)"
	@echo "  docs         - Lancer le serveur de documentation (hot-reload)"
	@echo "  docs-build   - Build statique de la documentation"
	@echo "  docs-deploy  - Deployer sur GitHub Pages"
	@echo ""
	@echo "$(GREEN)Nettoyage:$(RESET)"
	@echo "  clean        - Nettoyer les fichiers temporaires"

# Installation
install:
	@echo "$(BLUE)Installation du package...$(RESET)"
	uv sync

install-dev:
	@echo "$(BLUE)Installation des dépendances de développement...$(RESET)"
	uv sync --all-extras

# Formatage automatique
format:
	@echo "$(BLUE)Formatage du code avec Ruff...$(RESET)"
	ruff format src/$(PACKAGE) tests

# Correction automatique
fix: format
	@echo "$(GREEN)Code formaté automatiquement !$(RESET)"

# Linting
lint:
	@echo "$(BLUE)Vérification de la qualité du code...$(RESET)"
	$(PYTHON) .scripts/dev/lint.py

# Tests
test:
	@echo "$(BLUE)Lancement des tests unitaires...$(RESET)"
	$(PYTHON) tests/run_tests.py --type unit

test-cov:
	@echo "$(BLUE)Tests avec couverture...$(RESET)"
	$(PYTHON) tests/run_tests.py --coverage

test-fast:
	@echo "$(BLUE)Tests rapides...$(RESET)"
	$(PYTHON) tests/run_tests.py --fast

# Hooks pre-commit
setup-hooks:
	@echo "$(BLUE)Installation des hooks pre-commit...$(RESET)"
	uv run pre-commit install
	@echo "$(GREEN)Hooks pre-commit installés !$(RESET)"

pre-commit:
	@echo "$(BLUE)Lancement des vérifications pre-commit...$(RESET)"
	uv run pre-commit run --all-files

# Documentation
docs:
	@echo "$(BLUE)Lancement du serveur de documentation...$(RESET)"
	uv run mkdocs serve

docs-build:
	@echo "$(BLUE)Build de la documentation...$(RESET)"
	uv run mkdocs build --strict

docs-deploy:
	@echo "$(BLUE)Deploiement sur GitHub Pages...$(RESET)"
	uv run mkdocs gh-deploy --force

# Nettoyage
clean:
	@echo "$(BLUE)Nettoyage des fichiers temporaires...$(RESET)"
	find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete 2>/dev/null || true
	find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
	rm -rf build/ dist/ .coverage htmlcov/ .pytest_cache/ .mypy_cache/ 2>/dev/null || true
	@echo "$(GREEN)Nettoyage terminé !$(RESET)"

# Commande complète de vérification
check: format lint test
	@echo "$(GREEN)Toutes les vérifications sont terminées !$(RESET)"

# Préparation pour un commit
prepare: format lint test-fast
	@echo "$(GREEN)Code prêt pour le commit !$(RESET)"
