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

module.exports = (sequelize) => {
    const MasterList = sequelize.define('masterlist', {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        territory_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'territories',
                key: 'id'
            }
        },
        outlet_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'outlets',
                key: 'id'
            }
        },
        client_id: {
            type: DataTypes.INTEGER,
            references: {
                model: 'clients',
                key: 'id'
            }
        }
    }, {
        tableName: 'masterlists',
        freezeTableName: true
    });

    MasterList.associate = (models) => {
        MasterList.belongsTo(models.Territory, { foreignKey: 'territory_id', as: 'territory' });
        MasterList.belongsTo(models.Outlet, { foreignKey: 'outlet_id', as: 'outlet' });
        MasterList.belongsTo(models.Client, { foreignKey: 'client_id', as: 'client' });
    };

    return MasterList;
};
