.PHONY: test test-verbose test-cov test-quick install clean build publish publish-test

## Install/sync dependencies
install:
	uv sync --extra dev

## Run full test suite with coverage
test:
	uv run --extra dev python -m pytest

## Run tests with verbose output
test-verbose:
	uv run --extra dev python -m pytest -v

## Run tests without coverage (faster)
test-quick:
	uv run --extra dev python -m pytest --no-cov

## Run tests and show detailed coverage report
test-cov:
	uv run --extra dev python -m pytest --cov-report=html
	@echo "HTML report: htmlcov/index.html"

## Run a specific test file (usage: make test-file F=tests/test_parsers/test_mule_xml.py)
test-file:
	uv run --extra dev python -m pytest $(F) -v --no-cov

## Run tests matching a keyword (usage: make test-k K=curl)
test-k:
	uv run --extra dev python -m pytest -k "$(K)" -v --no-cov

## Build distribution packages
build: clean
	uv build

## Publish to PyPI
publish: build
	UV_PUBLISH_USERNAME=__token__ \
	UV_PUBLISH_PASSWORD=$$(python3 -c "import configparser; c = configparser.ConfigParser(); c.read('$$HOME/.pypirc'); print(c['pypi']['password'])") \
	uv publish

## Publish to TestPyPI
publish-test: build
	UV_PUBLISH_USERNAME=__token__ \
	UV_PUBLISH_PASSWORD=$$(python3 -c "import configparser; c = configparser.ConfigParser(); c.read('$$HOME/.pypirc'); print(c['testpypi']['password'])") \
	uv publish --publish-url https://test.pypi.org/legacy/

## Remove build artifacts and caches
clean:
	rm -rf dist build htmlcov .coverage .pytest_cache
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
