package it.integry.integrywmsnative.gest.ordini_uscita_elenco.rest;

import java.util.List;

import javax.inject.Singleton;

import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.model.DtbOrdt;
import it.integry.integrywmsnative.core.model.MtbColt;
import it.integry.integrywmsnative.core.model.secondary.GestioneEnum;
import it.integry.integrywmsnative.core.rest.RESTBuilder;
import it.integry.integrywmsnative.core.rest.consumers._BaseRESTConsumer;
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

@Singleton
public class OrdiniUscitaElencoRESTConsumer extends _BaseRESTConsumer {

    public void getOrdiniFromCommessaCollo(String codMdep, MtbColt testataCollo, RunnableArgs<List<DtbOrdt>> onComplete, RunnableArgs<Exception> onFailed) {
        OrdiniUscitaElencoRESTConsumerService service = RESTBuilder.getService(OrdiniUscitaElencoRESTConsumerService.class);
        service.getOrdiniInCommessaCollo(
                testataCollo.getDataColloS(),
                testataCollo.getNumCollo(),
                testataCollo.getSerCollo(),
                testataCollo.getGestione(),
                GestioneEnum.VENDITA.getText(),
                codMdep)
                .enqueue(new Callback<ServiceRESTResponse<List<DtbOrdt>>>() {
                    @Override
                    public void onResponse(Call<ServiceRESTResponse<List<DtbOrdt>>> call, Response<ServiceRESTResponse<List<DtbOrdt>>> response) {
                        analyzeAnswer(response, "getOrdiniFromCommessaCollo", (m) -> {
                            onComplete.run(response.body().getEntity());
                        }, onFailed);
                    }

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

}
