# AI近视防控系统 - Makefile

.PHONY: help build test run docker-build docker-run clean db-migrate

# 默认目标
help:
	@echo "AI近视防控系统 Makefile"
	@echo ""
	@echo "可用命令:"
	@echo "  help         - 显示此帮助信息"
	@echo "  build        - 构建项目"
	@echo "  test         - 运行测试"
	@echo "  run          - 运行项目"
	@echo "  docker-build - 构建Docker镜像"
	@echo "  docker-run   - 运行Docker容器"
	@echo "  clean        - 清理构建产物"
	@echo "  db-migrate   - 数据库迁移"

# 构建项目
build:
	@echo "构建AI近视防控系统..."
	go build -o bin/server cmd/main.go
	@echo "构建完成: bin/server"

# 运行测试
test:
	@echo "运行单元测试..."
	go test -v ./tests/unit/...
	@echo "运行集成测试..."
	go test -v ./tests/integration/...
	@echo "运行API测试..."
	go test -v ./tests/api/...

# 运行项目（开发模式）
run:
	@echo "启动AI近视防控系统..."
	go run cmd/main.go

# 构建Docker镜像
docker-build:
	@echo "构建Docker镜像..."
	docker build -t ai-myopia-prevention:latest .

# 运行Docker容器
docker-run:
	@echo "运行Docker容器..."
	docker run -d -p 8080:8080 --env-file .env ai-myopia-prevention:latest

# 清理构建产物
clean:
	@echo "清理构建产物..."
	rm -rf bin/
	rm -rf dist/

# 数据库迁移
db-migrate:
	@echo "执行数据库迁移..."
	go run scripts/migrate.go

# 安装依赖
deps:
	@echo "安装Go依赖..."
	go mod tidy
	go mod vendor

# 生成代码（如gRPC代码）
gen:
	@echo "生成代码..."
	# 这里可以添加protoc命令生成gRPC代码
	# protoc --go_out=. --go-grpc_out=. api/proto/*.proto

# 代码格式化
fmt:
	@echo "格式化代码..."
	go fmt ./...

# 代码检查
lint:
	@echo "检查代码..."
	golangci-lint run

# 安全扫描
security:
	@echo "执行安全扫描..."
	gosec ./...

# 覆盖率
coverage:
	@echo "生成测试覆盖率报告..."
	go test -coverprofile=coverage.out ./...
	go tool cover -html=coverage.out -o coverage.html
	@echo "覆盖率报告已生成: coverage.html"

# 开发环境启动
dev: deps run

# 完整构建流程
all: deps build test