.PHONY: help install test test-cov lint clean build publish check demo

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

install: ## Install development dependencies
	pip install -e ".[dev]"

test: ## Run tests
	pytest tests/ -v

test-cov: ## Run tests with coverage
	pytest tests/ -v --cov=envcompare --cov-report=html --cov-report=term
	@echo "Coverage report: htmlcov/index.html"

test-ci: ## Run tests as CI would
	pytest tests/ -v --cov=envcompare --cov-report=xml --strict-markers

lint: ## Check code style (if tools installed)
	@echo "No linter configured - keep it simple!"

clean: ## Clean build artifacts
	rm -rf build/ dist/ *.egg-info/ .pytest_cache/ .coverage 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
	twine check dist/*

publish: build ## Publish to PyPI
	twine upload dist/*

publish-test: build ## Publish to TestPyPI
	twine upload --repository testpypi dist/*

check: test lint ## Run all checks

demo: ## Run demo comparison
	@echo "Creating demo files..."
	@echo "DATABASE_URL=postgres://localhost/db" > /tmp/.env.example
	@echo "SECRET_KEY=secret123" >> /tmp/.env.example
	@echo "PORT=8080" >> /tmp/.env.example
	@echo "DEBUG=false" >> /tmp/.env.example
	@echo "" >> /tmp/.env.example
	@echo "DATABASE_URL=postgres://prod/db" > /tmp/.env.production
	@echo "PORT=\"8080\"" >> /tmp/.env.production
	@echo "DEBUG=true" >> /tmp/.env.production
	@echo ""
	@echo "=== Demo: envcompare in action ==="
	@python -m envcompare.cli /tmp/.env.example /tmp/.env.production || true
	@rm /tmp/.env.example /tmp/.env.production

demo-json: ## Run demo with JSON output
	@echo "DATABASE_URL=postgres://localhost/db" > /tmp/.env.example
	@echo "SECRET_KEY=secret123" >> /tmp/.env.example
	@echo "DATABASE_URL=postgres://prod/db" > /tmp/.env
	@echo ""
	@echo "=== Demo: JSON output ==="
	@python -m envcompare.cli /tmp/.env.example /tmp/.env --format json
	@rm /tmp/.env.example /tmp/.env

version: ## Show current version
	@python -m envcompare.cli --version

help-cli: ## Show CLI help
	@python -m envcompare.cli --help

release-patch: ## Bump patch version and publish
	@echo "Not automated yet. Manually update:"
	@echo "  1. envcompare/__init__.py"
	@echo "  2. CHANGELOG.md"
	@echo "  3. git tag vX.Y.Z"
	@echo "  4. make publish"