# Makefile

.PHONY: all build up down restart logs clean tidy test help

# 默认目标
all: build up

# 构建镜像
build:
	docker-compose build

# 启动服务
up:
	docker-compose up -d

# 停止服务
down:
	docker-compose down

# 完全清理（包括数据卷）
clean:
	docker-compose down -v
	docker system prune -f

# 重启服务
restart:
	docker-compose restart

# 查看日志
logs:
	docker-compose logs -f

# 查看 API 日志
logs-api:
	docker-compose logs -f api

# 查看数据库日志
logs-db:
	docker-compose logs -f postgres

# 查看 Redis 日志
logs-redis:
	docker-compose logs -f redis

# 进入 API 容器
shell-api:
	docker-compose exec api sh

# 进入数据库容器
shell-db:
	docker-compose exec postgres psql -U postgres -d appdb

# 进入 Redis 容器
shell-redis:
	docker-compose exec redis redis-cli

# 下载依赖
tidy:
	cd api && go mod tidy

# 运行测试
test:
	cd api && go test -v ./...

# 本地运行
run:
	cd api && go run main.go

# 帮助
help:
	@echo "Available targets:"
	@echo "  make build      - 构建 Docker 镜像"
	@echo "  make up         - 启动所有服务"
	@echo "  make down       - 停止所有服务"
	@echo "  make restart    - 重启所有服务"
	@echo "  make logs       - 查看所有服务日志"
	@echo "  make logs-api   - 查看 API 服务日志"
	@echo "  make logs-db    - 查看数据库日志"
	@echo "  make logs-redis - 查看 Redis 日志"
	@echo "  make shell-api  - 进入 API 容器"
	@echo "  make shell-db   - 进入数据库容器"
	@echo "  make shell-redis- 进入 Redis 容器"
	@echo "  make clean      - 清理所有容器和数据卷"
	@echo "  make tidy       - 整理 Go 依赖"
	@echo "  make test       - 运行测试"
	@echo "  make run        - 本地运行 API 服务"
