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

import com.casic.dcms.bean.ActionResultBean;
import com.casic.dcms.listener.OnActionResultListener;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.impl.UploadFileModelImpl;
import com.casic.dcms.mvp.presenter.IUploadFilePresenter;
import com.casic.dcms.mvp.view.IUploadFileView;

import java.io.File;

public class UploadAudioPresenterImpl extends BasePresenter implements IUploadFilePresenter, OnActionResultListener {

    private final IUploadFileView view;
    private final UploadFileModelImpl actionModel;

    public UploadAudioPresenterImpl(IUploadFileView uploadAudioView) {
        this.view = uploadAudioView;
        actionModel = new UploadFileModelImpl(this);
    }

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

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

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

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