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

module.exports = (sequelize) => {
    const GimmickAllocationOutlet = sequelize.define('gimmickallocationoutlet', {
        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 },
        
        // fk
        outlet_id: { type: DataTypes.INTEGER, allowNull: true },
        gimmickallocation_id: { type: DataTypes.INTEGER, allowNull: false, references: { model: "gimmickallocations", key: "id" } },
    }, {
        tableName: 'gimmickallocationoutlets',
        freezeTableName: true
    });

    /**
     * Associates the GimmickAllocation model with other models.
     * @param {object} models - The models to associate with.
     * @description
     */
    GimmickAllocationOutlet.associate = (models) => {
        GimmickAllocationOutlet.belongsTo(models.GimmickAllocation, { foreignKey: 'gimmickallocation_id', as: 'gimmickallocation'});
        GimmickAllocationOutlet.belongsTo(models.Outlet, { foreignKey: 'outlet_id', as: 'outlet' });
    };
    return GimmickAllocationOutlet;
};
