import { B as Business } from './Business-BcNb9bVO.js';
import { C as ComponentErrorSeverity } from './Plaid-DxSkT8pY.js';
import { g as getErrorCode, a as getErrorMessage } from './utils-CVYvs2hZ.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(response.data) });
        }
        else {
            const responseError = getErrorMessage(response.error);
            const code = getErrorCode((_a = response.error) === null || _a === void 0 ? void 0 : _a.code);
            return onError({
                error: responseError,
                code,
                severity: ComponentErrorSeverity.ERROR,
            });
        }
    }
    catch (error) {
        const code = getErrorCode(error === null || error === void 0 ? void 0 : error.code);
        return onError({
            error: error.message || error,
            code,
            severity: ComponentErrorSeverity.ERROR,
        });
    }
    finally {
        final();
    }
};

export { makeGetBusiness as m };
