# Legate Agent — developer task runner.
# These targets assume a POSIX shell (Linux/macOS or WSL/Git Bash on Windows).

API_DIR := apps/api
WEB_DIR := apps/web

.PHONY: help install install-api install-web up down logs migrate \
        test test-api lint lint-api format format-api typecheck

help:
	@echo "Targets:"
	@echo "  install      Install backend + frontend dependencies"
	@echo "  up           docker compose up (all services)"
	@echo "  down         docker compose down"
	@echo "  migrate      Run Alembic migrations inside the api container"
	@echo "  test         Run the full backend test suite"
	@echo "  lint         Run ruff + mypy (backend) and eslint (frontend)"
	@echo "  format       Run black (backend) and prettier (frontend)"

install: install-api install-web

install-api:
	cd $(API_DIR) && python -m pip install -e ".[dev]"

install-web:
	cd $(WEB_DIR) && npm install

up:
	docker compose up --build

down:
	docker compose down

logs:
	docker compose logs -f

migrate:
	cd $(API_DIR) && alembic upgrade head

backup:
	@echo "Backing up PostgreSQL + object storage (see docs/backup.md)."
	pg_dump "$(DATABASE_URL)" -Fc -f legate-backup-$$(date +%F).dump
	tar czf legate-storage-$$(date +%F).tgz $(API_DIR)/data/storage 2>/dev/null || true
	@echo "Remember: back up LEGATE_MASTER_KEY separately — it is not in the database."

test: test-api

test-api:
	cd $(API_DIR) && python -m pytest -q

lint: lint-api

lint-api:
	cd $(API_DIR) && ruff check legate tests && mypy legate

format: format-api

format-api:
	cd $(API_DIR) && black legate tests && ruff check --fix legate tests

typecheck:
	cd $(API_DIR) && mypy legate
