"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LoanCharge = exports.LoanChargeSchema = exports.defaultChargeList = exports.chargeViewValidationSchema = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
const joi_1 = __importDefault(require("joi"));
const loan_types_enum_1 = require("../enums/loan-types.enum");
const loan_charge_type_enum_1 = require("../enums/loan-charge-type.enum");
const _models_1 = require("./_models");
exports.chargeViewValidationSchema = joi_1.default.object({
    valid: joi_1.default.boolean(),
    _id: joi_1.default.string().allow(null),
    active: joi_1.default.boolean(),
    name: joi_1.default.string().required(),
    code: joi_1.default.string().required(),
    PLCode: joi_1.default.string().required(),
    productId: joi_1.default.string().required(),
    percent: joi_1.default.number().required().min(0),
    minimumAmount: joi_1.default.number().required().min(0),
    frequency: joi_1.default.string().required().valid(...Object.keys(loan_types_enum_1.EChargeFrequencies)),
    applyFrom: joi_1.default.date().required(),
    calculationBasis: joi_1.default.string().required().valid(...Object.keys(loan_types_enum_1.EChargeCalculationBasis)),
    chargeType: joi_1.default.string().required().valid(...Object.keys(loan_charge_type_enum_1.ELoanChargeType)),
    includeInYield: joi_1.default.boolean().required(),
    paymentOrder: joi_1.default.number(),
});
exports.defaultChargeList = [
    {
        _id: null,
        active: true,
        name: 'Interest',
        code: loan_charge_type_enum_1.ELoanChargeType.INTEREST_FEE,
        PLCode: '',
        chargeType: loan_charge_type_enum_1.ELoanChargeType.INTEREST_FEE,
        productId: null,
        percent: 0,
        minimumAmount: 0,
        frequency: loan_types_enum_1.EChargeFrequencies.DAILY,
        applyFrom: null,
        calculationBasis: loan_types_enum_1.EChargeCalculationBasis.DAILY_BALANCE,
        includeInYield: false,
    },
    {
        _id: null,
        active: true,
        name: 'Admin Fees',
        code: loan_charge_type_enum_1.ELoanChargeType.ADMIN_FEE,
        PLCode: '',
        chargeType: loan_charge_type_enum_1.ELoanChargeType.ADMIN_FEE,
        productId: null,
        percent: 0,
        minimumAmount: 0,
        frequency: loan_types_enum_1.EChargeFrequencies.MONTHLY,
        applyFrom: null,
        calculationBasis: loan_types_enum_1.EChargeCalculationBasis.AVERAGE_MONTHLY_BALANCE,
        includeInYield: false,
    },
    {
        _id: null,
        active: true,
        name: 'Unused Line Fee',
        code: loan_charge_type_enum_1.ELoanChargeType.UNUSED_LINE_FEE,
        PLCode: '',
        chargeType: loan_charge_type_enum_1.ELoanChargeType.UNUSED_LINE_FEE,
        productId: null,
        percent: 0,
        minimumAmount: 0,
        frequency: loan_types_enum_1.EChargeFrequencies.DAILY,
        applyFrom: null,
        calculationBasis: loan_types_enum_1.EChargeCalculationBasis.UNUSED_AMOUNT,
        includeInYield: false,
    },
    {
        _id: null,
        active: true,
        name: 'Annual Line Fee',
        code: loan_charge_type_enum_1.ELoanChargeType.ANNUAL_LINE_FEE,
        PLCode: '',
        chargeType: loan_charge_type_enum_1.ELoanChargeType.ANNUAL_LINE_FEE,
        productId: null,
        percent: 0,
        minimumAmount: 0,
        frequency: loan_types_enum_1.EChargeFrequencies.ANNUAL,
        applyFrom: null,
        calculationBasis: loan_types_enum_1.EChargeCalculationBasis.COMMITMENT,
        includeInYield: false,
    },
    {
        _id: null,
        active: true,
        name: 'Wire Fee',
        code: loan_charge_type_enum_1.ELoanChargeType.WIRE_FEE,
        PLCode: '',
        chargeType: loan_charge_type_enum_1.ELoanChargeType.WIRE_FEE,
        productId: null,
        percent: 0,
        minimumAmount: 0,
        frequency: loan_types_enum_1.EChargeFrequencies.DISBURSEMENT,
        applyFrom: null,
        calculationBasis: loan_types_enum_1.EChargeCalculationBasis.DISBURSEMENT_AMOUNT,
        includeInYield: false,
    },
    {
        _id: null,
        active: true,
        name: 'Forbearance',
        code: loan_charge_type_enum_1.ELoanChargeType.OTHER,
        PLCode: '',
        chargeType: loan_charge_type_enum_1.ELoanChargeType.OTHER,
        productId: null,
        percent: 0,
        minimumAmount: 0,
        frequency: loan_types_enum_1.EChargeFrequencies.ONE_TIME,
        applyFrom: null,
        calculationBasis: loan_types_enum_1.EChargeCalculationBasis.FIXED,
        includeInYield: false,
    },
    {
        _id: null,
        active: true,
        name: 'Overline/Over-advance',
        code: loan_charge_type_enum_1.ELoanChargeType.OTHER,
        PLCode: '',
        chargeType: loan_charge_type_enum_1.ELoanChargeType.OTHER,
        productId: null,
        percent: 0,
        minimumAmount: 0,
        frequency: loan_types_enum_1.EChargeFrequencies.ONE_TIME,
        applyFrom: null,
        calculationBasis: loan_types_enum_1.EChargeCalculationBasis.FIXED,
        includeInYield: false,
    },
    {
        _id: null,
        active: true,
        name: 'Closing Points',
        code: loan_charge_type_enum_1.ELoanChargeType.OTHER,
        PLCode: '',
        chargeType: loan_charge_type_enum_1.ELoanChargeType.OTHER,
        productId: null,
        percent: 0,
        minimumAmount: 0,
        frequency: loan_types_enum_1.EChargeFrequencies.ONE_TIME,
        applyFrom: null,
        calculationBasis: loan_types_enum_1.EChargeCalculationBasis.FIXED,
        includeInYield: false,
    },
];
exports.LoanChargeSchema = new mongoose_1.default.Schema({
    borrowerId: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.borrowers,
        required: true,
    },
    order: {
        type: Number,
        required: true,
    },
    active: {
        type: Boolean,
        required: true,
    },
    name: {
        type: String,
        required: true,
        trim: true,
    },
    code: {
        type: String,
        required: true,
        trim: true,
    },
    PLCode: {
        type: String,
        required: true,
        trim: true,
    },
    productId: {
        type: mongoose_1.default.Schema.Types.ObjectId,
        ref: _models_1.MODEL_NAMES.loanProducts,
        required: true,
    },
    percent: {
        type: Number,
        required: true,
    },
    minimumAmount: {
        type: Number,
        required: true,
    },
    frequency: {
        type: String,
        required: true,
        trim: true,
    },
    applyFrom: {
        type: Date,
        required: true,
    },
    calculationBasis: {
        type: String,
        required: true,
        trim: true,
    },
    chargeType: {
        type: String,
        required: true,
        trim: true,
    },
    includeInYield: {
        type: Boolean,
        required: true,
    },
    deletedAt: {
        type: Date,
    },
    paymentOrder: {
        type: Number,
    },
    __v: { type: Number, select: false },
}, { timestamps: true });
exports.LoanCharge = mongoose_1.default.model(_models_1.MODEL_NAMES.loanCharges, exports.LoanChargeSchema);
