"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CollateralAdjustment = exports.CollateralAdjustmentSchema = exports.allowedCollateralTypeValues = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
const _models_1 = require("./_models");
const collaterals_enum_1 = require("../enums/collaterals.enum");
const allowedCollateralSubset = {
    [collaterals_enum_1.ECollaterals.RECEIVABLE]: true,
    [collaterals_enum_1.ECollaterals.INVENTORY]: true,
    [collaterals_enum_1.ECollaterals.OTHER]: true,
};
exports.allowedCollateralTypeValues = Object.keys(allowedCollateralSubset).filter((key) => allowedCollateralSubset[key]);
let collateralAdjustmentSummary = {};
exports.allowedCollateralTypeValues.forEach(collateralType => {
    collateralAdjustmentSummary[collateralType] = {
        amount: {
            type: Number,
            required: true,
        },
    };
});
exports.CollateralAdjustmentSchema = new mongoose_1.default.Schema({
    bbcDateId: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.BBCDates,
        required: true,
    },
    summary: collateralAdjustmentSummary,
    items: [
        {
            active: {
                type: Boolean,
                required: true,
            },
            name: {
                type: String,
                trim: true,
                required: true,
            },
            type: {
                type: String,
                enum: exports.allowedCollateralTypeValues,
                required: true,
                trim: true,
            },
            amount: {
                type: Number,
                required: true,
            },
        },
    ],
    notes: {
        type: String,
        required: false,
        trim: true,
    },
}, { timestamps: true });
exports.CollateralAdjustment = mongoose_1.default.model(_models_1.MODEL_NAMES.collateralAdjustments, exports.CollateralAdjustmentSchema);
