import { ComponentErrorSeverity, TerminalModel } from "../../api";
import { getErrorCode, getErrorMessage } from "../../api/services/utils";
export const makeGetTerminalModels = ({ id, authToken, service }) => async ({ onSuccess, onError }) => {
    var _a, _b, _c, _d;
    try {
        const response = await service.fetchTerminalModels(id, authToken);
        if (!response.error) {
            const terminals = ((_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.terminal_order_models) === null || _b === void 0 ? void 0 : _b.map((dataItem) => new TerminalModel(dataItem))) || [];
            const orderLimit = (_c = response.data) === null || _c === void 0 ? void 0 : _c.order_limit;
            onSuccess({ terminals, orderLimit });
        }
        else {
            const responseError = getErrorMessage(response.error);
            const code = getErrorCode((_d = response.error) === null || _d === void 0 ? void 0 : _d.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,
        });
    }
};
