import { Model, DataTypes, Sequelize } from 'sequelize';

export interface TerminationHearingRecordAttributes {
    id: string;
    terminationRequestId: string;
    conductedBy: string; // User ID
    attendees: string;
    summary: string;
    momDocumentId: string | null;
    conductedAt: Date;
    recommendation: string; // 'Proceed', 'Reconsider', 'Reject'
}

export interface TerminationHearingRecordInstance extends Model<TerminationHearingRecordAttributes>, TerminationHearingRecordAttributes { }

export default (sequelize: Sequelize) => {
    const TerminationHearingRecord = sequelize.define<TerminationHearingRecordInstance>('TerminationHearingRecord', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        terminationRequestId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'termination_requests',
                key: 'id'
            }
        },
        conductedBy: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'users',
                key: 'id'
            }
        },
        attendees: {
            type: DataTypes.TEXT,
            allowNull: false
        },
        summary: {
            type: DataTypes.TEXT,
            allowNull: false
        },
        momDocumentId: {
            type: DataTypes.UUID,
            allowNull: true
        },
        conductedAt: {
            type: DataTypes.DATE,
            defaultValue: DataTypes.NOW
        },
        recommendation: {
            type: DataTypes.STRING,
            allowNull: false
        }
    }, {
        tableName: 'termination_hearing_records',
        timestamps: true
    });

    (TerminationHearingRecord as any).associate = (models: any) => {
        TerminationHearingRecord.belongsTo(models.TerminationRequest, { foreignKey: 'terminationRequestId', as: 'terminationRequest' });
        TerminationHearingRecord.belongsTo(models.User, { foreignKey: 'conductedBy', as: 'conductor' });
    };

    return TerminationHearingRecord;
};
