package org.springblade.flow.engine.service;

import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.springblade.flow.engine.entity.FlowTaskEntity;
import org.springblade.flow.engine.entity.FlowTaskOperatorEntity;
import org.springblade.flow.engine.model.FlowHandleModel;
import org.springblade.flow.engine.model.flowbefore.FlowBeforeInfoVO;
import org.springblade.flow.engine.model.flowengine.FlowModel;
import org.springblade.flow.exception.WorkFlowException;

/**
 * 流程引擎
 *
 * @author JNPF开发平台组
 * @version V3.2.0
 * @copyright 引迈信息技术有限公司
 * @date 2021年4月27日 上午9:18
 */
public interface FlowTaskNewService {

    /**
     * 保存
     *
     * @param flowModel 保存数据
     * @return
     * @throws WorkFlowException 异常
     */
    ProcessInstance saveIsAdmin(FlowModel flowModel) throws WorkFlowException;

    /**
     * 保存
     *
     * @param flowModel 保存数据
     * @return
     * @throws WorkFlowException 异常
     */
    ProcessInstance save(FlowModel flowModel) throws WorkFlowException;

    /**
     * 提交
     *
     * @param flowModel 提交数据
     * @throws WorkFlowException 异常
     */
    void submit(FlowModel flowModel) throws WorkFlowException;

    /**
     * 审批
     *
     * @param id        待办主键
     * @param flowModel 提交数据
     * @throws WorkFlowException 异常
     */
    void audit(String id, FlowModel flowModel) throws WorkFlowException;

    /**
     * 审批
     *
     * @param flowTask  流程实例
     * @param operator  流程经办
     * @param flowModel 提交数据
     * @throws WorkFlowException
     */
    void audit(FlowTaskEntity flowTask, FlowTaskOperatorEntity operator, FlowModel flowModel, Task task) throws WorkFlowException;

    /**
     * 驳回
     *
     * @param id        待办主键
     * @param flowModel 提交数据
     * @return
     * @throws WorkFlowException 异常
     */
    void reject(String id, FlowModel flowModel) throws WorkFlowException;

    /**
     * 驳回
     *
     * @param operator  流程经办
     * @param flowModel 提交数据
     * @throws WorkFlowException
     */
    void reject(FlowTaskOperatorEntity operator, FlowModel flowModel,Task task) throws WorkFlowException;

    /**
     * 已办撤回
     *
     * @param id             已办id
     * @param flowModel      提交数据
     * @throws WorkFlowException 异常
     */
    void recall(String id,  FlowModel flowModel, HistoricTaskInstance historicTaskInstance) throws WorkFlowException;

    /**
     * 发起撤回
     *
     * @param processInstance  流程实例
     * @param flowModel 提交数据
     */
    void revoke(ProcessInstance processInstance, FlowModel flowModel);

    /**
     * 终止
     *
     * @param processInstanceId
     * @param flowModel 提交数据
     */
    void cancel(String processInstanceId, FlowModel flowModel);

    /**
     * 指派
     *
     * @param id
     * @param flowHandleModel 提交数据
     * @return
     */
    boolean assign(String id, FlowHandleModel flowHandleModel);

    /**
     * 转办
     *
     * @param taskOperator 经办数据
     */
    void transfer(FlowTaskOperatorEntity taskOperator);

    /**
     * 获取任务详情
     *
     * @param id         主键
     * @param taskNodeId
     * @return
     * @throws WorkFlowException 异常
     */
    FlowBeforeInfoVO getBeforeInfo(String id, String taskNodeId) throws WorkFlowException;
}
