package com.cooleshow.teacher.presenter.mine;

import com.cooleshow.base.data.net.ApiException;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.ToastUtil;
import com.cooleshow.base.utils.ToastUtils;
import com.cooleshow.base.utils.ErrorParse;
import com.cooleshow.teacher.api.APIService;
import com.cooleshow.teacher.contract.CheckModifyPhoneNumContract;

/**
 * 创建日期：2022/5/17 10:15
 *
 * @author Ryan
 * 类说明：
 */
public class CheckModifyPhoneNumPresenter extends BasePresenter<CheckModifyPhoneNumContract.CheckModifyPhoneNumView> implements CheckModifyPhoneNumContract.Presenter {

    public void checkUser(String phone, String password) {
        getView().showLoading();
        addSubscribe(create(APIService.class).checkUser(phone, password), new BaseObserver<Object>(getView()) {
            @Override
            protected void onSuccess(Object data) {
                if (getView() != null) {
                    getView().checkUserSuccess(data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
                getView().hideLoading();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if (e instanceof ApiException) {
                    ErrorParse.getInstance().parseError(e);
                    ApiException apiException = (ApiException) e;
                    ToastUtil.getInstance().showShort(apiException.getErrmsg());
                }
            }
        });
    }
}
