/**
 * Check Services and Categories Data
 */

const { sequelize } = require('../config/database');
const Service = require('../models/Service');
const Category = require('../models/Category');

async function checkServicesData() {
  console.log('🔍 检查服务和分类数据...\n');

  try {
    await sequelize.authenticate();
    console.log('✅ 数据库连接成功\n');

    // Check categories
    console.log('📂 检查分类数据...');
    const categories = await Category.findAll({
      attributes: ['id', 'name', 'icon', 'sortOrder']
    });
    
    console.log(`   总分类数: ${categories.length}\n`);
    
    if (categories.length > 0) {
      console.log('   分类列表:');
      categories.forEach((cat, index) => {
        console.log(`   ${index + 1}. ${cat.name.zh} (${cat.name.en})`);
        console.log(`      ID: ${cat.id}`);
        console.log(`      排序: ${cat.sortOrder}\n`);
      });
    }

    // Check services
    console.log('📋 检查服务数据...');
    const services = await Service.findAll({
      include: [{
        model: Category,
        as: 'category',
        attributes: ['id', 'name']
      }],
      attributes: ['id', 'name', 'price', 'categoryId', 'isActive']
    });
    
    console.log(`   总服务数: ${services.length}\n`);
    
    if (services.length > 0) {
      console.log('   服务列表:');
      services.forEach((service, index) => {
        console.log(`   ${index + 1}. ${service.name.zh} (${service.name.en})`);
        console.log(`      ID: ${service.id}`);
        console.log(`      价格: ¥${service.price}`);
        console.log(`      分类: ${service.category ? service.category.name.zh : '无'}`);
        console.log(`      状态: ${service.isActive ? '启用' : '禁用'}\n`);
      });
    } else {
      console.log('   ⚠️  没有找到任何服务数据！');
      console.log('   💡 建议: 在管理后台添加服务\n');
    }

    console.log('✅ 检查完成！\n');

  } catch (error) {
    console.error('❌ 检查过程中出错:', error.message);
    console.error(error);
  } finally {
    await sequelize.close();
  }
}

// Run check
checkServicesData();
