"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryResult = exports.QueryResultSchema = exports.QUERY_GROUPS = exports.EFilterParams = exports.EChartsSales = exports.EChartsCash = exports.EChartsMisc = exports.EChartsReceivable = exports.EChartsInventory = exports.EQueriesGroups = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
const _models_1 = require("./_models");
const unit_cost_difference_1 = require("../queries/inventory/unit-cost-difference");
const turn_1 = require("../queries/inventory/turn");
const invoice_difference_1 = require("../queries/inventory/invoice-difference");
const inconsistent_data_1 = require("../queries/inventory/inconsistent-data");
const movement_1 = require("../queries/inventory/movement");
const extension_1 = require("../queries/inventory/extension");
const dublicates_1 = require("../queries/receivable/dublicates");
const average_invoice_size_1 = require("../queries/receivable/average-invoice-size");
const invoice_difference_2 = require("../queries/receivable/invoice-difference");
const partially_paid_restated_1 = require("../queries/receivable/partially-paid-restated");
const grouped_receivables_1 = require("../queries/receivable/grouped-receivables");
const ar_turn_1 = require("../queries/receivable/ar-turn");
var EQueriesGroups;
(function (EQueriesGroups) {
    EQueriesGroups["INVENTORY"] = "INVENTORY";
    EQueriesGroups["RECEIVABLE"] = "RECEIVABLE";
    EQueriesGroups["OTHER"] = "OTHER";
    EQueriesGroups["CASH"] = "CASH";
    EQueriesGroups["SALES"] = "SALES";
})(EQueriesGroups || (exports.EQueriesGroups = EQueriesGroups = {}));
var EChartsInventory;
(function (EChartsInventory) {
    EChartsInventory["BENFORD"] = "BENFORD";
    EChartsInventory["EXPOSURES"] = "EXPOSURES";
    EChartsInventory["EXPOSURES_CATEGORIES"] = "EXPOSURES_CATEGORIES";
    EChartsInventory["AGING_PLOT"] = "AGING_PLOT";
    EChartsInventory["AVERAGE_SKU_VALUES"] = "AVERAGE_SKU_VALUES";
    EChartsInventory["UNIT_COST_DIFFERENCE"] = "UNIT_COST_DIFFERENCE";
    EChartsInventory["INCONSISTENT_DATA"] = "INCONSISTENT_DATA";
    EChartsInventory["INVENTORY_TURN"] = "INVENTORY_TURN";
    EChartsInventory["INVOICE_DIFFERENCE"] = "INVOICE_DIFFERENCE";
    EChartsInventory["MOVEMENT"] = "MOVEMENT";
    EChartsInventory["EXTENSION"] = "EXTENSION";
})(EChartsInventory || (exports.EChartsInventory = EChartsInventory = {}));
var EChartsReceivable;
(function (EChartsReceivable) {
    EChartsReceivable["BENFORD"] = "BENFORD";
    EChartsReceivable["EXPOSURES"] = "EXPOSURES";
    EChartsReceivable["EXPOSURES_CUSTOMERS"] = "EXPOSURES_CUSTOMERS";
    EChartsReceivable["DUPLICATES"] = "DUPLICATES";
    EChartsReceivable["AVERAGE_INVOICE"] = "AVERAGE_INVOICE";
    EChartsReceivable["INVOICE_VALUE_PLOT"] = "INVOICE_VALUE_PLOT";
    EChartsReceivable["AGING_PLOT"] = "AGING_PLOT";
    EChartsReceivable["INVOICE_DIFFERENCE"] = "INVOICE_DIFFERENCE";
    EChartsReceivable["PARTIALLY_PAID_RESTATED"] = "PARTIALLY_PAID_RESTATED";
    EChartsReceivable["AR_TURN"] = "AR_TURN";
    EChartsReceivable["GROUP_CUSTOMERS"] = "GROUP_CUSTOMERS";
})(EChartsReceivable || (exports.EChartsReceivable = EChartsReceivable = {}));
var EChartsMisc;
(function (EChartsMisc) {
    EChartsMisc["CONTRAS"] = "CONTRAS";
})(EChartsMisc || (exports.EChartsMisc = EChartsMisc = {}));
var EChartsCash;
(function (EChartsCash) {
    EChartsCash["TRANSACTIONS"] = "TRANSACTIONS";
    EChartsCash["DELUTION"] = "DELUTION";
})(EChartsCash || (exports.EChartsCash = EChartsCash = {}));
var EChartsSales;
(function (EChartsSales) {
    EChartsSales["FOR_PERIOD"] = "FOR_PERIOD";
})(EChartsSales || (exports.EChartsSales = EChartsSales = {}));
var EFilterParams;
(function (EFilterParams) {
    EFilterParams["NONE"] = "NONE";
    EFilterParams["BBC"] = "BBC";
    EFilterParams["PERIOD"] = "PERIOD";
    EFilterParams["CUSTOM"] = "CUSTOM";
})(EFilterParams || (exports.EFilterParams = EFilterParams = {}));
exports.QUERY_GROUPS = {
    [EQueriesGroups.INVENTORY]: {
        [EChartsInventory.BENFORD]: { scheduled: false, queryAPI: 'benford', queryFunction: null },
        [EChartsInventory.INVOICE_DIFFERENCE]: {
            scheduled: true,
            queryAPI: 'invoice-difference',
            queryFunction: invoice_difference_1.getInventoryDifferenceFull,
            filterParams: EFilterParams.BBC,
            sheetTitle: 'INV.New|Dropped SKUs',
        },
        [EChartsInventory.EXPOSURES]: { scheduled: false, queryAPI: 'exposures', queryFunction: null },
        [EChartsInventory.EXPOSURES_CATEGORIES]: {
            scheduled: false,
            queryAPI: 'exposures-categories',
            queryFunction: null,
        },
        [EChartsInventory.AVERAGE_SKU_VALUES]: { scheduled: false, queryAPI: 'average-sku-values', queryFunction: null },
        [EChartsInventory.AGING_PLOT]: { scheduled: false, queryAPI: 'aging-plot', queryFunction: null },
        [EChartsInventory.UNIT_COST_DIFFERENCE]: {
            scheduled: true,
            queryAPI: 'unit-cost-difference',
            queryFunction: unit_cost_difference_1.getUnitCostDifferenceFull,
            filterParams: EFilterParams.NONE,
            sheetTitle: 'INV.Change in unit cost',
        },
        [EChartsInventory.INCONSISTENT_DATA]: {
            scheduled: true,
            queryAPI: 'inconsistent-data',
            queryFunction: inconsistent_data_1.getInconsistentDataFull,
            filterParams: EFilterParams.BBC,
            sheetTitle: 'INV.Inconsistent data',
        },
        [EChartsInventory.INVENTORY_TURN]: {
            scheduled: true,
            queryAPI: 'turn',
            queryFunction: turn_1.getInventoryTurnFull,
            filterParams: EFilterParams.PERIOD,
            sheetTitle: 'INV.Inventory turn',
        },
        [EChartsInventory.MOVEMENT]: {
            scheduled: true,
            queryAPI: 'movement',
            queryFunction: movement_1.getInvoiceMovementFull,
            filterParams: EFilterParams.BBC,
            sheetTitle: 'INV.Invoice Movement',
        },
        [EChartsInventory.EXTENSION]: {
            scheduled: true,
            queryAPI: 'extension',
            queryFunction: extension_1.getExtensionFull,
            filterParams: EFilterParams.PERIOD,
            sheetTitle: 'INV.Extension',
        },
    },
    [EQueriesGroups.RECEIVABLE]: {
        [EChartsReceivable.BENFORD]: { scheduled: false, queryAPI: 'benford', queryFunction: null },
        [EChartsReceivable.EXPOSURES]: { scheduled: false, queryAPI: 'exposures', queryFunction: null },
        [EChartsReceivable.EXPOSURES_CUSTOMERS]: { scheduled: false, queryAPI: 'exposures-customers', queryFunction: null },
        [EChartsReceivable.DUPLICATES]: {
            scheduled: true,
            queryAPI: 'duplicates',
            queryFunction: dublicates_1.getReceivableDuplicatesFull,
            filterParams: EFilterParams.BBC,
            sheetTitle: 'REC.Duplicates',
        },
        [EChartsReceivable.AVERAGE_INVOICE]: {
            scheduled: true,
            queryAPI: 'average-invoice',
            queryFunction: average_invoice_size_1.getAverageInvoiceFull,
            filterParams: EFilterParams.NONE,
            sheetTitle: 'REC.Average invoice',
        },
        [EChartsReceivable.INVOICE_VALUE_PLOT]: { scheduled: false, queryAPI: 'average-sku-values', queryFunction: null },
        [EChartsReceivable.AGING_PLOT]: { scheduled: false, queryAPI: 'aging-plot', queryFunction: null },
        [EChartsReceivable.INVOICE_DIFFERENCE]: {
            scheduled: true,
            queryAPI: 'invoice-difference',
            queryFunction: invoice_difference_2.getInvoiceDifferenceFull,
            filterParams: EFilterParams.BBC,
            sheetTitle: 'REC.AR movement report',
        },
        [EChartsReceivable.PARTIALLY_PAID_RESTATED]: {
            scheduled: true,
            queryAPI: 'partially-paid-restated',
            queryFunction: partially_paid_restated_1.getPartialPaidFull,
            filterParams: EFilterParams.PERIOD,
            sheetTitle: 'REC.Partially paid & restated',
        },
        [EChartsReceivable.AR_TURN]: {
            scheduled: true,
            queryAPI: 'ar-turn',
            queryFunction: ar_turn_1.getARTurnFull,
            filterParams: EFilterParams.CUSTOM,
            sheetTitle: 'REC.AR Turn',
        },
        [EChartsReceivable.GROUP_CUSTOMERS]: {
            scheduled: true,
            queryAPI: 'grouped-receivables',
            queryFunction: grouped_receivables_1.getGroupedReceivablesFull,
            filterParams: EFilterParams.BBC,
            sheetTitle: 'REC.Detailed grouped receivables',
        },
    },
    [EQueriesGroups.OTHER]: {
        [EChartsMisc.CONTRAS]: { scheduled: false, queryAPI: 'contras', queryFunction: null },
    },
    [EQueriesGroups.CASH]: {
        [EChartsCash.TRANSACTIONS]: { scheduled: false, queryAPI: 'transactions', queryFunction: null },
        [EChartsCash.DELUTION]: { scheduled: false, queryAPI: 'delution', queryFunction: null },
    },
    [EQueriesGroups.SALES]: {
        [EChartsSales.FOR_PERIOD]: { scheduled: false, queryAPI: 'sales-for-period', queryFunction: null },
    }
};
exports.QueryResultSchema = new mongoose_1.default.Schema({
    query: {
        type: String,
        required: true,
    },
    filter: mongoose_1.default.Schema.Types.Mixed,
    userId: {
        type: String,
        required: false,
    },
    result: mongoose_1.default.Schema.Types.Mixed,
}, { timestamps: true });
exports.QueryResult = mongoose_1.default.model(_models_1.MODEL_NAMES.queryResult, exports.QueryResultSchema);
