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

module.exports = (sequelize) => {
    const OutletClient = sequelize.define('outletclient', {
        outlet_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'outlets',
                key: 'id',
                primaryKey: true
            }
        },
        client_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'clients',
                key: 'id',
                primaryKey: true
            }
        }
    }, {
        tableName: 'outletclients',
    }, {
        freezeTableName: true
    });

    /**
     * Associates the OutletClient model with other models.
     * @param {object} models - The models to associate with.
     */
    OutletClient.associate = (models) => {
        /**
         * Associate OutletClient with Outlet
         * @property {object} outlet - The Outlet model associated with OutletClient.
         */
        OutletClient.belongsTo(models.Outlet, {
            foreignKey: 'outlet_id',
            as: 'outlet'
        });

        /**
         * Associate OutletClient with Client
         * @property {object} client - The Client model associated with OutletClient.
         */
        OutletClient.belongsTo(models.Client, {
            foreignKey: 'client_id',
            as: 'client'
        });
    };

    return OutletClient;
};