#!/bin/bash

echo "=== 移动端页面文件生成器配置验证 ==="
echo ""

# 检查模板文件
echo "📋 检查模板文件："
TEMPLATE_DIR="src/test/java/com/gxwebsoft/generator/templates"

templates=(
    "index.config.ts.btl"
    "index.tsx.btl"
    "add.config.ts.btl"
    "add.tsx.btl"
)

for template in "${templates[@]}"; do
    if [ -f "${TEMPLATE_DIR}/${template}" ]; then
        echo "✅ ${template}"
        # 检查文件大小
        size=$(wc -c < "${TEMPLATE_DIR}/${template}")
        echo "   文件大小: ${size} bytes"
    else
        echo "❌ ${template} 缺失"
    fi
done

echo ""

# 检查生成器配置
echo "🔧 检查生成器配置："

# 检查 ShopGenerator
echo "ShopGenerator.java:"
if grep -q "OUTPUT_LOCATION_UNIAPP.*template-10550" src/test/java/com/gxwebsoft/generator/ShopGenerator.java; then
    echo "✅ UniApp输出路径配置正确"
else
    echo "❌ UniApp输出路径配置错误"
fi

if grep -q "移动端页面文件生成" src/test/java/com/gxwebsoft/generator/ShopGenerator.java; then
    echo "✅ 包含移动端页面生成配置"
    
    # 统计移动端配置数量
    count=$(grep -c "index.config.ts\|index.tsx\|add.config.ts\|add.tsx" src/test/java/com/gxwebsoft/generator/ShopGenerator.java)
    echo "   配置项数量: ${count}/4"
else
    echo "❌ 缺少移动端页面生成配置"
fi

echo ""

# 检查 CmsGenerator
echo "CmsGenerator.java:"
if grep -q "OUTPUT_LOCATION_UNIAPP.*template-10550" src/test/java/com/gxwebsoft/generator/CmsGenerator.java; then
    echo "✅ UniApp输出路径配置正确"
else
    echo "❌ UniApp输出路径配置错误"
fi

if grep -q "移动端页面文件生成" src/test/java/com/gxwebsoft/generator/CmsGenerator.java; then
    echo "✅ 包含移动端页面生成配置"
    
    # 统计移动端配置数量
    count=$(grep -c "index.config.ts\|index.tsx\|add.config.ts\|add.tsx" src/test/java/com/gxwebsoft/generator/CmsGenerator.java)
    echo "   配置项数量: ${count}/4"
else
    echo "❌ 缺少移动端页面生成配置"
fi

echo ""

# 检查输出目录
echo "📁 检查输出目录："
OUTPUT_DIR="/Users/gxwebsoft/VUE/template-10550"

if [ -d "$OUTPUT_DIR" ]; then
    echo "✅ 输出目录存在: $OUTPUT_DIR"
    
    if [ -d "$OUTPUT_DIR/src" ]; then
        echo "✅ src 目录存在"
    else
        echo "⚠️  src 目录不存在，生成时会自动创建"
    fi
else
    echo "❌ 输出目录不存在: $OUTPUT_DIR"
    echo "   请确保该目录存在或修改生成器中的 OUTPUT_LOCATION_UNIAPP 配置"
fi

echo ""

# 检查文档
echo "📚 检查文档："
docs=(
    "docs/MOBILE_PAGE_GENERATOR.md"
    "docs/MOBILE_GENERATOR_EXAMPLE.md"
)

for doc in "${docs[@]}"; do
    if [ -f "$doc" ]; then
        echo "✅ $doc"
    else
        echo "❌ $doc 缺失"
    fi
done

echo ""

echo "=== 验证完成 ==="
echo ""
echo "如果所有检查都通过，您可以："
echo "1. 在生成器中配置 TABLE_NAMES"
echo "2. 运行对应的生成器"
echo "3. 检查生成的移动端页面文件"
