#!/usr/bin/env bash
# =============================================================================
# sanguo_quant_live 调研文档更新自动化脚本
# 作者: 姜维（后勤总督）
# 版本: v1.0
# =============================================================================

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"

# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

print_info() {
    echo -e "${BLUE}[INFO]${NC} $1"
}

print_success() {
    echo -e "${GREEN}[SUCCESS]${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}[WARNING]${NC} $1"
}

print_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

cd "$PROJECT_ROOT"

print_info "检查调研文档..."
RESEARCH_DOC="platform/research/ALIBABA_CLOUD_DEPLOYMENT_RESEARCH.md"

if [ ! -f "$RESEARCH_DOC" ]; then
    print_error "调研文档不存在: $RESEARCH_DOC"
    exit 1
fi

print_info "检查变更..."
if git diff --quiet "$RESEARCH_DOC" && git diff --cached --quiet "$RESEARCH_DOC"; then
    print_warning "调研文档没有变更"
    exit 0
fi

print_info "提交调研文档更新..."
git add "$RESEARCH_DOC"

# 生成 commit message
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
git commit -m "docs(platform): 姜维更新阿里云部署调研 - $TIMESTAMP

调研内容更新:
- 最小费用方案已完善
- 成本优化策略已更新
- 架构设计已优化"

print_info "推送到 Gitee..."
git push origin main

print_success "调研文档更新和推送完成！"
