import { __decorate, __metadata } from "tslib";
import DataLoader from 'dataloader';
import { Injectable, Scope } from 'graphql-modules';
import { sql } from '@pgtyped/runtime';
import { TenantAwareDBClient } from '../../app-providers/tenant-db-client.js';
const getBalanceCancellationByChargesIds = sql `
    SELECT *
    FROM accounter_schema.charge_balance_cancellation
    WHERE charge_id IN $$chargeIds;`;
const deleteBalanceCancellationByBusinessId = sql `
    DELETE FROM accounter_schema.charge_balance_cancellation
    WHERE business_id = $businessId;`;
let BalanceCancellationProvider = class BalanceCancellationProvider {
    db;
    constructor(db) {
        this.db = db;
    }
    async batchBalanceCancellationByChargesIds(ids) {
        const ballanceCancellations = await getBalanceCancellationByChargesIds.run({
            chargeIds: ids,
        }, this.db);
        return ids.map(id => ballanceCancellations.filter(record => record.charge_id === id));
    }
    getBalanceCancellationByChargesIdLoader = new DataLoader((keys) => this.batchBalanceCancellationByChargesIds(keys));
    deleteBalanceCancellationByBusinessId(businessId) {
        return deleteBalanceCancellationByBusinessId.run({ businessId }, this.db);
    }
    clearCache() {
        this.getBalanceCancellationByChargesIdLoader.clearAll();
    }
};
BalanceCancellationProvider = __decorate([
    Injectable({
        scope: Scope.Operation,
        global: true,
    }),
    __metadata("design:paramtypes", [TenantAwareDBClient])
], BalanceCancellationProvider);
export { BalanceCancellationProvider };
//# sourceMappingURL=balance-cancellation.provider.js.map