.DEFAULT_GOAL := help
PACKAGE_NAME := pixel_drawing_pad

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

.PHONY: install
install: ## Install package in editable mode with dev dependencies
	uv pip install -e ".[dev]"

.PHONY: sync
sync: ## Sync environment from pyproject.toml
	uv sync --extra dev

.PHONY: lint
lint: ## Run ruff linter and formatter check
	uv run ruff check src/ tests/
	uv run ruff format --check src/ tests/

.PHONY: format
format: ## Auto-format code with ruff
	uv run ruff check --fix src/ tests/
	uv run ruff format src/ tests/

.PHONY: test
test: ## Run tests with pytest
	uv run pytest

.PHONY: test-cov
test-cov: ## Run tests with coverage
	uv run pytest --cov=$(PACKAGE_NAME) --cov-report=term-missing

.PHONY: clean
clean: ## Remove build artifacts
	rm -rf dist/ build/ *.egg-info src/*.egg-info
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name '*.pyc' -delete 2>/dev/null || true

.PHONY: dist
dist: clean ## Build source and wheel package
	uv build
	ls -l dist/

.PHONY: release
release: dist ## Build and upload to PyPI
	uv publish --username __token__ --password "$$(python3 -c "import configparser; c=configparser.ConfigParser(); c.read('$$HOME/.pypirc'); print(c['pypi']['password'])")"

.PHONY: release-test
release-test: dist ## Build and upload to Test PyPI
	uv publish --publish-url https://test.pypi.org/legacy/ --username __token__ --password "$$(python3 -c "import configparser; c=configparser.ConfigParser(); c.read('$$HOME/.pypirc'); print(c['test']['password'])")"

.PHONY: check
check: lint test ## Run lint + tests
