.PHONY: help install dev-install test test-unit test-integration clean lint format run build uninstall reinstall publish-test publish-prod publish-dry-run bump-major bump-minor bump-patch version

# Default target
help:
	@echo "Available commands:"
	@echo ""
	@echo "Development:"
	@echo "  make install          - Install the package in editable mode"
	@echo "  make dev-install      - Install package with dev dependencies"
	@echo "  make test             - Run all tests"
	@echo "  make test-unit        - Run unit tests only"
	@echo "  make test-integration - Run integration tests only"
	@echo "  make lint             - Run linter (ruff check)"
	@echo "  make fix              - Fix linter issues automatically"
	@echo "  make format           - Format code (ruff format)"
	@echo "  make clean            - Clean up cache and build files"
	@echo "  make build            - Build the package"
	@echo "  make reinstall        - Reinstall the package"
	@echo "  make run              - Run CLI with --help"
	@echo ""
	@echo "Publishing:"
	@echo "  make version          - Show current version"
	@echo "  make bump-patch       - Bump patch version (0.1.0 -> 0.1.1)"
	@echo "  make bump-minor       - Bump minor version (0.1.0 -> 0.2.0)"
	@echo "  make bump-major       - Bump major version (0.1.0 -> 1.0.0)"
	@echo "  make publish-dry-run  - Dry run of publishing (no actual upload)"
	@echo "  make publish-test     - Publish to Test PyPI"
	@echo "  make publish-prod     - Publish to Production PyPI"

# Install package in editable mode
install:
	uv sync

# Install with dev dependencies
dev-install:
	uv sync --group dev

# Run all tests
test:
	uv run pytest tests/ -v

# Run unit tests only
test-unit:
	uv run pytest tests/test_commands/ -v

# Run integration tests only (requires REPORTIFY_API_KEY)
test-integration:
	uv run pytest tests/integration/ -v

# Run linter
lint:
	uv run ruff check src/ tests/

fix:
	uv run ruff check src/ tests/ --fix

# Format code
format:
	uv run ruff format src/ tests/

# Clean cache and build files
clean:
	rm -rf __pycache__
	rm -rf src/__pycache__
	rm -rf src/commands/__pycache__
	rm -rf tests/__pycache__
	rm -rf tests/test_commands/__pycache__
	rm -rf tests/integration/__pycache__
	rm -rf .pytest_cache
	rm -rf .ruff_cache
	rm -rf build/
	rm -rf dist/
	rm -rf *.egg-info
	rm -rf reportify_api_cli.egg-info
	find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete

# Build the package
build:
	uv build

# Reinstall the package (clean sync)
reinstall:
	uv sync --reinstall

# Run CLI with --help
run:
	uv run reportify-cli --help

# Show current version
version:
	@grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/'

# Bump patch version (0.1.0 -> 0.1.1)
bump-patch:
	@./scripts/bump_version.sh patch

# Bump minor version (0.1.0 -> 0.2.0)
bump-minor:
	@./scripts/bump_version.sh minor

# Bump major version (0.1.0 -> 1.0.0)
bump-major:
	@./scripts/bump_version.sh major

# Dry run of publishing (no actual upload)
publish-dry-run:
	@./scripts/publish.sh test dry-run

# Publish to Test PyPI
publish-test:
	@./scripts/publish.sh test

# Publish to Production PyPI
publish-prod:
	@./scripts/publish.sh prod


