.PHONY: install install-dev test test-unit test-integration lint format typecheck clean build help

# Default target
.DEFAULT_GOAL := help

# Variables
PYTHON := python3
PIP := $(PYTHON) -m pip
PYTEST := $(PYTHON) -m pytest
RUFF := $(PYTHON) -m ruff
MYPY := $(PYTHON) -m mypy

help: ## Show this help message
	@echo "LAIDA CLI - Development Commands"
	@echo ""
	@echo "Usage: make [target]"
	@echo ""
	@echo "Targets:"
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-20s\033[0m %s\n", $$1, $$2}'

install: ## Install package in production mode
	$(PIP) install -e .

install-dev: ## Install package with development dependencies
	$(PIP) install -e ".[dev]"

test: ## Run all tests
	$(PYTEST) tests/ -v --cov=src/laida_cli --cov-report=term-missing

test-unit: ## Run unit tests only
	$(PYTEST) tests/unit/ -v -m unit

test-integration: ## Run integration tests only
	$(PYTEST) tests/integration/ -v -m integration

lint: ## Run linting checks
	$(RUFF) check src/ tests/

format: ## Format code with ruff
	$(RUFF) format src/ tests/
	$(RUFF) check --fix src/ tests/

typecheck: ## Run type checking with mypy
	$(MYPY) src/laida_cli/

check: lint typecheck test ## Run all checks (lint, typecheck, test)

clean: ## Clean build artifacts
	rm -rf build/
	rm -rf dist/
	rm -rf *.egg-info/
	rm -rf src/*.egg-info/
	rm -rf .pytest_cache/
	rm -rf .mypy_cache/
	rm -rf .ruff_cache/
	rm -rf .coverage
	rm -rf htmlcov/
	find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete

build: clean ## Build package
	$(PYTHON) -m build

# Development shortcuts
dev: install-dev ## Alias for install-dev

run: ## Run the CLI (example: make run ARGS="status")
	$(PYTHON) -m laida_cli $(ARGS)
