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

import com.casic.dcms.bean.PublicKeyBean;
import com.casic.dcms.listener.OnAuthenticateListener;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.impl.AuthenticateModelImpl;
import com.casic.dcms.mvp.presenter.IAuthenticatePresenter;
import com.casic.dcms.mvp.view.IAuthenticateView;

public class AuthenticatePresenterImpl extends BasePresenter implements IAuthenticatePresenter, OnAuthenticateListener {

    private final IAuthenticateView view;
    private final AuthenticateModelImpl model;

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

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

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

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

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