const Vaccine = require('../models/Vaccine')
const sequelize = require('../config/database')

// 疫苗测试数据
const vaccineData = [
  {
    name: '口蹄疫疫苗（O型-亚洲I型）二价灭活疫苗',
    type: 'foot_and_mouth_disease',
    manufacturer: '中国农业科学院兰州兽医研究所',
    approvalNumber: '兽药生字（2020）050356789',
    specification: '10ml/瓶',
    price: 8.5,
    validDays: 365,
    storageCondition: '2-8℃冷藏保存',
    notes: '',
    stockCount: 1200,
    status: 'valid'
  },
  {
    name: '牛结核病提纯蛋白衍生物（PPD）检测试剂',
    type: 'bovine_tuberculosis',
    manufacturer: '中国兽医药品监察所',
    approvalNumber: '兽药生字（2020）010123456',
    specification: '1ml/瓶',
    price: 15.0,
    validDays: 270,
    storageCondition: '2-8℃冷藏保存',
    notes: '用于牛结核病的皮内变态反应检测',
    stockCount: 850,
    status: 'valid'
  },
  {
    name: '布鲁氏菌病活疫苗（S2株）',
    type: 'brucellosis',
    manufacturer: '中国农业科学院哈尔滨兽医研究所',
    approvalNumber: '兽药生字（2020）080789012',
    specification: '100头份/瓶',
    price: 22.5,
    validDays: 180,
    storageCondition: '2-8℃冷藏保存',
    notes: '用于预防牛、羊布鲁氏菌病',
    stockCount: 430,
    status: 'valid'
  },
  {
    name: '狂犬病疫苗（灭活疫苗）',
    type: 'rabies',
    manufacturer: '武汉生物制品研究所有限责任公司',
    approvalNumber: '兽药生字（2020）170456789',
    specification: '1ml/瓶',
    price: 35.0,
    validDays: 365,
    storageCondition: '2-8℃冷藏保存',
    notes: '',
    stockCount: 520,
    status: 'valid'
  },
  {
    name: '牛支原体肺炎疫苗（灭活疫苗）',
    type: 'other',
    manufacturer: '青岛易邦生物工程有限公司',
    approvalNumber: '兽药生字（2020）150234567',
    specification: '20ml/瓶',
    price: 45.0,
    validDays: 270,
    storageCondition: '2-8℃冷藏保存',
    notes: '用于预防牛支原体肺炎',
    stockCount: 180,
    status: 'low_stock'
  },
  {
    name: '牛副伤寒疫苗（灭活疫苗）',
    type: 'other',
    manufacturer: '中牧实业股份有限公司',
    approvalNumber: '兽药生字（2020）010678901',
    specification: '100ml/瓶',
    price: 98.0,
    validDays: 365,
    storageCondition: '2-8℃冷藏保存',
    notes: '用于预防牛副伤寒',
    stockCount: 65,
    status: 'low_stock'
  },
  {
    name: '牛流行热疫苗（灭活疫苗）',
    type: 'other',
    manufacturer: '金宇保灵生物药品有限公司',
    approvalNumber: '兽药生字（2020）050345678',
    specification: '10ml/瓶',
    price: 28.0,
    validDays: 180,
    storageCondition: '2-8℃冷藏保存',
    notes: '用于预防牛流行热',
    stockCount: 320,
    status: 'valid'
  },
  {
    name: '牛病毒性腹泻/粘膜病疫苗（弱毒疫苗）',
    type: 'other',
    manufacturer: '北京世纪元亨动物防疫技术有限公司',
    approvalNumber: '兽药生字（2020）010890123',
    specification: '10头份/瓶',
    price: 32.0,
    validDays: 270,
    storageCondition: '-15℃以下冷冻保存',
    notes: '用于预防牛病毒性腹泻/粘膜病',
    stockCount: 0,
    status: 'expired'
  },
  {
    name: '羊痘疫苗（弱毒疫苗）',
    type: 'other',
    manufacturer: '内蒙古生物药品厂',
    approvalNumber: '兽药生字（2020）150567890',
    specification: '50头份/瓶',
    price: 18.0,
    validDays: 180,
    storageCondition: '2-8℃冷藏保存',
    notes: '用于预防羊痘',
    stockCount: 280,
    status: 'valid'
  },
  {
    name: '羊口疮疫苗（弱毒疫苗）',
    type: 'other',
    manufacturer: '新疆天康生物制药股份有限公司',
    approvalNumber: '兽药生字（2020）650123456',
    specification: '100头份/瓶',
    price: 25.0,
    validDays: 270,
    storageCondition: '2-8℃冷藏保存',
    notes: '用于预防羊口疮',
    stockCount: 150,
    status: 'low_stock'
  }
]

async function seedVaccines() {
  try {
    console.log('开始添加疫苗测试数据...')
    
    // 清空现有数据
    await Vaccine.destroy({ where: {} })
    console.log('已清空现有疫苗数据')
    
    // 添加测试数据
    for (const vaccine of vaccineData) {
      await Vaccine.create(vaccine)
    }
    
    console.log(`成功添加 ${vaccineData.length} 条疫苗测试数据`)
    
    // 验证数据
    const count = await Vaccine.count()
    console.log(`数据库中现有疫苗数量: ${count}`)
    
  } catch (error) {
    console.error('添加疫苗测试数据失败:', error)
  } finally {
    await sequelize.close()
  }
}

// 如果直接运行此脚本
if (require.main === module) {
  seedVaccines()
}

module.exports = seedVaccines
