"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReceivableAvailabilityModel = exports.AvailabilitySchema = exports.summarySchemeDesc = exports.ELimitSettings = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
const _models_1 = require("./_models");
const mongooseLeanId = require('../plugins/id.plugin');
var ELimitSettings;
(function (ELimitSettings) {
    ELimitSettings["EXCLUDED_CUSTOMERS"] = "excludedCustomers";
    ELimitSettings["PERMITTED_CONCENTRATION"] = "permittedConcentration";
    ELimitSettings["PERMITTED_EXTENDED_AR_DAYS"] = "permittedExtendedARDays";
    ELimitSettings["INSURED_CUSTOMERS"] = "insuredCustomers";
})(ELimitSettings || (exports.ELimitSettings = ELimitSettings = {}));
exports.summarySchemeDesc = {
    invoiceAmount: {
        type: Number,
        required: false,
    },
    creditNotes: {
        type: Number,
        required: false,
    },
    excludedCustomerDeduction: {
        type: Number,
        required: false,
    },
    grossAR: {
        type: Number,
        required: false,
    },
    permittedOver: {
        type: Number,
        required: false,
    },
    preliminaryEligibleBalance: {
        type: Number,
        required: false,
    },
    creditNotesNegative: {
        type: Number,
        required: false,
    },
    deduction: {
        type: Number,
        required: false,
    },
    partiallyPaidDeduction: {
        type: Number,
        required: false,
    },
    contraDeduction: {
        type: Number,
        required: false,
    },
    crossAgeDeduction: {
        type: Number,
        required: false,
    },
    waivedDeduction: {
        type: Number,
        required: false,
    },
    balanceAfterCrossAge: {
        type: Number,
        required: false,
    },
    finalResult: {
        type: Number,
        required: false,
    },
    insuredComponent: {
        type: Number,
        required: false,
    },
    uninsuredComponent: {
        type: Number,
        required: false,
    },
    insuredAvailability: {
        type: Number,
        required: false,
    },
    uninsuredAvailability: {
        type: Number,
        required: false,
    },
    ARReserves: {
        type: Number,
        required: false,
    },
    ARAvailability: {
        type: Number,
        required: false,
    },
};
exports.AvailabilitySchema = new mongoose_1.default.Schema({
    borrowerId: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.borrowers,
        required: true,
    },
    bbcDateId: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.BBCDates,
        required: true,
    },
    userCalculatedId: {
        type: String,
        required: false,
    },
    calculatedAt: {
        type: Date,
        required: false,
    },
    actual: {
        type: Boolean,
        required: false,
        default: false,
    },
    useManualInputs: {
        type: Boolean,
        default: false,
    },
    settings: {
        standardARDays: {
            type: Number,
            required: false,
        },
        customerConcentrationLimit: {
            type: Number,
            required: false,
        },
        crossAgeLimit: {
            type: Number,
            required: false,
        },
        contraProvision: {
            type: Number,
            required: false,
        },
        paidDays: {
            type: Number,
            required: false,
        },
        insuredARAdvanceRate: {
            type: Number,
            required: false,
        },
        uninsuredARAdvanceRate: {
            type: Number,
            required: false,
        },
        excludeFromTotal: {
            type: Boolean,
            required: false,
            default: true,
        },
        waiveInsuredCustomers: {
            type: Boolean,
            required: false,
            default: true,
        },
        excludedCustomers: [
            {
                customer: {
                    type: String,
                    required: false,
                },
                limit: {
                    type: Number,
                    required: false,
                }
            },
        ],
        insuredCustomers: [
            {
                customer: {
                    type: String,
                    required: false,
                },
                limit: {
                    type: Number,
                    required: false,
                }
            },
        ],
        permittedConcentration: [
            {
                customer: {
                    type: String,
                    required: false,
                },
                limit: {
                    type: Number,
                    required: false,
                }
            },
        ],
        permittedExtendedARDays: [
            {
                customer: {
                    type: String,
                    required: false,
                },
                limit: {
                    type: Number,
                    required: false,
                }
            },
        ],
    },
    summary: exports.summarySchemeDesc,
    __v: { type: Number, select: false },
}, { timestamps: true });
exports.AvailabilitySchema.plugin(mongooseLeanId);
exports.ReceivableAvailabilityModel = mongoose_1.default.model(_models_1.MODEL_NAMES.ARAvailabilities, exports.AvailabilitySchema);
