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

import java.util.List;

import javax.inject.Singleton;

import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.model.DtbDoct;
import it.integry.integrywmsnative.core.rest.RESTBuilder;
import it.integry.integrywmsnative.core.rest.model.LoadColliDTO;
import it.integry.integrywmsnative.core.rest.model.ServiceRESTResponse;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

@Singleton
public class DocumentiRESTConsumer extends _BaseRESTConsumer {
    

    public void createDocsFromColli(List<LoadColliDTO> listColli, RunnableArgs<List<DtbDoct>> onComplete, RunnableArgs<Exception> onFailed) {
        DocumentiRESTConsumerService documentiRESTConsumerService = RESTBuilder.getService(DocumentiRESTConsumerService.class);
        documentiRESTConsumerService.createDocsFromColli(listColli).enqueue(new Callback<>() {
            @Override
            public void onResponse(Call<ServiceRESTResponse<List<DtbDoct>>> call, Response<ServiceRESTResponse<List<DtbDoct>>> response) {
                analyzeAnswer(response, "createDocsFromColli", onComplete, onFailed);
            }

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

    public void createDocFromColli(LoadColliDTO loadColliDTO, RunnableArgs<DtbDoct> onComplete, RunnableArgs<Exception> onFailed) {
        DocumentiRESTConsumerService documentiRESTConsumerService = RESTBuilder.getService(DocumentiRESTConsumerService.class);
        documentiRESTConsumerService.createDocFromColli(loadColliDTO).enqueue(new Callback<>() {
            @Override
            public void onResponse(Call<ServiceRESTResponse<DtbDoct>> call, Response<ServiceRESTResponse<DtbDoct>> response) {
                analyzeAnswer(response, "createDocFromColli", onComplete, onFailed);
            }

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


}
