.PHONY: init install lint format typecheck check fix test release clean


init: precommit-install install

precommit-install:
	pre-commit install

install:
	uv sync --frozen --all-groups --link-mode=copy

lint:
	uv run ruff check .

format:
	uv run ruff format .

format-check:
	uv run ruff format . --check

typecheck:
	uv run mypy .

test:
	uv run pytest

check: lint typecheck test format-check

fix:
	uv run ruff check . --fix
	uv run ruff format .

build:
	uv build

release: clean check build

clean:
	rm -rf .pytest_cache .ruff_cache .mypy_cache dist build *.egg-info .coverage

release: clean check build

	@if [ -z "$(VERSION)" ]; then \
		echo "ERROR: VERSION is required. Usage: make release VERSION=x.y.z"; \
		exit 1; \
	fi
	@echo "Creating release v$(VERSION)..."

	# Update version in pyproject.toml
	@sed -i.bak 's/^version = ".*"/version = "$(VERSION)"/' pyproject.toml && rm pyproject.toml.bak
	
	# Update version in uv.lock
	@sed -i.bak '/^name = "lara-ai"$$/,/^version = / s/^version = ".*"/version = "$(VERSION)"/' uv.lock && rm uv.lock.bak

	# Update version in src/fast_office/config/config.py
	@sed -i.bak 's/^\(\s*API_VERSION\s*:\s*str\s*=\s*\)"[^"]*"/\1"$(VERSION)"/' src/fast_office/config/config.py && rm src/fast_office/config/config.py.bak

	# Git operations
	@echo "Creating release branch and committing..."
	@git checkout main
	@git add pyproject.toml uv.lock src/fast_office/config/config.py
	@git commit -m "Release v$(VERSION)"
	@git push
	@uv publish