package org.ntlab.acanthus_client.views.animation;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;

import org.ntlab.acanthus_client.Acanthus;
import org.ntlab.acanthus_client.entities.Stroke;
import org.ntlab.acanthus_client.resources.gallery.StrokesRest;

import java.util.Collection;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

public class AnimationConnectionModel {
    private Retrofit retrofit;
    private Acanthus acanthus;

    public AnimationConnectionModel(Acanthus acanthus) {
        init(acanthus);
    }

    public void init(Acanthus acanthus) {
        this.acanthus = acanthus;
        this.retrofit = new Retrofit.Builder()
                .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/")
                .addConverterFactory(ScalarsConverterFactory.create())
                .addConverterFactory(JacksonConverterFactory.create())
                .build();
    }

    public void getPage(MutableLiveData<String> pages) {
        final StrokesRest strokesRest = retrofit.create(StrokesRest.class);

        //-----------------------------------------------------------------
        // 筆跡追加API
        Call<String> call = strokesRest.getLayers(300, 0);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if (response.isSuccessful()){
                    pages.setValue(response.body());
                }
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                Log.d("a", "onFailure: ");
            }

        });

    }
}
