package com.example.nemophila.viewmodels;
import com.example.nemophila.entities.Account;
import com.example.nemophila.resources.AccountsRest;
import androidx.lifecycle.ViewModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;
public class AccountViewModel extends ViewModel {
    // フィールド
    private final Retrofit retrofit;
    private final AccountsRest accountsRest;
    // コンストラクタ
    public AccountViewModel() {
        this.retrofit = new Retrofit.Builder()
                .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/nemophila/")
                .addConverterFactory(JacksonConverterFactory.create())
                .build();
        this.accountsRest = retrofit.create(AccountsRest.class);
    }
    // アカウント情報の取得
    public void getAccount(String uid) {
        Call<Account> call = accountsRest.getAccount(uid);
        call.enqueue(new Callback<Account>() {
            @Override
            public void onResponse(Call<Account> call, Response<Account> response) {
            }
            @Override
            public void onFailure(Call<Account> call, Throwable t) {
            }
        });
    }
    // アカウント名の変更
    public void changeName(String uid, String name, String token) {
        Call<Void> call = accountsRest.changeName(uid, name, token);
        call.enqueue(new Callback<Void>() {
            @Override
            public void onResponse(Call<Void> call, Response<Void> response) {
            }
            @Override
            public void onFailure(Call<Void> call, Throwable t) {
            }
        });
    }
}