#!/bin/bash
# validate-config.sh — 验证 SCALE OS 配置完整性
set -e

echo "🔍 验证 SCALE OS 配置..."
echo ""

PASS=0
FAIL=0
WARN=0

check() {
  local name="$1"
  local path="$2"
  local required="$3"
  
  if [ -e "$path" ]; then
    echo "  ✅ $name"
    PASS=$((PASS + 1))
  elif [ "$required" = "true" ]; then
    echo "  ❌ $name (缺失: $path)"
    FAIL=$((FAIL + 1))
  else
    echo "  ⚠️  $name (可选, 缺失: $path)"
    WARN=$((WARN + 1))
  fi
}

echo "📁 项目级文件:"
check "AGENTS.md" "AGENTS.md" "true"
check "TOOLS.md" "TOOLS.md" "true"
check ".openclaw/settings.json" ".openclaw/settings.json" "true"

echo ""
echo "📁 SCALE 配置:"
check ".scale/ 目录" ".scale" "true"
check "workflow.json" ".scale/workflow.json" "true"
check "quality-contract.json" ".scale/quality-contract.json" "true"
check "skills-registry.json" ".scale/skills-registry.json" "true"
check "verification.json" ".scale/verification.json" "true"
check "skills.json" ".scale/skills.json" "true"
check "tools.json" ".scale/tools.json" "true"
check ".gitignore" ".scale/.gitignore" "true"

echo ""
echo "📁 工作流模板:"
check "docs/workflow/ 目录" "docs/workflow" "true"
check "QUALITY_CONTRACT.md" "docs/workflow/QUALITY_CONTRACT.md" "true"

echo ""
echo "📁 验证脚本:"
check "scripts/validate-config.sh" "scripts/validate-config.sh" "true"
check "scripts/qa/product-smoke.sh" "scripts/qa/product-smoke.sh" "true"

echo ""
echo "────────────────────────────────────"
echo "结果: ✅ $PASS 通过 | ❌ $FAIL 失败 | ⚠️  $WARN 警告"

if [ $FAIL -gt 0 ]; then
  echo "❌ 配置验证失败"
  exit 1
else
  echo "✅ 配置验证通过"
  exit 0
fi
