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.Model;
import cn.stylefeng.workflow.design.api.pojo.BusinessCategoryVo;
import cn.stylefeng.workflow.design.modular.pojo.request.ModelRequest;
import cn.stylefeng.workflow.design.modular.service.ModelService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@ApiResource(name = "流程模型")
public class ModelController {

    @Resource
    private ModelService modelService;

    @GetResource(name = "获取流程模型列表", path = "/flowModel/list")
    public ResponseData<List<BusinessCategoryVo>> list(ModelRequest modelRequest) {
        return new SuccessResponseData<>(modelService.findList(modelRequest));
    }

    @GetResource(name = "查看流程模型详情", path = "/flowModel/detail")
    public ResponseData<Model> detail(@Validated(ModelRequest.detail.class) ModelRequest modelRequest) {
        return new SuccessResponseData<>(modelService.detail(modelRequest));
    }

    @PostResource(name = "添加模型", path = "/flowModel/add")
    public ResponseData<Model> add(@RequestBody @Validated(BaseRequest.add.class) ModelRequest modelRequest) {
        modelService.add(modelRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除模型", path = "/flowModel/delete")
    public ResponseData<?> delete(@RequestBody @Validated(ModelRequest.delete.class) ModelRequest modelRequest) {
        modelService.del(modelRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑", path = "/flowModel/edit")
    public ResponseData<?> edit(@RequestBody @Validated(ModelRequest.edit.class) ModelRequest modelRequest) {
        modelService.edit(modelRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "复制模型", path = "/flowModel/copy")
    public ResponseData<?> copy(@Validated(ModelRequest.detail.class) ModelRequest modelRequest) {
        modelService.copy(modelRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "获取流程定义下拉列表", path = "/model/getDefinitionSelectList")
    public ResponseData<List<Model>> getDefinitionSelectList(ModelRequest modelRequest) {
        List<Model> definitionSelectList = modelService.getDefinitionSelectList(modelRequest);
        return new SuccessResponseData<>(definitionSelectList);
    }

}
