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

export interface InterviewEvaluationAttributes {
    id: string;
    interviewId: string;
    evaluatorId: string;
    ktMatrixScore: number | null;
    qualitativeFeedback: string | null;
    recommendation: string | null;
    remarks: string | null;
    decision: string | null;
}

export interface InterviewEvaluationInstance extends Model<InterviewEvaluationAttributes>, InterviewEvaluationAttributes { }

export default (sequelize: Sequelize) => {
    const InterviewEvaluation = sequelize.define<InterviewEvaluationInstance>('InterviewEvaluation', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        interviewId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'interviews',
                key: 'id'
            }
        },
        evaluatorId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'users',
                key: 'id'
            }
        },
        ktMatrixScore: {
            type: DataTypes.DECIMAL(10, 2),
            allowNull: true
        },
        qualitativeFeedback: {
            type: DataTypes.TEXT,
            allowNull: true
        },
        recommendation: {
            type: DataTypes.STRING,
            allowNull: true
        },
        remarks: {
            type: DataTypes.TEXT,
            allowNull: true
        },
        decision: {
            type: DataTypes.STRING,
            allowNull: true
        }
    }, {
        tableName: 'interview_evaluations',
        timestamps: true
    });

    (InterviewEvaluation as any).associate = (models: any) => {
        InterviewEvaluation.belongsTo(models.Interview, { foreignKey: 'interviewId', as: 'interview' });
        InterviewEvaluation.belongsTo(models.User, { foreignKey: 'evaluatorId', as: 'evaluator' });
        InterviewEvaluation.hasMany(models.KTMatrixScore, { foreignKey: 'evaluationId', as: 'criterionScores' });
        InterviewEvaluation.hasMany(models.InterviewFeedback, { foreignKey: 'evaluationId', as: 'feedbackDetails' });
    };

    return InterviewEvaluation;
};
