# Makefile (레포 루트)
.PHONY: help install fe be dev test lint format health seed migrate clean

FRONT := frontend
BACK  := backend

help:
	@echo "make install   - 프론트/백 의존성 설치"
	@echo "make dev       - 프론트(3000)+백(8000) 동시 실행"
	@echo "make fe        - 프론트만 (next dev)"
	@echo "make be        - 백엔드만 (uvicorn --reload)"
	@echo "make test      - pytest + vitest"
	@echo "make lint      - ruff + eslint"
	@echo "make health    - 두 health 엔드포인트 curl"
	@echo "make seed      - DB 시드 적재"
	@echo "make migrate   - alembic upgrade head"

install:
	cd $(FRONT) && pnpm install
	cd $(BACK)  && uv sync

fe:
	cd $(FRONT) && pnpm dev

be:
	cd $(BACK) && uv run uvicorn app.main:app --reload --port 8000

# 두 서버 동시 실행: Ctrl-C 시 둘 다 정리.
dev:
	@echo "▶ backend :8000 / frontend :3000 (Ctrl-C 로 종료)"
	@trap 'kill 0' INT TERM EXIT; \
	( cd $(BACK) && uv run uvicorn app.main:app --reload --port 8000 ) & \
	( cd $(FRONT) && pnpm dev ) & \
	wait

test:
	cd $(BACK)  && uv run pytest
	cd $(FRONT) && pnpm test

lint:
	cd $(BACK)  && uv run ruff check .
	cd $(FRONT) && pnpm lint

format:
	cd $(BACK)  && uv run ruff format . && uv run black .
	cd $(FRONT) && pnpm format

health:
	@echo "── /api/health ──"     && curl -s http://localhost:8000/api/health     | python3 -m json.tool
	@echo "── /api/llm/health ──" && curl -s http://localhost:8000/api/llm/health | python3 -m json.tool

seed:
	cd $(BACK) && uv run python -m app.seed

migrate:
	cd $(BACK) && uv run alembic upgrade head

clean:
	rm -rf $(FRONT)/.next $(BACK)/ari.db $(BACK)/.pytest_cache
