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

export interface KTMatrixScoreAttributes {
    id: string;
    evaluationId: string;
    criterionName: string;
    score: number;
    maxScore: number;
    weightage: number;
    weightedScore: number;
}

export interface KTMatrixScoreInstance extends Model<KTMatrixScoreAttributes>, KTMatrixScoreAttributes { }

export default (sequelize: Sequelize) => {
    const KTMatrixScore = sequelize.define<KTMatrixScoreInstance>('KTMatrixScore', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        evaluationId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'interview_evaluations',
                key: 'id'
            }
        },
        criterionName: {
            type: DataTypes.STRING,
            allowNull: false
        },
        score: {
            type: DataTypes.DECIMAL(10, 2),
            allowNull: false
        },
        maxScore: {
            type: DataTypes.DECIMAL(10, 2),
            allowNull: false
        },
        weightage: {
            type: DataTypes.DECIMAL(10, 2),
            allowNull: false
        },
        weightedScore: {
            type: DataTypes.DECIMAL(10, 2),
            allowNull: false
        }
    }, {
        tableName: 'kt_matrix_scores',
        timestamps: true,
        updatedAt: false
    });

    (KTMatrixScore as any).associate = (models: any) => {
        KTMatrixScore.belongsTo(models.InterviewEvaluation, { foreignKey: 'evaluationId', as: 'evaluation' });
    };

    return KTMatrixScore;
};
