package com.sheep.gamegroup.presenter;

import android.util.Log;

import com.sheep.gamegroup.model.api.ApiService;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.util.SheepSubscriber;
import com.sheep.jiuyan.samllsheep.SheepApp;
import com.sheep.jiuyan.samllsheep.utils.SpUtils;

import javax.inject.Inject;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ljy on 2018/3/10.
 */

public class PersonalCenterPresenter implements PersonalCenterContract.Persenter {
    private PersonalCenterContract.View view;
    private ApiService apiService;

    @Inject
    public PersonalCenterPresenter(PersonalCenterContract.View view, ApiService apiService) {
        this.view = view;
        this.apiService = apiService;
    }

    @Override
    public void getUserInfo() {
        String token = SpUtils.getOpenId(SheepApp.mContext);

        Log.e("token---user",token+"");
        apiService.getInfo()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.failData2View(baseMessage);

                    }

                    @Override
                    public void onNext(BaseMessage baseMessage) {
                        view.updateData2View(baseMessage);

                    }
                });
    }
}
