package com.casic.dcms.mvp.presenter;

import com.casic.dcms.bean.PublicKeyBean;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.AuthenticateModelImpl;
import com.casic.dcms.mvp.view.IAuthenticateView;

public class AuthenticatePresenterImpl extends BasePresenter implements IAuthenticatePresenter, AuthenticateModelImpl.OnAuthenticateListener {

    private IAuthenticateView view;
    private AuthenticateModelImpl model;

    public AuthenticatePresenterImpl(IAuthenticateView authenticateView) {
        this.view = authenticateView;
        model = new AuthenticateModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest() {
        view.showProgress();
        addSubscription(model.sendRetrofitRequest());
    }

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

    @Override
    public void onSuccess(PublicKeyBean key) {
        view.hideProgress();
        view.authenticateResult(key);
    }

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