"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMappedGroups = exports.getAPCustomerGroups = void 0;
const CustomerAPGroup_model_1 = __importDefault(require("../models/CustomerAPGroup.model"));
const MappedGroup_model_1 = __importDefault(require("../models/MappedGroup.model"));
const getAPCustomerGroups = async (borrowerId) => {
    return CustomerAPGroup_model_1.default.aggregate([
        {
            $match: {
                'borrowerId': borrowerId
            }
        },
        {
            $unwind: {
                'path': '$items'
            }
        },
    ]);
};
exports.getAPCustomerGroups = getAPCustomerGroups;
const getMappedGroups = async ({ group1, group2 }) => {
    if (!group1 && !group2) {
        return Promise.resolve(null);
    }
    if (!group2) {
        return MappedGroup_model_1.default.aggregate([
            {
                $match: {
                    'group1': group1
                }
            },
        ]);
    }
    if (!group1) {
        return MappedGroup_model_1.default.aggregate([
            {
                $match: {
                    'group2': group2
                }
            },
        ]);
    }
    return MappedGroup_model_1.default.aggregate([
        {
            $match: {
                $and: [
                    { 'group1': group1 },
                    { 'group2': group2 },
                ]
            }
        },
    ]);
};
exports.getMappedGroups = getMappedGroups;
