#!/bin/bash

echo "🚀 啟動 DramaLing .NET Core API..."

# 設定 PATH
export PATH="$HOME/.dotnet:$PATH"
export DOTNET_ROOT="$HOME/.dotnet"

# 檢查 .NET SDK
if ! command -v dotnet &> /dev/null; then
    echo "❌ .NET SDK 未安裝或 PATH 未設定"
    echo "請執行: source ~/.zshrc"
    exit 1
fi

echo "✅ .NET SDK 版本: $(dotnet --version)"

# 進入專案目錄
cd backend/DramaLing.Api

# 恢復套件 (如果需要)
echo "📦 恢復 NuGet 套件..."
dotnet restore

# 建置專案
echo "🔨 建置專案..."
dotnet build

if [ $? -eq 0 ]; then
    echo "✅ 建置成功！"
    echo "🌐 啟動 API 服務..."
    echo "📍 API 端點: http://localhost:5000"
    echo "📊 Swagger UI: http://localhost:5000/swagger"
    echo "💓 健康檢查: http://localhost:5000/health"
    echo ""

    # 啟動 API
    dotnet run --urls="http://localhost:5000"
else
    echo "❌ 建置失敗"
    exit 1
fi