.PHONY: help up down logs backend-shell migrate migration test lint typecheck codegen pre-commit-install

help:
	@echo "make up                 - start all services (Postgres, Redis, backend, frontend)"
	@echo "make down               - stop all services"
	@echo "make logs               - tail logs from all services"
	@echo "make backend-shell      - shell into backend container"
	@echo "make migrate            - run alembic upgrade head"
	@echo "make migration NAME=... - autogenerate a new alembic migration"
	@echo "make test               - run backend pytest"
	@echo "make lint               - ruff check"
	@echo "make typecheck          - mypy on core modules"
	@echo "make codegen            - regenerate frontend TS types from backend OpenAPI"
	@echo "make pre-commit-install - install local git hooks (runs ruff/prettier on commit)"

up:
	docker compose up -d --build

down:
	docker compose down

logs:
	docker compose logs -f --tail=100

backend-shell:
	docker compose exec backend bash

migrate:
	docker compose exec backend alembic upgrade head

migration:
	@if [ -z "$(NAME)" ]; then echo "Usage: make migration NAME=add_parcel_table"; exit 1; fi
	docker compose exec backend alembic revision --autogenerate -m "$(NAME)"

test:
	cd backend && uv run pytest -q

lint:
	cd backend && uv run ruff check .

typecheck:
	cd backend && uv run mypy app/services/generative app/services/site_finder/scorer.py

codegen:
	cd frontend && npm run codegen

pre-commit-install:
	pip install pre-commit && pre-commit install
