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.PackageHandleModelImpl;
import com.casic.dcms.mvp.presenter.IPackageHandlePresenter;
import com.casic.dcms.mvp.view.IPackageDetailHandleView;

public class PackageHandlePresenterImpl extends BasePresenter implements IPackageHandlePresenter, OnActionResultListener {

    private final IPackageDetailHandleView view;
    private final PackageHandleModelImpl actionModel;

    public PackageHandlePresenterImpl(IPackageDetailHandleView packageDetailHandleView) {
        this.view = packageDetailHandleView;
        actionModel = new PackageHandleModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String id, String punishType, String punishRemarks, String punishTime,
                                       String punishImage) {
        view.showProgress();
        addSubscription(actionModel.sendPackageHandleRequest(id, punishType, punishRemarks, punishTime, punishImage));
    }

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

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

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