const { RESIGNATION_TYPES, RESIGNATION_STAGES } = require('../config/constants'); module.exports = (sequelize, DataTypes) => { const Resignation = sequelize.define('Resignation', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true }, resignationId: { type: DataTypes.STRING, unique: true, allowNull: false }, outletId: { type: DataTypes.UUID, allowNull: false, references: { model: 'outlets', key: 'id' } }, dealerId: { type: DataTypes.UUID, allowNull: false, references: { model: 'users', key: 'id' } }, resignationType: { type: DataTypes.ENUM(Object.values(RESIGNATION_TYPES)), allowNull: false }, lastOperationalDateSales: { type: DataTypes.DATEONLY, allowNull: false }, lastOperationalDateServices: { type: DataTypes.DATEONLY, allowNull: false }, reason: { type: DataTypes.TEXT, allowNull: false }, additionalInfo: { type: DataTypes.TEXT, allowNull: true }, currentStage: { type: DataTypes.ENUM(Object.values(RESIGNATION_STAGES)), defaultValue: RESIGNATION_STAGES.ASM }, status: { type: DataTypes.STRING, defaultValue: 'Pending' }, progressPercentage: { type: DataTypes.INTEGER, defaultValue: 0 }, submittedOn: { type: DataTypes.DATE, defaultValue: DataTypes.NOW }, documents: { type: DataTypes.JSON, defaultValue: [] }, timeline: { type: DataTypes.JSON, defaultValue: [] }, rejectionReason: { type: DataTypes.TEXT, allowNull: true } }, { tableName: 'resignations', timestamps: true, indexes: [ { fields: ['resignationId'] }, { fields: ['outletId'] }, { fields: ['dealerId'] }, { fields: ['currentStage'] }, { fields: ['status'] } ] }); Resignation.associate = (models) => { Resignation.belongsTo(models.Outlet, { foreignKey: 'outletId', as: 'outlet' }); Resignation.belongsTo(models.User, { foreignKey: 'dealerId', as: 'dealer' }); Resignation.hasMany(models.Worknote, { foreignKey: 'requestId', as: 'worknotes', scope: { requestType: 'resignation' } }); }; return Resignation; };