package cn.stylefeng.workflow.design.modular.controller;

import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.workflow.design.modular.pojo.request.NodeConditionRequest;
import cn.stylefeng.workflow.rule.api.ExpressionEngineApi;
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 = "流程条件配置控制器")
public class NodeConditionController {

    @Resource
    private ExpressionEngineApi expressionEngineApi;

    @PostResource(name = "校验条件表达式是否正确", path = "/nodeConditionGroup/validateExpression")
    public ResponseData<?> validateExpression(
            @RequestBody @Validated(NodeConditionRequest.validateExpression.class) NodeConditionRequest nodeConditionRequest) {
        return expressionEngineApi.validateExpression(nodeConditionRequest.getExpressionString());
    }

}
