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.FriendAndAwardEntity;
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 AskGetMoneyPresenter implements AskGetMoneyContract.Presenter {
    private AskGetMoneyContract.View view;
    private ApiService apiService;

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


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

        apiService.FriendCountAndAward()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.NetError(-1, baseMessage.getMsg());
                    }

                    @Override
                    public void onNext(BaseMessage baseMessage) {
                        if(baseMessage!=null){
                            FriendAndAwardEntity Ety = baseMessage.getData(FriendAndAwardEntity.class);
                            view.showTask(Ety);
                        }else{
                            view.NetError(-1,"数据解析出错");
                        }

                    }
                });


    }
}
