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.util.SheepSubscriber;
import com.sheep.jiuyan.samllsheep.SheepApp;

import java.util.HashMap;
import java.util.Iterator;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

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

public class RealNameAutherPresenter implements  RealNameAutherContract.Presenter  {

    private RealNameAutherContract.View view;
    private ApiService apiService;

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

    @Override
    public void getTask(HashMap<String, String> map) {
       JSONObject  jsonObject=new JSONObject();
        Iterator map1it=map.entrySet().iterator();
        for(String key:map.keySet())
        {
            jsonObject.put(key,map.get(key));
        }
        view.showGoProgress();
        apiService.bindALl(jsonObject).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) {
                        view.NetSuccess(0,baseMessage.getMsg() +"", null);

                    }
                });




    }
}
