package cn.stylefeng.workflow.instance.modular.openapi.controller;

import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.workflow.api.entity.instance.RuntimeInstance;
import cn.stylefeng.workflow.instance.api.pojo.request.WorkflowStartRequest;
import cn.stylefeng.workflow.instance.modular.openapi.pojo.FinishOpenApiRequest;
import cn.stylefeng.workflow.instance.modular.openapi.pojo.UpdateVariablesApiRequest;
import cn.stylefeng.workflow.instance.modular.openapi.service.WorkflowOpenApiService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ApiResource(name = "流程控制独立的API")
public class WorkflowOpenApiController {

    @Resource
    private WorkflowOpenApiService workflowOpenApiService;

    @PostResource(name = "完成运行中节点", path = "/workflowOpenApi/finishNode", requiredLogin = false)
    public ResponseData<?> finishNode(@RequestBody @Validated FinishOpenApiRequest finishOpenApiRequest) {
        workflowOpenApiService.finishNode(finishOpenApiRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "发起流程接口", path = "/workflowOpenApi/startWorkflow", requiredLogin = false)
    public ResponseData<RuntimeInstance> startWorkflow(@RequestBody @Validated WorkflowStartRequest workflowStartRequest) {
        RuntimeInstance result = workflowOpenApiService.startWorkflow(workflowStartRequest);
        return new SuccessResponseData<>(result);
    }

    @PostResource(name = "更新流程实例的变量", path = "/workflowOpenApi/updateWorkflowVariable", requiredLogin = false)
    public ResponseData<?> updateWorkflowVariable(@RequestBody @Validated UpdateVariablesApiRequest updateVariablesApiRequest) {
        workflowOpenApiService.updateWorkflowVariable(updateVariablesApiRequest);
        return new SuccessResponseData<>();
    }

}
