"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StorecardSubmission = exports.StorecardSubmissionSchema = exports.SUBMISSION_STATUSES = exports.RESULT_SOURCES = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
const _models_1 = require("./_models");
exports.RESULT_SOURCES = [
    'SCORE',
    'RULE',
];
exports.SUBMISSION_STATUSES = [
    'draft',
    'final',
];
exports.StorecardSubmissionSchema = new mongoose_1.default.Schema({
    borrowerId: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.borrowers,
        required: true,
    },
    scorecardId: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.scorecard,
        required: true,
    },
    scorecardVersionId: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.scorecardVersion,
        required: true,
    },
    period: {
        type: String,
        required: true,
    },
    totalScore: {
        type: Number,
    },
    sectionScores: {
        type: Map,
        of: Number,
        required: false,
    },
    status: {
        type: String,
        enum: exports.SUBMISSION_STATUSES,
        required: true,
    },
    lockedAt: {
        type: Date,
        required: false,
    },
    finalResult: {
        type: String,
        required: false,
    },
    resultSource: {
        type: String,
        enum: exports.RESULT_SOURCES,
        required: false,
    },
    resultRuleKey: {
        type: String,
        required: false,
    },
}, {
    timestamps: { createdAt: true, updatedAt: true },
    versionKey: false,
});
exports.StorecardSubmission = mongoose_1.default.model(_models_1.MODEL_NAMES.scorecardSubmission, exports.StorecardSubmissionSchema);
exports.StorecardSubmissionSchema.index({ borrowerId: 1, scorecardId: 1, period: 1 }, { unique: true });
