package com.casic.dcms.mvp.presenter;

import com.casic.dcms.bean.ActionResultBean;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.ChangePasswordModelImpl;
import com.casic.dcms.mvp.view.IChangePasswordView;

public class ChangePasswordPresenterImpl extends BasePresenter implements IChangePasswordPresenter, ChangePasswordModelImpl.OnPasswordChangedListener {

    private IChangePasswordView view;
    private ChangePasswordModelImpl actionModel;

    public ChangePasswordPresenterImpl(IChangePasswordView changePasswordView) {
        this.view = changePasswordView;
        actionModel = new ChangePasswordModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String oldPwd, String newPwd) {
        addSubscription(actionModel.sendRetrofitRequest(oldPwd, newPwd));
    }

    @Override
    public void onSuccess(ActionResultBean resultBean) {
        view.obtainChangePassResult(resultBean);
    }

    @Override
    public void onFailure(Throwable throwable) {
        view.obtainDataFail();
    }

    @Override
    public void disposeRetrofitRequest() {
        unSubscription();
    }
}
