const { OUTLET_TYPES, OUTLET_STATUS, REGIONS } = require('../../common/config/constants'); module.exports = (sequelize, DataTypes) => { const Outlet = sequelize.define('Outlet', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true }, code: { type: DataTypes.STRING, unique: true, allowNull: false }, name: { type: DataTypes.STRING, allowNull: false }, type: { type: DataTypes.ENUM(Object.values(OUTLET_TYPES)), allowNull: false }, address: { type: DataTypes.TEXT, allowNull: false }, city: { type: DataTypes.STRING, allowNull: false }, state: { type: DataTypes.STRING, allowNull: false }, pincode: { type: DataTypes.STRING, allowNull: false }, latitude: { type: DataTypes.DECIMAL(10, 8), allowNull: true }, longitude: { type: DataTypes.DECIMAL(11, 8), allowNull: true }, status: { type: DataTypes.ENUM(Object.values(OUTLET_STATUS)), defaultValue: OUTLET_STATUS.ACTIVE }, establishedDate: { type: DataTypes.DATEONLY, allowNull: false }, dealerId: { type: DataTypes.UUID, allowNull: false, references: { model: 'users', key: 'id' } }, region: { type: DataTypes.ENUM(Object.values(REGIONS)), allowNull: false }, zone: { type: DataTypes.STRING, allowNull: false } }, { tableName: 'outlets', timestamps: true, indexes: [ { fields: ['code'] }, { fields: ['dealerId'] }, { fields: ['type'] }, { fields: ['status'] }, { fields: ['region'] }, { fields: ['zone'] } ] }); Outlet.associate = (models) => { Outlet.belongsTo(models.User, { foreignKey: 'dealerId', as: 'dealer' }); Outlet.hasMany(models.Resignation, { foreignKey: 'outletId', as: 'resignations' }); Outlet.hasMany(models.ConstitutionalChange, { foreignKey: 'outletId', as: 'constitutionalChanges' }); Outlet.hasMany(models.RelocationRequest, { foreignKey: 'outletId', as: 'relocationRequests' }); }; return Outlet; };