'use strict';

var Business = require('./Business-oBifyXkW.js');
var Plaid = require('./Plaid-CPESyiiV.js');
var utils = require('./utils-BsnepLy6.js');

const makeGetBusiness = ({ id, authToken, service }) => async ({ onSuccess, onError, final }) => {
    var _a;
    try {
        const response = await service.fetchBusiness(id, authToken);
        if (!response.error) {
            onSuccess({ business: new Business.Business(response.data) });
        }
        else {
            const responseError = utils.getErrorMessage(response.error);
            const code = utils.getErrorCode((_a = response.error) === null || _a === void 0 ? void 0 : _a.code);
            return onError({
                error: responseError,
                code,
                severity: Plaid.ComponentErrorSeverity.ERROR,
            });
        }
    }
    catch (error) {
        const code = utils.getErrorCode(error === null || error === void 0 ? void 0 : error.code);
        return onError({
            error: error.message || error,
            code,
            severity: Plaid.ComponentErrorSeverity.ERROR,
        });
    }
    finally {
        final();
    }
};

exports.makeGetBusiness = makeGetBusiness;
