package com.cooleshow.usercenter.presenter;

import android.text.TextUtils;

import com.cooleshow.base.bean.QueryParamsConfigBean;
import com.cooleshow.base.common.BaseApplication;
import com.cooleshow.base.data.net.ApiException;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.ErrorParse;
import com.cooleshow.base.utils.ToastUtil;
import com.cooleshow.base.utils.ToastUtils;
import com.cooleshow.usercenter.data.api.UserApi;
import com.cooleshow.usercenter.presenter.contract.BindPasswordContract;


/**
 * Author by pq, Date on 2022/4/19.
 */
public class BindPasswordPresenter extends BasePresenter<BindPasswordContract.BindPwdView> implements BindPasswordContract.Presenter {

    @Override
    public void onBindPwd(String pwd, String nickName) {
        if (getView() != null) {
            getView().showLoading();
        }
        if (TextUtils.isEmpty(nickName)) {
            addSubscribe(create(UserApi.class).bindPassword(pwd), new BaseObserver<Object>(getView()) {
                @Override
                protected void onSuccess(Object data) {
                    if (getView() != null) {
                        getView().onBindSuccess();
                    }
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                }
            });
        } else {
            addSubscribe(create(UserApi.class).bindPassword(pwd, nickName), new BaseObserver<Object>(getView()) {
                @Override
                protected void onSuccess(Object data) {
                    if (getView() != null) {
                        getView().onBindSuccess();
                    }
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                }
            });
        }

    }

    public void queryModifyConfig() {
        getView().showLoading();
        String params = "last_username_month";
        if (BaseApplication.Companion.isTeacherClient()) {
            addSubscribe(create(UserApi.class).queryModifyNickConfigForTeacher(params), new BaseObserver<QueryParamsConfigBean>(getView()) {
                @Override
                protected void onSuccess(QueryParamsConfigBean data) {
                    if (getView() != null) {
                        getView().queryModifyConfigSuccess(data);
                    }
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);

                }
            });
        }
    }
}
