package org.ntlab.acanthus_client.views.paint.models;

import org.ntlab.acanthus_client.Acanthus;
import org.ntlab.acanthus_client.resources.gallery.InvitesRest;
import org.ntlab.acanthus_client.resources.gallery.StrokesRest;

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

//-----------------------------------------------------------------
// 招待関係通信
public class InvitesConnectionModel {
    private Retrofit retrofit;
    private Acanthus acanthus;

    //-----------------------------------------------------------------
    //
    public InvitesConnectionModel(Acanthus acanthus) {
        init(acanthus);
    }

    //-----------------------------------------------------------------
    //-----------------------------------------------------------------
    // init
    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();
    }

    //-----------------------------------------------------------------
    // 新しい編集者の追加(POST)
    public void inviteNewEditor(Integer invitedUid) {
        final InvitesRest invitesRest = retrofit.create(InvitesRest.class);

        //-----------------------------------------------------------------
        // 招待リクエストを送るAPI
        //        Call<String> call = invitesRest.addInvite(
        //                acanthus.getAid(), acanthus.getPreferenceUid().toString(),
        //                invitedUid.toString(), acanthus.getPreferenceToken());

        Integer owner = 1;
        String token = "abc0";
        int dummyAid = 1111;

        Call<String> call = invitesRest.addInvite(dummyAid, owner.toString(), invitedUid.toString(), token);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if (response.isSuccessful()) ;
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        });
    }
    //-----------------------------------------------------------------

}
