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

const EpidemicRecord = sequelize.define('EpidemicRecord', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true,
    allowNull: false
  },
  farmName: {
    type: DataTypes.STRING(100),
    allowNull: false,
    field: 'farm_name',
    comment: '养殖场名称'
  },
  type: {
    type: DataTypes.ENUM('vaccination', 'disinfection', 'health_check', 'other'),
    allowNull: false,
    comment: '防疫类型'
  },
  epidemicStaff: {
    type: DataTypes.STRING(50),
    allowNull: false,
    field: 'epidemic_staff',
    comment: '防疫员'
  },
  phone: {
    type: DataTypes.STRING(20),
    allowNull: false,
    comment: '联系电话'
  },
  epidemicDate: {
    type: DataTypes.DATEONLY,
    allowNull: false,
    field: 'epidemic_date',
    comment: '防疫日期'
  },
  count: {
    type: DataTypes.INTEGER,
    allowNull: true,
    defaultValue: 0,
    comment: '防疫数量'
  },
  vaccineName: {
    type: DataTypes.STRING(100),
    allowNull: true,
    field: 'vaccine_name',
    comment: '使用疫苗'
  },
  area: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '防疫范围'
  },
  disinfectant: {
    type: DataTypes.STRING(100),
    allowNull: true,
    comment: '防疫药品'
  },
  healthResult: {
    type: DataTypes.ENUM('normal', 'abnormal'),
    allowNull: true,
    field: 'health_result',
    comment: '检查结果'
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '防疫描述'
  },
  notes: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '备注'
  },
  status: {
    type: DataTypes.ENUM('completed', 'pending', 'failed'),
    allowNull: false,
    defaultValue: 'completed',
    comment: '状态'
  },
  createTime: {
    type: DataTypes.DATE,
    allowNull: false,
    field: 'create_time',
    defaultValue: DataTypes.NOW,
    comment: '创建时间'
  },
  updateTime: {
    type: DataTypes.DATE,
    allowNull: false,
    field: 'update_time',
    defaultValue: DataTypes.NOW,
    comment: '更新时间'
  }
}, {
  tableName: 'government_epidemic_records',
  timestamps: false,
  paranoid: false,
  underscored: true,
  indexes: [
    {
      name: 'idx_farm_name',
      fields: ['farm_name']
    },
    {
      name: 'idx_type',
      fields: ['type']
    },
    {
      name: 'idx_status',
      fields: ['status']
    },
    {
      name: 'idx_epidemic_date',
      fields: ['epidemic_date']
    },
    {
      name: 'idx_epidemic_staff',
      fields: ['epidemic_staff']
    }
  ],
  comment: '防疫记录管理表'
})

module.exports = EpidemicRecord
