.PHONY: help unittest format lint typecheck test act build publish docs docs-build

# Default target
help:
	@echo "Available targets:"
	@echo "  make unittest       - Run unittests with pytest"
	@echo "  make format         - Reformat using ruff"
	@echo "  make lint           - Lint using ruff"
	@echo "  make typecheck      - Typecheck with pyright"
	@echo "  make test           - Run all tests with Docker-based MinIO"
	@echo "  make act            - Run GitHub Actions locally with act"
	@echo "  make build          - Build package for distribution"
	@echo "  make publish        - Publish package to PyPI"
	@echo "  make docs           - Serve docs locally"
	@echo "  make docs-build     - Build docs with strict checking"

# Reformat using ruff
format:
	@echo "==> Formatting all files"
	@uv run ruff format
	@uv run ruff check --fix

# Lint using ruff
lint:
	@echo "==> Linting all files"
	@uv run ruff check

# Typecheck with pyright
typecheck:
	@echo "==> Typechecking"
	@uv run pyright

# Run all tests with Docker-based MinIO
test: lint typecheck
	@echo "==> Detecting Docker context"
	$(eval DOCKER_HOST := $(shell docker context inspect --format '{{.Endpoints.docker.Host}}'))
	@echo "Using Docker context: $(DOCKER_HOST)"
	@echo "==> Running tests with Docker MinIO"
	@DOCKER_HOST=$(DOCKER_HOST) uv run pytest --sw

clean:
	rm -rf data/* metadata/*

act:
	@echo "==> Detecting Docker context"
	$(eval DOCKER_HOST := $(shell docker context inspect --format '{{.Endpoints.docker.Host}}'))
	@echo "Using Docker context: $(DOCKER_HOST)"
	@echo "==> Running GitHub Actions workflow locally with act"
	@DOCKER_HOST=$(DOCKER_HOST) act

build:
	@echo "==> Building package"
	@rm -rf dist
	@uv build
	@uv run twine check dist/*

publish: build
	@echo "==> Publishing to PyPI"
	@uv run twine upload dist/*

docs:
	@echo "==> Serving docs locally"
	@uv run zensical serve

docs-build:
	@echo "==> Building docs"
	@uv run zensical build --clean
