#!/bin/bash

echo "🚀 启动云盘应用开发环境..."

# 检查Docker是否运行
if ! docker info > /dev/null 2>&1; then
    echo "❌ Docker未运行，请先启动Docker"
    exit 1
fi

# 停止现有容器
echo "🛑 停止现有容器..."
docker-compose down

# 构建并启动服务
echo "🔨 构建并启动服务..."
docker-compose up --build -d

# 等待服务启动
echo "⏳ 等待服务启动..."
sleep 10

# 检查服务状态
echo "🔍 检查服务状态..."
docker-compose ps

# 检查健康状态
echo "🏥 检查服务健康状态..."
echo "检查后端API..."
curl -f http://localhost:8000/api/v1/health || echo "❌ 后端API未就绪"

echo "检查数据库连接..."
curl -f http://localhost:8000/api/v1/ready || echo "❌ 数据库连接未就绪"

echo "检查前端..."
curl -f http://localhost:3000 || echo "❌ 前端未就绪"

echo "✅ 开发环境启动完成！"
echo "📝 访问地址："
echo "   前端应用: http://localhost:3000"
echo "   后端API: http://localhost:8000"
echo "   API文档: http://localhost:8000/docs"
echo "   健康检查: http://localhost:8000/api/v1/health"

echo "📊 查看日志: docker-compose logs -f"
echo "🛑 停止服务: docker-compose down"