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

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

/**
 * Created by realicing on 2018/3/23.
 * realicing@sina.com
 */

public class CommitWxMakeMoneyPresenter implements CommitWxMakeMoneyContract.Presenter {
    private CommitWxMakeMoneyContract.View view;
    private ApiService apiService;
    @Inject
    public CommitWxMakeMoneyPresenter(CommitWxMakeMoneyContract.View view, ApiService apiService) {
        this.view = view;
        this.apiService = apiService;
    }

    @Override
    public void postWebchat(String account, String password) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("account", account);
        jsonObject.put("password", password);
        apiService.postWebchat(jsonObject)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.failPostWebchat2View(baseMessage);
                    }

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

                    }
                });
    }
}
