.PHONY: setup setup-backend setup-frontend dev dev-backend dev-frontend db-up db-migrate test clean

# ─── Setup ───────────────────────────────────────────────────────────
setup: setup-backend setup-frontend

setup-backend:
	cd backend && python3.12 -m venv .venv
	cd backend && .venv/bin/pip install --upgrade pip
	cd backend && .venv/bin/pip install -e ".[dev]"
	cd backend && .venv/bin/pip install "deepgaze-pytorch @ git+https://github.com/matthias-k/DeepGaze.git"
	cd backend && .venv/bin/pip install "clip @ git+https://github.com/openai/CLIP.git"

setup-frontend:
	cd frontend && npm install

# ─── Database ────────────────────────────────────────────────────────
db-up:
	docker compose up -d postgres

db-migrate:
	cd backend && .venv/bin/alembic upgrade head

db-revision:
	cd backend && .venv/bin/alembic revision --autogenerate -m "$(msg)"

# ─── Development ─────────────────────────────────────────────────────
dev: db-up dev-backend dev-frontend

dev-backend:
	cd backend && .venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload

dev-frontend:
	cd frontend && npm run dev

# ─── Docker ──────────────────────────────────────────────────────────
docker-up:
	docker compose up --build

docker-down:
	docker compose down

# ─── Testing ─────────────────────────────────────────────────────────
test:
	cd backend && .venv/bin/pytest -v

test-backend:
	cd backend && .venv/bin/pytest -v

# ─── Utilities ───────────────────────────────────────────────────────
lint:
	cd backend && .venv/bin/ruff check app/ tests/

lint-fix:
	cd backend && .venv/bin/ruff check --fix app/ tests/

clean:
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type d -name .pytest_cache -exec rm -rf {} + 2>/dev/null || true
	rm -rf backend/.venv frontend/node_modules
