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 rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ljy on 2018/3/19.
 */

public class BindDataPresenter implements BindDataContract.Presenter {
    private BindDataContract.View view;
    private ApiService apiService;

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

    @Override
    public void submitData(Object o) {

    }

    @Override
    public void submitDataRealname(Object o) {

        apiService.bindRealname((JSONObject) o)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.failView(baseMessage);
                    }

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

    }

    @Override
    public void submitDataBankcard(Object o) {

        apiService.bindBankCard((JSONObject) o)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.failView(baseMessage);
                    }

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

    }

    @Override
    public void submitDataIdnumber(Object o) {

        apiService.bindIdNumber((JSONObject) o)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        view.failView(baseMessage);
                    }

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

    }
}
