package com.hmg.hmgDr.ui;

import com.hmg.hmgDr.Model.ChangeCallStatusRequestModel;
import com.hmg.hmgDr.Model.GetSessionStatusModel;
import com.hmg.hmgDr.Model.SessionStatusModel;
//import com.hmg.hmgDr.Service.AppRetrofit;
import com.hmg.hmgDr.Service.SessionStatusAPI;

import org.jetbrains.annotations.NotNull;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class VideoCallPresenterImpl implements VideoCallContract.VideoCallPresenter {

    private VideoCallContract.VideoCallView view;
    private SessionStatusAPI sessionStatusAPI;
    private String baseUrl;

    public VideoCallPresenterImpl(VideoCallContract.VideoCallView view, String baseUrl) {
        this.view = view;
        this.baseUrl = baseUrl;
    }

    @Override
    public void callClintConnected(GetSessionStatusModel statusModel) {


//        sessionStatusAPI = AppRetrofit.getRetrofit(baseUrl).create(SessionStatusAPI.class);

        Call<SessionStatusModel> call = sessionStatusAPI.getSessionStatusModelData(statusModel);

        call.enqueue(new Callback<SessionStatusModel>() {
            @Override
            public void onResponse(@NotNull Call<SessionStatusModel> call, @NotNull Response<SessionStatusModel> response) {
                if (response.isSuccessful()) {
                    view.onCallSuccessful(response.body());
                } else
                    view.onFailure();
            }

            @Override
            public void onFailure(@NotNull Call<SessionStatusModel> call, @NotNull Throwable t) {
                view.onFailure();
            }
        });

    }

    @Override
    public void callChangeCallStatus(ChangeCallStatusRequestModel statusModel) {
//        sessionStatusAPI = AppRetrofit.getRetrofit(baseUrl).create(SessionStatusAPI.class);

        Call<SessionStatusModel> call = sessionStatusAPI.changeCallStatus(statusModel);

        call.enqueue(new Callback<SessionStatusModel>() {
            @Override
            public void onResponse(@NotNull Call<SessionStatusModel> call, @NotNull Response<SessionStatusModel> response) {
                if (!response.isSuccessful())
                    view.onFailure();
            }

            @Override
            public void onFailure(@NotNull Call<SessionStatusModel> call, @NotNull Throwable t) {
                view.onFailure();
            }
        });
    }
}
