import { C as ComponentErrorSeverity } from './Plaid.js';
import { g as getErrorCode, a as getErrorMessage } from './utils3.js';
import { A as Api } from './Api.js';
import './Pagination.js';
import './Business.js';
import './ApplePay.js';

const makeUpdateDisputeResponse = ({ authToken, disputeId, service }) => async ({ payload, onSuccess, onError, final = () => { } }) => {
    var _a;
    try {
        const response = await service.updateDisputeResponse(disputeId, authToken, payload);
        if (!response.error) {
            onSuccess(response);
        }
        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();
    }
};
const makeSubmitDisputeResponse = ({ authToken, disputeId, service }) => async ({ payload, onSuccess, onError, final = () => { } }) => {
    var _a;
    try {
        const response = await service.submitDisputeResponse(disputeId, authToken, payload);
        if (!response.error) {
            onSuccess(response);
        }
        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();
    }
};
const makeCreateDisputeEvidence = ({ authToken, disputeId, service }) => async ({ payload, onSuccess, onError, final = () => { } }) => {
    var _a;
    try {
        const response = await service.createDisputeEvidence(disputeId, authToken, payload);
        if (!response.error) {
            onSuccess(response);
        }
        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();
    }
};

const api = Api();
class DisputeService {
    async fetchDispute(disputeId, authToken) {
        const endpoint = `disputes/${disputeId}`;
        return api.get({ endpoint, authToken });
    }
    async updateDisputeResponse(disputeId, authToken, payload) {
        const endpoint = `disputes/${disputeId}/response`;
        const body = payload;
        return api.patch({ endpoint, body, authToken });
    }
    async submitDisputeResponse(disputeId, authToken, payload) {
        const endpoint = `disputes/${disputeId}/response`;
        const body = payload;
        return api.post({ endpoint, body, authToken });
    }
    async createDisputeEvidence(disputeId, authToken, payload) {
        const endpoint = `disputes/${disputeId}/evidence`;
        const body = payload;
        return api.put({ endpoint, body, authToken });
    }
}

var DisputeManagementClickActions;
(function (DisputeManagementClickActions) {
    DisputeManagementClickActions["nextStep"] = "nextStep";
    DisputeManagementClickActions["previousStep"] = "previousStep";
    DisputeManagementClickActions["cancelDispute"] = "cancelDispute";
    DisputeManagementClickActions["respondToDispute"] = "respondToDispute";
    DisputeManagementClickActions["submit"] = "submit";
})(DisputeManagementClickActions || (DisputeManagementClickActions = {}));
var DisputeResponseFormStep;
(function (DisputeResponseFormStep) {
    DisputeResponseFormStep["disputeReason"] = "dispute_reason";
    DisputeResponseFormStep["productOrService"] = "product_or_service";
    DisputeResponseFormStep["customerDetails"] = "customer_details";
    DisputeResponseFormStep["cancellationPolicy"] = "cancellation_policy";
    DisputeResponseFormStep["refundPolicy"] = "refund_policy";
    DisputeResponseFormStep["duplicateCharge"] = "duplicate_charge";
    DisputeResponseFormStep["electronicEvidence"] = "electronic_evidence";
    DisputeResponseFormStep["shippingDetails"] = "shipping_details";
    DisputeResponseFormStep["additionalStatement"] = "additional_statement";
})(DisputeResponseFormStep || (DisputeResponseFormStep = {}));

export { DisputeManagementClickActions as D, DisputeService as a, makeUpdateDisputeResponse as b, makeCreateDisputeEvidence as c, makeSubmitDisputeResponse as m };
