package org.ntlab.acanthus_client.views.main_menu_ui.home;

import org.ntlab.acanthus_client.resources.HelloWorldRest;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

public class HomeModel {
    private MutableLiveData<String> text;

    public void Gethelloworld(MutableLiveData<String> mText){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/")
                .addConverterFactory(ScalarsConverterFactory.create())
                .addConverterFactory(JacksonConverterFactory.create())
                .build();
        final HelloWorldRest helloworld = retrofit.create(HelloWorldRest.class);
        Call<String> call = helloworld.getHelloWorld();
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if(response.isSuccessful()) {
                    String res = response.body();
                    mText.setValue(res);

                }else{
                    mText.setValue("False helloworld");
                }
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                mText.setValue("みす helloworld");
            }
        });

    }

//    public void setText(MutableLiveData<String> mText){
//        this.text=mText;
//    }
//
//    public LiveData<String> getText(){
//        return text;
//    }

}
