.PHONY: help
help:
	@echo "Comandos disponibles para verificación de código OCA:"
	@echo ""
	@echo "  make lint          - Ejecutar todas las verificaciones (pre-commit)"
	@echo "  make format        - Formatear código (black + isort)"
	@echo "  make check-format  - Verificar formateo sin modificar"
	@echo "  make flake8        - Ejecutar flake8"
	@echo "  make pylint        - Ejecutar pylint (opcionales y mandatorios)"
	@echo "  make pylint-required - Ejecutar solo verificaciones mandatorias"
	@echo "  make test          - Ejecutar tests"
	@echo "  make install-hooks - Instalar pre-commit hooks"
	@echo "  make update-hooks  - Actualizar pre-commit hooks"
	@echo "  make clean         - Limpiar archivos temporales"
	@echo ""

.PHONY: install-hooks
install-hooks:
	pre-commit install

.PHONY: update-hooks
update-hooks:
	pre-commit autoupdate

.PHONY: lint
lint:
	pre-commit run --all-files

.PHONY: lint-changed
lint-changed:
	pre-commit run

.PHONY: format
format:
	black .
	isort .

.PHONY: check-format
check-format:
	black --check .
	isort --check-only .

.PHONY: flake8
flake8:
	flake8 .

.PHONY: pylint
pylint:
	@for addon in $$(ls -d */ | grep -v "\."); do \
		if [ -f "$$addon/__manifest__.py" ] || [ -f "$$addon/__openerp__.py" ]; then \
			echo "Checking $$addon with pylint..."; \
			pylint --rcfile=.pylintrc --exit-zero $$addon; \
		fi \
	done

.PHONY: pylint-required
pylint-required:
	@for addon in $$(ls -d */ | grep -v "\."); do \
		if [ -f "$$addon/__manifest__.py" ] || [ -f "$$addon/__openerp__.py" ]; then \
			echo "Checking $$addon with pylint (mandatory checks)..."; \
			pylint --rcfile=.pylintrc-mandatory $$addon; \
		fi \
	done

.PHONY: test
test:
	@echo "Ejecutar tests de Odoo aquí"
	@echo "Por ejemplo: pytest o python -m pytest"

.PHONY: clean
clean:
	find . -type f -name '*.pyc' -delete
	find . -type d -name '__pycache__' -delete
	find . -type d -name '*.egg-info' -exec rm -rf {} + || true
	find . -type d -name '.pytest_cache' -exec rm -rf {} + || true
	find . -type d -name '.tox' -exec rm -rf {} + || true
	rm -rf build/ dist/

.PHONY: requirements
requirements:
	pre-commit run setuptools-odoo-get-requirements --all-files
