"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAverageOverData = exports.getAverageInvoiceData = exports.getAverageInvoiceFull = void 0;
const excel_helper_1 = require("../../helpers/excel.helper");
const receivables_db_1 = require("../../db/receivables.db");
const getAverageInvoiceFull = async (params) => {
    const dateAll = await (0, exports.getAverageInvoiceData)(params);
    const dataTop = await (0, exports.getAverageOverData)(params);
    const headerAll = getAverageInvoiceFullHeader('all');
    const headerTop = getAverageInvoiceFullHeader('top');
    const tableAll = (0, excel_helper_1.addHeaderToData)(headerAll, dateAll);
    const tableTop = (0, excel_helper_1.addHeaderToData)(headerTop, dataTop);
    return { 'all': tableAll, 'top': tableTop };
};
exports.getAverageInvoiceFull = getAverageInvoiceFull;
const getAverageInvoiceData = async (params) => {
    const { borrowerId } = params;
    return (0, receivables_db_1.getAverageInvoiceSize)(borrowerId.toString());
};
exports.getAverageInvoiceData = getAverageInvoiceData;
const getAverageOverData = async (params) => {
    const { borrowerId } = params;
    return (0, receivables_db_1.getAverageOver)(borrowerId.toString());
};
exports.getAverageOverData = getAverageOverData;
const getAverageInvoiceFullHeader = (type) => {
    const headerMap = {
        'all': {
            bbcDate: 'BBC date',
            totalInvoices: 'Number of Invoices',
            totalAmount: 'Total Invoices',
            averageInvoiceSize: 'Average Invoice',
        },
        'top': {
            bbcDate: 'BBC date',
            invoiceNumber: 'Invoice number',
            invoiceDate: 'Invoice date',
            customerTitle: 'Customer name',
            invoiceAmount: 'Invoice amount',
        },
    };
    return headerMap[type];
};
