package com.cooleshow.student.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.ToastUtils;
import com.cooleshow.base.utils.ErrorParse;
import com.cooleshow.student.api.APIService;
import com.cooleshow.student.contract.ModifyPhoneNumContract;

/**
 * 创建日期：2022/5/17 10:56
 *
 * @author Ryan
 * 类说明：
 */
public class ModifyPhoneNumPresenter extends BasePresenter<ModifyPhoneNumContract.ModifyPhoneNumView> implements ModifyPhoneNumContract.Presenter {
    public void updatePhone(String authCode,String newPhone, String oldPhone) {
        getView().showLoading();
        addSubscribe(create(APIService.class).updatePhone(authCode, newPhone,oldPhone), new BaseObserver<Object>(getView()) {
            @Override
            protected void onSuccess(Object data) {
                if (getView() != null) {
                    getView().updatePhoneSuccess(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;
                    ToastUtils.showShort(apiException.getErrmsg());
                }
            }
        });
    }
}
