import { __decorate, __metadata } from "tslib";
import DataLoader from 'dataloader';
import { Injectable, Scope } from 'graphql-modules';
import { sql } from '@pgtyped/runtime';
import { DBProvider } from '../../app-providers/db.provider.js';
const getAllTaxVariables = sql `
  SELECT *
  FROM accounter_schema.business_trips_tax_variables
  ORDER BY date DESC;`;
let BusinessTripTaxVariablesProvider = class BusinessTripTaxVariablesProvider {
    dbProvider;
    constructor(dbProvider) {
        this.dbProvider = dbProvider;
    }
    async batchTaxVariablesByDates(dates) {
        const taxVariables = await getAllTaxVariables.run(undefined, this.dbProvider);
        return dates.map(date => taxVariables.find(record => date.getTime() >= record.date.getTime()));
    }
    getTaxVariablesByDateLoader = new DataLoader((dates) => this.batchTaxVariablesByDates(dates));
    clearCache() {
        this.getTaxVariablesByDateLoader.clearAll();
    }
};
BusinessTripTaxVariablesProvider = __decorate([
    Injectable({
        scope: Scope.Singleton,
        global: true,
    }),
    __metadata("design:paramtypes", [DBProvider])
], BusinessTripTaxVariablesProvider);
export { BusinessTripTaxVariablesProvider };
//# sourceMappingURL=business-trips-tax-variables.provider.js.map