package cn.stylefeng.team.meta.modular.controller;

import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
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.team.meta.modular.entity.BusinessDiagram;
import cn.stylefeng.team.meta.modular.pojo.request.BusinessDiagramRequest;
import cn.stylefeng.team.meta.modular.service.BusinessDiagramService;
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 BusinessDiagramController {

    @Resource
    private BusinessDiagramService businessDiagramService;

    @PostResource(name = "添加业务流程图", path = "/businessDiagram/add")
    public ResponseData<BusinessDiagram> add(@RequestBody @Validated(BusinessDiagramRequest.add.class) BusinessDiagramRequest businessDiagramRequest) {
        BusinessDiagram businessDiagram = businessDiagramService.add(businessDiagramRequest);
        return new SuccessResponseData<>(businessDiagram);
    }

    @PostResource(name = "删除业务流程图", path = "/businessDiagram/delete")
    public ResponseData<?> delete(@RequestBody @Validated(BusinessDiagramRequest.delete.class) BusinessDiagramRequest businessDiagramRequest) {
        businessDiagramService.del(businessDiagramRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除业务流程图", path = "/businessDiagram/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) BusinessDiagramRequest businessDiagramRequest) {
        businessDiagramService.batchDelete(businessDiagramRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑业务流程图", path = "/businessDiagram/edit")
    public ResponseData<?> edit(@RequestBody @Validated(BusinessDiagramRequest.edit.class) BusinessDiagramRequest businessDiagramRequest) {
        businessDiagramService.edit(businessDiagramRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看业务流程图详情", path = "/businessDiagram/detail")
    public ResponseData<BusinessDiagram> detail(@Validated(BusinessDiagramRequest.detail.class) BusinessDiagramRequest businessDiagramRequest) {
        return new SuccessResponseData<>(businessDiagramService.detail(businessDiagramRequest));
    }

    @GetResource(name = "获取业务流程图列表（带分页）", path = "/businessDiagram/page")
    public ResponseData<PageResult<BusinessDiagram>> page(BusinessDiagramRequest businessDiagramRequest) {
        return new SuccessResponseData<>(businessDiagramService.findPage(businessDiagramRequest));
    }

    @GetResource(name = "获取项目下所有的业务图", path = "/businessDiagram/list")
    public ResponseData<List<BusinessDiagram>> list(BusinessDiagramRequest businessDiagramRequest) {
        return new SuccessResponseData<>(businessDiagramService.findList(businessDiagramRequest));
    }

}
