package com.casic.dcms.mvp.presenter;

import com.casic.dcms.bean.ActionResultBean;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.UploadImageModelImpl;
import com.casic.dcms.mvp.view.IUploadFileView;

import java.io.File;

public class UploadImagePresenterImpl extends BasePresenter implements IUploadFilePresenter, UploadImageModelImpl.OnUploadImageListener {

    private IUploadFileView view;
    private UploadImageModelImpl actionModel;

    public UploadImagePresenterImpl(IUploadFileView uploadImageView) {
        this.view = uploadImageView;
        actionModel = new UploadImageModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(File file) {
        view.showProgress();
        addSubscription(actionModel.sendRetrofitRequest(file));
    }

    @Override
    public void onSuccess(ActionResultBean resultBean) {
        view.hideProgress();
        view.obtainUploadImageResult(resultBean);
    }

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

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