.PHONY: help install install-dev test test-cov lint format clean build publish

help:
	@echo "PR Assistant - Development Commands"
	@echo ""
	@echo "Available commands:"
	@echo "  make install      - Install package"
	@echo "  make install-dev  - Install with development dependencies"
	@echo "  make test         - Run tests"
	@echo "  make test-cov     - Run tests with coverage report"
	@echo "  make lint         - Run linters (flake8, mypy)"
	@echo "  make format       - Format code with black and isort"
	@echo "  make clean        - Remove build artifacts"
	@echo "  make build        - Build distribution packages"
	@echo "  make publish      - Publish to PyPI (use with caution)"
	@echo "  make pre-commit   - Run pre-commit hooks on all files"
	@echo "  make docs         - Generate documentation"

install:
	pip install -e .

install-dev:
	pip install -e ".[dev]"
	pre-commit install

test:
	pytest tests/ -v --tb=long --full-trace -l --maxfail=10

test-cov:
	pytest --cov=pr --cov-report=html --cov-report=term-missing
	@echo "Coverage report generated in htmlcov/index.html"

lint:
	flake8 pr tests --max-line-length=100 --ignore=E203,W503
	mypy pr --ignore-missing-imports

format:
	black pr tests
	isort pr tests --profile black

clean:
	rm -rf build/
	rm -rf dist/
	rm -rf *.egg-info
	rm -rf .pytest_cache/
	rm -rf .mypy_cache/
	rm -rf htmlcov/
	rm -rf .coverage
	find . -type d -name __pycache__ -exec rm -rf {} +
	find . -type f -name "*.pyc" -delete

build: clean
	black .
	autoflake --in-place --remove-all-unused-imports --remove-unused-variables --recursive .
	python -m build

publish: build
	python -m twine upload dist/*

pre-commit:
	pre-commit run --all-files

check: lint test
	@echo "All checks passed!"

backup:
	zip -r rp.zip *
	mv rp.zip ../

serve:
	rpserver


implode: build
	if [ -d /home/retoor/bin ]; then \
		python -m rp.implode rp.py -o /home/retoor/bin/rp; \
		chmod +x /home/retoor/bin/rp; \
	fi

.DEFAULT_GOAL := help
