package it.integry.integrywmsnative.core.menu;

import javax.inject.Singleton;

import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.model.StbMenu;
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 MenuRESTConsumer extends _BaseRESTConsumer {

    public void retrieveMenu(String rootCodOpz, RunnableArgs<StbMenu> onComplete, RunnableArgs<Exception> onFailed) {
        MenuRESTConsumerService menuRESTConsumerService = RESTBuilder.getService(MenuRESTConsumerService.class);
        menuRESTConsumerService.retrieveMenuConfig(rootCodOpz).enqueue(new Callback<>() {
            @Override
            public void onResponse(Call<ServiceRESTResponse<StbMenu>> call, Response<ServiceRESTResponse<StbMenu>> response) {
                analyzeAnswer(response, "retrieveMenu", onComplete, onFailed);
            }

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

}
