const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
    const GimmickReqType = sequelize.define('gimmickreqtype', {
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true
        },
        creation: { type: DataTypes.DATE, allowNull: false },
        modified: { type: DataTypes.DATE, allowNull: false },
        modified_by: { type: DataTypes.INTEGER, allowNull: false },
        owner: { type: DataTypes.INTEGER, allowNull: false },
        enabled: { type: DataTypes.BOOLEAN, allowNull: false },

        // main
        display_name: {type: DataTypes.STRING, allowNull: false, unique: true},
        description: {type: DataTypes.TEXT, allowNull: true},

        // fk
         company_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            references: {
            model: "companies",
            key: "id",
            },
        }
    }, {
        tableName: 'gimmickreqtypes',
        freezeTableName: true
    });

    /**
     * Associates the Drug model with other models.
     * @param {object} models - The models to associate with.
     * @description
     */
    GimmickReqType.associate = (models) => {
        GimmickReqType.belongsTo(models.Company, { foreignKey: "company_id", as: "company" });
        GimmickReqType.hasMany(models.GimmickReqSubType, { foreignKey: "gimmickreqtype_id", as: "subtypes" });
        GimmickReqType.hasMany(models.GimmickRequest, { foreignKey: "gimmickreqtype_id", as: "gimmickrequest" });
    };

    return GimmickReqType;
};
