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.workflow.api.entity.design.Model;
import cn.stylefeng.workflow.api.pojo.config.node.button.NodeButtonPermission;
import cn.stylefeng.workflow.design.api.pojo.BusinessCategoryVo;
import cn.stylefeng.workflow.design.modular.pojo.FlowDefinitionFormVo;
import cn.stylefeng.workflow.design.modular.pojo.request.DefinitionRequest;
import cn.stylefeng.workflow.design.modular.pojo.request.StartPageRequest;
import cn.stylefeng.workflow.design.modular.service.StartPageService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@ApiResource(name = "流程发起界面的接口")
public class FlowStartPageController {

    @Resource
    private StartPageService startPageService;

    @GetResource(name = "获取用户的所有流程模型列表", path = "/flowModel/getUserModelList")
    public ResponseData<List<BusinessCategoryVo>> getUserModelList(StartPageRequest startPageRequest) {
        return new SuccessResponseData<>(startPageService.getUserModelList(startPageRequest));
    }

    @GetResource(name = "获取流程发起界面的表单设计信息", path = "/getFlowDefinitionFormConfig")
    public ResponseData<FlowDefinitionFormVo> getFlowDefinitionFormConfig(
            @Validated(BaseRequest.detail.class) DefinitionRequest definitionRequest) {
        FlowDefinitionFormVo flowDefinitionFormVo = startPageService.getFlowDefinitionFormConfig(definitionRequest);
        return new SuccessResponseData<>(flowDefinitionFormVo);
    }

    @GetResource(name = "获取指定流程定义下，发起人可以操作的按钮权限", path = "/startPage/getApplicantButtonPermission")
    public ResponseData<NodeButtonPermission> getApplicantButtonPermission(
            @Validated(BaseRequest.detail.class) DefinitionRequest definitionRequest) {
        NodeButtonPermission nodeButtonPermission = startPageService.getApplicantButtonPermission(definitionRequest);
        return new SuccessResponseData<>(nodeButtonPermission);
    }

    @GetResource(name = "获取平铺的用户所有流程模型列表", path = "/flowModel/getUserModelList/flat")
    public ResponseData<List<Model>> getUserModelListFlat() {
        return new SuccessResponseData<>(startPageService.getUserModelListFlat());
    }

}
