package it.integry.integrywmsnative.core.REST.consumers;

import com.google.gson.JsonObject;

import it.integry.integrywmsnative.core.REST.RESTBuilder;
import it.integry.integrywmsnative.core.REST.model.Ean128Model;
import it.integry.integrywmsnative.core.REST.model.ServiceRESTResponse;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.plugins.barcode_base_library.model.BarcodeScanDTO;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class BarcodeRESTConsumer extends _BaseRESTConsumer {

    public static void decodeEan128(BarcodeScanDTO barcodeObj, RunnableArgs<Ean128Model> onComplete, RunnableArgs<Exception> onFailed) {

        String ean128 = barcodeObj.getStringValue().replaceAll("" + ((char) 29), "|");

        BarcodeRESTConsumerService barcodeRESTConsumerService = RESTBuilder.getService(BarcodeRESTConsumerService.class);
        barcodeRESTConsumerService.decodeEan128(ean128).enqueue(new Callback<ServiceRESTResponse<Ean128Model>>() {
            @Override
            public void onResponse(Call<ServiceRESTResponse<Ean128Model>> call, Response<ServiceRESTResponse<Ean128Model>> response) {
                analyzeAnswer(response, "DecodeEan128", onComplete, onFailed);
            }

            @Override
            public void onFailure(Call<ServiceRESTResponse<Ean128Model>> call, Throwable t) {
                onFailed.run(new Exception(t));
            }
        });

    }
}
