# 项目常用命令模板
# 按你的实际技术栈调整路径和命令。
#
# 用法：
#   make dev          # 启动本地依赖（数据库等）
#   make dev-api      # 启动后端
#   make dev-web      # 启动前端
#   make test
#   make lint
#   make e2e
#   make report STORY=US-004 ENV=dev
#   make migrate-up
#   make build

STORY ?= US-001
ENV ?= dev
COMPOSE_FILE ?= docker-compose.dev.yml

.PHONY: dev dev-deps dev-api dev-web test test-unit test-integration lint e2e report migrate-up build clean

dev: dev-deps
	@echo ""
	@echo "依赖已启动。请分别运行："
	@echo "  make dev-api   # 后端"
	@echo "  make dev-web   # 前端"

dev-deps:
	docker compose -f $(COMPOSE_FILE) up -d

dev-api:
	cd backend && go run ./cmd/api

dev-web:
	cd frontend && npm run dev

test: test-unit test-integration

test-unit:
	cd backend && go test -race ./...
	cd frontend && npm run test

test-integration:
	cd backend && go test -tags=integration ./...

lint:
	cd backend && test -z "$$(gofmt -l .)" && go vet ./... && golangci-lint run
	cd frontend && npm run typecheck && npm run lint

e2e:
	./scripts/start-chrome-debug.sh
	@echo ""
	@echo "Chrome 调试端点已就绪。请用 Chrome MCP 执行 $(STORY) 的 E2E，"
	@echo "并生成 docs/04-qa/manifests/$(STORY).json。"

report:
	python3 scripts/build_test_report.py \
		--manifest docs/04-qa/manifests/$(STORY).json \
		--qa-root docs/04-qa \
		--out docs/04-qa/e2e-report-$(ENV)-$$(date +%Y%m%d).docx \
		--project "$$(basename $$(pwd))"

migrate-up:
	cd backend && goose -dir migrations postgres "$$DATABASE_URL" up

build:
	cd backend && go build -o bin/api ./cmd/api
	cd frontend && npm run build

clean:
	rm -rf backend/bin frontend/dist
	docker compose -f $(COMPOSE_FILE) down
