"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBorrowerGroups = exports.groupsMap = void 0;
const CustomerGroup_model_1 = require("../models/CustomerGroup.model");
exports.groupsMap = {
    customers: { Model: CustomerGroup_model_1.CustomerGroupModel },
    categories: { Model: CustomerGroup_model_1.CustomerGroupModel },
    vendors: { Model: CustomerGroup_model_1.CustomerGroupModel },
};
const getBorrowerGroups = async (borrowerId, relationshipGroups) => {
    if (typeof relationshipGroups == 'string') {
        relationshipGroups = [relationshipGroups];
    }
    const allCustomerGroups = await Promise.all(relationshipGroups.map(async (groupName) => {
        const groups = await exports.groupsMap[groupName].Model.find({ borrowerId }).sort({ 'createdAt': 1 });
        return { [groupName]: groups };
    }));
    return allCustomerGroups.reduce((acc, group) => {
        return { ...acc, ...group };
    }, {});
};
exports.getBorrowerGroups = getBorrowerGroups;
