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

import cn.axzo.workflow.client.config.CommonFeignConfiguration;
import cn.axzo.workflow.common.model.request.bpmn.RestBpmnProcessVariable;
import cn.azxo.framework.common.model.CommonResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
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;

/**
 * 流程变量api
 */
@FeignClient(name = "workflow-engine", url = "${axzo.service.workflow-engine:http://workflow-engine:8080}", configuration = CommonFeignConfiguration.class)
public interface ProcessVariableApi {

    /**
     * 为指定流程新增变量
     */
    @PostMapping("/api/process/variable/create/{executionId}")
    CommonResponse<Void> createVariable(@PathVariable @NotBlank(message = "流程实例 ID 不能为空") String executionId,
                                        @RequestBody @Validated RestBpmnProcessVariable restVariable);

    /**
     * 仅更新流程已存在的变量
     *
     * @param executionId
     * @param restVariable
     * @return
     */
    @PostMapping("/api/process/variable/update/{executionId}")
    CommonResponse<Void> updateVariable(@PathVariable @NotBlank(message = "流程实例 ID 不能为空") String executionId,
                                        @RequestBody @Validated RestBpmnProcessVariable restVariable);

    /**
     * 批量删除流程变量
     */
    @DeleteMapping("/api/process/variable/delete/{executionId}")
    CommonResponse<Void> deleteVariables(@PathVariable("executionId") String executionId,
                                         @RequestParam String variableNames,
                                         @RequestParam(value = "scope", required = false) String scope);
}
