.PHONY: help install dev-install run test test-unit test-integration test-e2e test-coverage lint format clean build check all commit bump mcp-dev mcp-run mcp-version mcp-install configure-cline

# Default target
help:
	@echo "Available targets:"
	@echo "  install         - Install dependencies"
	@echo "  dev-install     - Install development dependencies"
	@echo "  run             - Run the main application"
	@echo "  test            - Run tests"
	@echo "  test-unit       - Run only unit tests"
	@echo "  test-integration - Run only integration tests"
	@echo "  test-e2e        - Run only end-to-end tests"
	@echo "  test-coverage   - Run tests with coverage report"
	@echo "  lint            - Run linting checks"
	@echo "  format          - Format code"
	@echo "  check           - Run all checks (lint + test)"
	@echo "  clean           - Clean build artifacts"
	@echo "  build           - Build the package"
	@echo "  commit          - Create a conventional commit using commitizen"
	@echo "  bump            - Bump version using commitizen"
	@echo "  all             - Install deps, format, lint, test, and build"
	@echo "  mcp-dev         - Run MCP server with inspector for development"
	@echo "  mcp-run         - Run MCP server in production mode"
	@echo "  mcp-version     - Show MCP SDK version"
	@echo "  mcp-install     - Install MCP server in Claude desktop app"
	@echo "  configure-cline - Configure Cline with auto-approval settings"

# Install dependencies
install:
	uv sync

# Install development dependencies
dev-install:
	uv sync --dev

# Run the main application
run:
	uv run python main.py

# Run tests
# Usage: make test [pytest options and arguments]
# Examples:
#   make test tests/unit/services/test_gitpython_core.py
#   make test -k security
#   make test tests/unit/services/test_gitpython_core.py::TestSecurityFunctions
test:
	uv run pytest -v -x $(filter-out $@,$(MAKECMDGOALS)) $(ARGS)

# Run only unit tests
test-unit:
	uv run pytest -v -x -m unit $(ARGS)

# Run only integration tests
test-integration:
	uv run pytest -v -x -m integration $(ARGS)

# Run only end-to-end tests
test-e2e:
	uv run pytest -v -x -m e2e $(ARGS)

# Run tests with coverage
test-coverage:
	uv run pytest --cov=src/commit_helper_mcp $(ARGS)

# Allow any arguments after test target to be passed through
%:
	@:

# Run linting checks (placeholder - add linter as needed)
lint:
	@echo "No linter configured yet. Consider adding ruff, flake8, or pylint."
	# uv run ruff check .
	# uv run mypy .

# Format code (placeholder - add formatter as needed)
format:
	uv run ruff format .

# Run all checks
check: lint test

# Clean build artifacts
clean:
	rm -rf build/
	rm -rf dist/
	rm -rf *.egg-info/
	find . -type d -name __pycache__ -exec rm -rf {} +
	find . -type f -name "*.pyc" -delete

# Build the package
build: clean
	uv build

# Run all common development tasks
all: install format lint test build

# Create a conventional commit using commitizen
commit:
	uv tool run --from commitizen cz commit

# Bump version using commitizen
bump:
	uv tool run --from commitizen cz bump

# Development server (if applicable)
dev:
	uv run python main.py

# MCP SDK Commands
mcp-dev:
	DANGEROUSLY_OMIT_AUTH=true uv run mcp dev main.py

# Run MCP server in production mode
mcp-run:
	uv run mcp run main.py

# Show MCP SDK version
mcp-version:
	uv run mcp version

# Install MCP server in Claude desktop app
mcp-install:
	uv run mcp install main.py

# Configure Cline with MCP server and auto-approval settings
configure-cline:
	@echo "🔧 Configuring Cline with Commitizen MCP Connector..."
	python configure_cline.py
	@echo ""
	@echo "✅ Configuration complete!"
	@echo "🔄 Please restart Cline to apply the new settings."
	@echo ""
	@echo "📋 Next steps:"
	@echo "  1. Restart Cline (close and reopen the panel)"
	@echo "  2. Navigate to any git repository"
	@echo "  3. Test with: 'Use health_check tool to verify the server'"
