import { Model, DataTypes, Sequelize } from 'sequelize'; export interface TerminationRequestAttributes { id: string; dealerId: string; category: string; reason: string; proposedLwd: Date; status: string; currentStage: string; initiatedBy: string; comments: string | null; timeline: any[]; documents: any[]; } export interface TerminationRequestInstance extends Model, TerminationRequestAttributes { } export default (sequelize: Sequelize) => { const TerminationRequest = sequelize.define('TerminationRequest', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true }, dealerId: { type: DataTypes.UUID, allowNull: false, references: { model: 'dealers', key: 'id' } }, category: { type: DataTypes.STRING, allowNull: false }, reason: { type: DataTypes.TEXT, allowNull: false }, proposedLwd: { type: DataTypes.DATEONLY, allowNull: false }, status: { type: DataTypes.STRING, defaultValue: 'Initiated' }, currentStage: { type: DataTypes.STRING, defaultValue: 'INITIATED' }, initiatedBy: { type: DataTypes.UUID, allowNull: false, references: { model: 'users', key: 'id' } }, comments: { type: DataTypes.TEXT, allowNull: true }, timeline: { type: DataTypes.JSON, defaultValue: [] }, documents: { type: DataTypes.JSON, defaultValue: [] } }, { tableName: 'termination_requests', timestamps: true }); (TerminationRequest as any).associate = (models: any) => { TerminationRequest.belongsTo(models.Dealer, { foreignKey: 'dealerId', as: 'dealer' }); TerminationRequest.belongsTo(models.User, { foreignKey: 'initiatedBy', as: 'initiator' }); TerminationRequest.hasOne(models.FnF, { foreignKey: 'terminationRequestId', as: 'fnfSettlement' }); }; return TerminationRequest; };