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

const EpidemicAgency = sequelize.define('EpidemicAgency', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '机构名称'
  },
  director: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '负责人'
  },
  phone: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '联系电话'
  },
  address: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '地址'
  },
  email: {
    type: DataTypes.STRING,
    allowNull: true,
    comment: '邮箱'
  },
  type: {
    type: DataTypes.ENUM('center', 'branch', 'mobile'),
    allowNull: false,
    defaultValue: 'branch',
    comment: '机构类型: center(中心防疫站), branch(防疫分站), mobile(流动防疫队)'
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive'),
    allowNull: false,
    defaultValue: 'active',
    comment: '状态: active(活跃), inactive(非活跃)'
  },
  establishmentDate: {
    type: DataTypes.DATEONLY,
    allowNull: false,
    comment: '成立日期'
  },
  epidemicScope: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '防疫范围'
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '机构描述'
  },
  created_by: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: '创建人ID'
  },
  updated_by: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: '更新人ID'
  }
}, {
  tableName: 'government_epidemic_agencies',
  indexes: [
    {
      name: 'idx_agency_name',
      fields: ['name']
    },
    {
      name: 'idx_agency_status',
      fields: ['status']
    },
    {
      name: 'idx_agency_type',
      fields: ['type']
    }
  ]
});

module.exports = EpidemicAgency;