import { TaxCategoriesProvider } from '../../financial-entities/providers/tax-categories.provider.js';
import { getFinancialAccountByTransactionId } from '../helpers/account-by-transaction.helper.js';
import { FinancialAccountsProvider } from '../providers/financial-accounts.provider.js';
function getPrivateOrBusinessType(privateOrBusiness) {
    switch (privateOrBusiness) {
        case 'PRIVATE':
            return 'PRIVATE';
        case 'BUSINESS':
            return 'BUSINESS';
        default:
            throw new Error(`Unknown privateOrBusiness type: ${privateOrBusiness}`);
    }
}
export const commonFinancialAccountFields = {
    id: DbAccount => DbAccount.id,
    type: DbAccount => DbAccount.type,
    number: DbAccount => DbAccount.account_number,
    privateOrBusiness: DbAccount => getPrivateOrBusinessType(DbAccount.private_business),
    accountTaxCategories: async (DbAccount, _, { injector }) => {
        const taxCategories = await injector
            .get(TaxCategoriesProvider)
            .taxCategoryByFinancialAccountIdsLoader.load(DbAccount.id)
            .then(categories => {
            return categories.map(category => ({
                id: `${DbAccount.id}-${category.currency}`,
                currency: category.currency,
                taxCategory: category,
            }));
        });
        return taxCategories;
    },
};
export const commonTransactionFields = {
    account: async (transactionId, _, { injector }) => getFinancialAccountByTransactionId(transactionId, injector),
};
export const commonFinancialEntityFields = {
    accounts: async (DbBusiness, _, { injector }) => {
        const accounts = await injector
            .get(FinancialAccountsProvider)
            .getFinancialAccountsByOwnerIdLoader.load(DbBusiness.id);
        return accounts;
    },
};
//# sourceMappingURL=common.js.map