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

import com.casic.dcms.bean.LoginResultBean;
import com.casic.dcms.listener.OnLoginListener;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.impl.LoginInModelImpl;
import com.casic.dcms.mvp.presenter.ILoginInPresenter;
import com.casic.dcms.mvp.view.ILoginInView;

public class LoginPresenterImpl extends BasePresenter implements ILoginInPresenter, OnLoginListener {

    private final ILoginInView view;
    private final LoginInModelImpl actionModel;

    public LoginPresenterImpl(ILoginInView loginInView) {
        this.view = loginInView;
        actionModel = new LoginInModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String username, String key) {
        view.showProgress();
        addSubscription(actionModel.sendLoginInRequest(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();
    }
}
