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

import com.casic.dcms.bean.NewVersionBean;
import com.casic.dcms.listener.OnUpdateVersionListener;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.impl.UpdateVersionModelImpl;
import com.casic.dcms.mvp.presenter.IUpdatePresenter;
import com.casic.dcms.mvp.view.IUpdateVersionView;

public class UpdatePresenterImpl extends BasePresenter implements IUpdatePresenter, OnUpdateVersionListener {

    private final IUpdateVersionView view;
    private final UpdateVersionModelImpl actionModel;

    public UpdatePresenterImpl(IUpdateVersionView updateVersionView) {
        this.view = updateVersionView;
        actionModel = new UpdateVersionModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest() {
        view.showProgress();
        addSubscription(actionModel.sendUpdateVersionRequest());
    }

    @Override
    public void onSuccess(NewVersionBean resultBean) {
        view.hideProgress();
        view.obtainVersionResult(resultBean);
    }

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

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