.PHONY: install format lint typecheck test build check-tag-version clean

install:
	uv sync --all-groups

format:
	uv run black src/ tests/
	uv run ruff check --fix src/ tests/

lint:
	uv run ruff check src/ tests/
	uv run black --check src/ tests/

typecheck:
	uv run mypy --package hostel.protocol --package hostel.transport --package hostel.client

test:
	uv run pytest

build:
	uv build

clean:
	uv cache clean
	find . -type d -name __pycache__ | xargs rm -rf
	find . -type d -name "*.egg-info" | xargs rm -rf
	rm -rf .venv dist build

check-tag-version:
	@test -n "$(TAG)" || (echo "Usage: make check-tag-version TAG=vX.Y.Z"; exit 1)
	@uv run python -c "import pathlib, sys, tomllib; p=pathlib.Path('pyproject.toml'); v=tomllib.loads(p.read_text())['project']['version']; t='$(TAG)'; expected=f'v{v}';\
print(f'pyproject version: {v}'); print(f'tag: {t}');\
sys.exit(0 if t == expected else 1)"
	@echo "Tag and project version are synchronized."
