package cn.axzo.workflow.client.feign.bpmn;

import cn.axzo.workflow.client.annotation.WorkflowEngineFeignClient;
import cn.axzo.workflow.common.annotation.InvokeMode;
import cn.axzo.workflow.common.annotation.Manageable;
import cn.axzo.workflow.common.model.request.bpmn.activity.BpmnActivityTimeoutCallbackDTO;
import cn.axzo.workflow.common.model.request.bpmn.activity.BpmnActivityTimeoutTriggerDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnActivitySetAssigneeDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnActivityTriggerDTO;
import cn.azxo.framework.common.model.CommonResponse;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.constraints.NotBlank;

import static cn.axzo.workflow.common.enums.RpcInvokeModeEnum.ASYNC;
import static cn.axzo.workflow.common.enums.RpcInvokeModeEnum.SYNC;

/**
 * 流程活动的 API
 *
 * @author wangli
 * @since 2023/11/17 16:28
 */
//@FeignClient(name = "workflow-engine", url = "${axzo.service.workflow-engine:http://workflow-engine:8080}", configuration = CommonFeignConfiguration.class)
@WorkflowEngineFeignClient
public interface ProcessActivityApi {

    /**
     * 业务节点唤醒, 该节点废弃，请换成 {@link ProcessActivityApi#trigger(cn.axzo.workflow.common.model.request.bpmn.task.BpmnActivityTriggerDTO)} 接口
     * <p>
     * 当模型中使用了“业务节点”，且设置了“不设置审批人”模式，则当业务监听到 PROCESS_ACTIVITY_START 事件时，可通过该接口推动流程继续运行
     */
    @Deprecated
    @GetMapping("/api/process/activity/trigger")
    @Manageable
    @InvokeMode(SYNC)
    CommonResponse<Boolean> trigger(@NotBlank(message = "触发 ID 不能为空") @RequestParam String triggerId);

    /**
     * 业务节点唤醒
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/process/activity/trigger")
    @InvokeMode(SYNC)
    CommonResponse<Boolean> trigger(@Validated @RequestBody BpmnActivityTriggerDTO dto);


    /**
     * 业务节点设置审批人, 不支持重复设置
     * <p>
     * 当模型中使用了“业务节点”，且设置了“业务指定审批人”模式，则当业务监听到 PROCESS_ACTIVITY_WAIT_ASSIGNEE 事件时，可通过该接口设置动态设置审批人
     * <p>
     * <strong color=orange>注意：如果调用接口时，传入的审批人集合为空，流程引擎将对该审批流程实例自动中止。</strong>
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/process/activity/assignee/set")
    @Operation(summary = "业务节点设置审批人，不支持重复调用设置审批人，需一次性传入所有审批人")
    @InvokeMode(SYNC)
    CommonResponse<Boolean> setAssignee(@Validated @RequestBody BpmnActivitySetAssigneeDTO dto);

    /**
     * 该功能应该利用引擎的 TimerBoundaryEvent 来实现，但为了简便，先利用引擎的任务调度来实现
     *
     * @return
     */
    @PostMapping("/api/process/activity/timeout/trigger")
    @Operation(summary = "设置指定业务节点定时继续往下执行")
    @InvokeMode(SYNC)
    CommonResponse<Boolean> setTimeoutTrigger(@Validated @RequestBody BpmnActivityTimeoutTriggerDTO dto);

    /**
     * 为指定业务节点设置定时回调
     *
     * @return
     */
    @PostMapping("/api/process/activity/timeout/callback")
    @Operation(summary = "设置指定业务节点定时回调")
    @InvokeMode(SYNC)
    CommonResponse<Boolean> setTimeoutCallback(@Validated @RequestBody BpmnActivityTimeoutCallbackDTO dto);
}
