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 javax.inject.Inject;

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

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

public class ReNamePresenter implements  ReNameContract.Presenter  {

    private ReNameContract.View view;
    private ApiService apiService;

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

    @Override
    public void getTask(HashMap<String, String> map) {
        view.showDialog();
        JSONObject j = new JSONObject();
        j.put("nickname",map.get("nickname"));

        apiService.changeBaseInfo(j)
                .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){
                            view.NetSuccess(1,"修改昵称成功", null);
                        }else{
                            view.NetError(-1,"数据解析出错");
                        }

                    }
                });
    }
}
