package com.example.doctor_app_flutter.ui;

import com.example.doctor_app_flutter.Model.GetSessionStatusModel;
import com.example.doctor_app_flutter.Model.SessionStatusModel;
import com.example.doctor_app_flutter.Service.AppRetrofit;
import com.example.doctor_app_flutter.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();
            }
        });

    }
}
