package com.casic.dcms.mvp.presenter;

import com.casic.dcms.bean.LoginResultBean;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.LoginActionModelImpl;
import com.casic.dcms.mvp.view.ILoginView;

public class LoginPresenterImpl extends BasePresenter implements ILoginPresenter, LoginActionModelImpl.OnLoginListener {

    private ILoginView view;
    private LoginActionModelImpl actionModel;

    public LoginPresenterImpl(ILoginView loginView) {
        this.view = loginView;
        actionModel = new LoginActionModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String username, String key) {
        view.showProgress();
        addSubscription(actionModel.sendRetrofitRequest(username, key));
    }

    @Override
    public void onSuccess(LoginResultBean resultBean) {
        view.hideProgress();
        view.obtainLoginResult(resultBean);
    }

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

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