package com.casic.dcms.mvp.presenter.impl;

import com.casic.dcms.bean.ActionResultBean;
import com.casic.dcms.listener.OnActionResultListener;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.impl.ChangePasswordModelImpl;
import com.casic.dcms.mvp.presenter.IChangePasswordPresenter;
import com.casic.dcms.mvp.view.IChangePasswordView;

public class ChangePasswordPresenterImpl extends BasePresenter implements IChangePasswordPresenter, OnActionResultListener {

    private final IChangePasswordView view;
    private final ChangePasswordModelImpl actionModel;

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

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

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

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

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