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

const Vaccine = sequelize.define('Vaccine', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true,
    allowNull: false
  },
  name: {
    type: DataTypes.STRING(200),
    allowNull: false,
    field: 'name',
    comment: '疫苗名称'
  },
  type: {
    type: DataTypes.ENUM('foot_and_mouth_disease', 'bovine_tuberculosis', 'brucellosis', 'rabies', 'other'),
    allowNull: false,
    comment: '疫苗类型'
  },
  manufacturer: {
    type: DataTypes.STRING(200),
    allowNull: false,
    field: 'manufacturer',
    comment: '生产厂商'
  },
  approvalNumber: {
    type: DataTypes.STRING(100),
    allowNull: false,
    field: 'approval_number',
    comment: '批准文号'
  },
  specification: {
    type: DataTypes.STRING(100),
    allowNull: false,
    field: 'specification',
    comment: '规格'
  },
  price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    field: 'price',
    comment: '单价'
  },
  validDays: {
    type: DataTypes.INTEGER,
    allowNull: false,
    field: 'valid_days',
    comment: '有效期（天）'
  },
  storageCondition: {
    type: DataTypes.STRING(200),
    allowNull: false,
    field: 'storage_condition',
    comment: '储存条件'
  },
  stockCount: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    field: 'stock_count',
    comment: '库存数量'
  },
  status: {
    type: DataTypes.ENUM('valid', 'expired', 'low_stock'),
    allowNull: false,
    defaultValue: 'valid',
    comment: '状态'
  },
  notes: {
    type: DataTypes.TEXT,
    allowNull: true,
    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_vaccines',
  timestamps: false,
  paranoid: false,
  underscored: true,
  indexes: [
    {
      name: 'idx_name',
      fields: ['name']
    },
    {
      name: 'idx_type',
      fields: ['type']
    },
    {
      name: 'idx_status',
      fields: ['status']
    },
    {
      name: 'idx_manufacturer',
      fields: ['manufacturer']
    },
    {
      name: 'idx_approval_number',
      fields: ['approval_number']
    }
  ],
  comment: '疫苗管理表'
})

module.exports = Vaccine
