package com.sheep.gamegroup.presenter;

import com.alibaba.fastjson.JSONObject;
import com.sheep.gamegroup.model.api.ApiService;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.entity.UserEntity;
import com.sheep.gamegroup.model.util.SheepSubscriber;
import com.sheep.gamegroup.util.FastJsonUtils;
import com.sheep.jiuyan.samllsheep.SheepApp;

import java.util.HashMap;

import javax.inject.Inject;

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

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

public class AccountAndSecuritPresenter implements  AccountAndSecuritContract.Presenter  {

    private AccountAndSecuritContract.View view;
    private ApiService apiService;

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


    @Override
    public void getTask(HashMap<String, String> map) {


        apiService.getInfo().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.NetError(-1,"请求网络异常");
                    }

                    @Override
                    public void onNext(BaseMessage baseMessage) {
                        if(baseMessage!=null){


                        UserEntity loginEty = FastJsonUtils.toBean( JSONObject.toJSONString(baseMessage.getData()),UserEntity.class);
                        view.showTask(loginEty);

                        }
                    }
                }); } }