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

import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
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.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.workflow.api.entity.design.Definition;
import cn.stylefeng.workflow.design.modular.pojo.request.DefinitionRequest;
import cn.stylefeng.workflow.design.modular.service.DefinitionService;
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 ModelDesignController {

    @Resource
    private DefinitionService definitionService;

    @GetResource(name = "查看流程设计的详情", path = "/flowDesign/detail")
    public ResponseData<Definition> detail(@Validated(BaseRequest.detail.class) DefinitionRequest definitionRequest) {
        return new SuccessResponseData<>(definitionService.detail(definitionRequest));
    }

    @PostResource(name = "保存流程设计", path = "/flowDesign/saveSixGraphDesign")
    public ResponseData<?> saveSixGraphDesign(@RequestBody @Validated(DefinitionRequest.save.class) DefinitionRequest definitionRequest) {
        definitionService.saveSixGraphDesign(definitionRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "升级并保存流程设计", path = "/flowDesign/upgradeAndSave")
    public ResponseData<Long> upgradeAndSave(
            @RequestBody @Validated(DefinitionRequest.upgradeAndSave.class) DefinitionRequest definitionRequest) {
        Long newDefinitionId = definitionService.upgradeAndSave(definitionRequest);
        return new SuccessResponseData<>(newDefinitionId);
    }

}
