import { Payout } from "../../api";
import { ComponentErrorSeverity } from "../../api/ComponentError";
import { getErrorCode, getErrorMessage } from "../../api/services/utils";
export const makeGetPayoutDetails = ({ id, authToken, service }) => async ({ onSuccess, onError }) => {
    var _a;
    try {
        const response = await service.fetchPayout(id, authToken);
        if (!response.error) {
            const payout = new Payout(response.data);
            onSuccess(payout);
        }
        else {
            const errorMessage = getErrorMessage(response.error);
            const code = getErrorCode((_a = response.error) === null || _a === void 0 ? void 0 : _a.code);
            onError({
                error: errorMessage,
                code,
                severity: ComponentErrorSeverity.ERROR,
            });
        }
    }
    catch (error) {
        const errorMessage = getErrorMessage(error);
        const code = getErrorCode(error === null || error === void 0 ? void 0 : error.code);
        onError({
            error: errorMessage,
            code,
            severity: ComponentErrorSeverity.ERROR,
        });
    }
};
