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

async function insertClaimsData() {
  try {
    console.log('开始插入理赔数据...');
    
    // 插入理赔数据
    await sequelize.query(`
      INSERT INTO livestock_claims (
        claim_no, policy_id, claim_type, incident_date, report_date,
        incident_description, incident_location, affected_count, 
        claim_amount, claim_status, investigator_id,
        reviewer_id, created_by, updated_by
      ) VALUES
      ('CL202303050001', 1, 'disease', '2023-03-01', '2023-03-02', '牛群感染口蹄疫，导致5头牛死亡', '内蒙古自治区呼和浩特市赛罕区昭乌达路养殖场', 5, 35000.00, 'approved', 1, 1, 1, 1),
      ('CL202303100002', 2, 'natural_disaster', '2023-03-08', '2023-03-09', '暴雪导致羊舍倒塌，造成10只羊死亡', '内蒙古自治区包头市昆都仑区钢铁大街养殖场', 10, 10000.00, 'investigating', 1, NULL, 1, 1),
      ('CL202302200003', 4, 'accident', '2023-02-18', '2023-02-19', '运输车辆事故，导致3头牛受伤', '内蒙古自治区通辽市科尔沁区建国路', 3, 12000.00, 'pending', NULL, NULL, 1, 1)
    `);
    console.log('✅ 理赔数据插入成功');

    // 验证数据插入结果
    const [claimCount] = await sequelize.query("SELECT COUNT(*) as count FROM livestock_claims");
    console.log(`数据库中共有 ${claimCount[0].count} 条理赔记录`);
    
  } catch (error) {
    console.error('❌ 插入理赔数据失败:', error.message);
    if (error.errors) {
      console.error('详细错误信息:');
      error.errors.forEach(err => {
        console.error(`- ${err.path}: ${err.message}`);
      });
    }
    if (error.sql) {
      console.error('SQL语句:', error.sql);
    }
  } finally {
    await sequelize.close();
  }
}

insertClaimsData();