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

// 屠宰场数据模型
const Slaughterhouse = sequelize.define('Slaughterhouse', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        comment: '屠宰场ID'
    },
    name: {
        type: DataTypes.STRING(100),
        allowNull: false,
        unique: true,
        comment: '屠宰场名称'
    },
    address: {
        type: DataTypes.STRING(255),
        allowNull: false,
        comment: '地址'
    },
    contactPerson: {
        field: 'contactPerson',
        type: DataTypes.STRING,
        allowNull: true,
        comment: '联系人'
    },
    contactPhone: {
        field: 'contactPhone',
        type: DataTypes.STRING,
        allowNull: true,
        comment: '联系电话'
    },
    licenseNumber: {
        field: 'licenseNumber',
        type: DataTypes.STRING,
        allowNull: true,
        comment: '许可证号'
    },
    status: {
        type: DataTypes.ENUM('active', 'inactive'),
        allowNull: false,
        defaultValue: 'active',
        comment: '状态（active: 正常, inactive: 停用）'
    },
    createTime: {
        field: 'createTime',
        type: DataTypes.DATE,
        allowNull: false,
        defaultValue: DataTypes.NOW,
        comment: '创建时间'
    },
    created_by: {
        type: DataTypes.INTEGER,
        allowNull: true,
        comment: '创建人ID'
    },
    updated_by: {
        type: DataTypes.INTEGER,
        allowNull: true,
        comment: '更新人ID'
    }
}, {
    tableName: 'government_slaughterhouses',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
    paranoid: false,
    indexes: [
        { name: 'idx_name', fields: ['name'] },
        { name: 'idx_licenseNumber', fields: ['licenseNumber'] },
        { name: 'idx_status', fields: ['status'] }
    ]
});

module.exports = Slaughterhouse;