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.CaseHandleModelImpl;
import com.casic.dcms.mvp.presenter.ICaseHandlePresenter;
import com.casic.dcms.mvp.view.ICaseDetailHandleView;

/**
 * @Author: Pengxh
 * @Time: 2021/4/12 13:29
 * @Email: 290677893@qq.com
 **/
public class CaseHandlePresenterImpl extends BasePresenter implements ICaseHandlePresenter, OnActionResultListener {

    private final ICaseDetailHandleView view;
    private final CaseHandleModelImpl actionModel;

    public CaseHandlePresenterImpl(ICaseDetailHandleView caseHandleView) {
        this.view = caseHandleView;
        actionModel = new CaseHandleModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String processId, String bizId, String currState, String changeState,
                                       String remarks, String fileId) {
        view.showProgress();
        addSubscription(actionModel.sendVerifyHandleRequest(processId, bizId, currState, changeState, remarks, fileId));
    }

    @Override
    public void onReadyRetrofitRequest(String processId, String bizId, String currState, String changeState,
                                       String remarks, String fileId, String approvalResult) {
        view.showProgress();
        addSubscription(actionModel.sendOvertimeHandleRequest(processId, bizId, currState, changeState, remarks, fileId,
                approvalResult));
    }

    @Override
    public void onReadyRetrofitRequest(String processId, String bizId, String currState, String changeState,
                                       String remarks, String fileId, String eorc, String casetypeCode,
                                       String casetypeDetailCode, String lng, String lat, String caseLevel,
                                       String areaCode, String streetCode, String communityCode, String gridId,
                                       String fieldintro) {
        view.showProgress();
        addSubscription(actionModel.sendCheckHandleRequest(processId, bizId, currState, changeState,
                remarks, fileId, eorc, casetypeCode, casetypeDetailCode, lng, lat, caseLevel, areaCode,
                streetCode, communityCode, gridId, fieldintro));
    }

    @Override
    public void onReadyDispatcherRetrofitRequest(String processId, String bizId, String currState,
                                                 String changeState, String remarks, String operationKey,
                                                 String taskUserId) {
        view.showProgress();
        addSubscription(actionModel.sendDispatcherHandleRequest(processId, bizId, currState, changeState, remarks,
                operationKey, taskUserId));
    }

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

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

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