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

import javax.inject.Singleton;

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

@Singleton
public class AziendaRESTConsumer extends _BaseRESTConsumer {

    public void retrieveAzienda(RunnableArgs<Azienda> onComplete, RunnableArgs<Exception> onFailed) {
        AziendaRESTConsumerService aziendaRESTConsumerService = RESTBuilder.getService(AziendaRESTConsumerService.class);
        aziendaRESTConsumerService.retrieveDefaultAzienda().enqueue(new Callback<>() {
            @Override
            public void onResponse(Call<ServiceRESTResponse<Azienda>> call, Response<ServiceRESTResponse<Azienda>> response) {
                analyzeAnswer(response, "Retrieve default azienda", onComplete, onFailed);
            }

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

}
