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

const HarmlessPlace = sequelize.define('HarmlessPlace', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true,
    allowNull: false
  },
  name: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '场所名称'
  },
  address: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: '地址'
  },
  contactPerson: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '联系人'
  },
  contactPhone: {
    type: DataTypes.STRING(20),
    allowNull: false,
    comment: '联系电话'
  },
  licenseNumber: {
    type: DataTypes.STRING(50),
    allowNull: false,
    unique: true,
    comment: '许可证号'
  },
  status: {
    type: DataTypes.ENUM('正常', '维护中', '停用'),
    allowNull: false,
    defaultValue: '正常',
    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_harmless_places',
  timestamps: false,
  paranoid: false,
  underscored: true,
  indexes: [
    {
      name: 'idx_name',
      fields: ['name']
    },
    {
      name: 'idx_status',
      fields: ['status']
    },
    {
      name: 'idx_license_number',
      fields: ['licenseNumber'],
      unique: true
    }
  ],
  comment: '无害化场所管理表'
});

module.exports = HarmlessPlace;