package cn.stylefeng.workflow.instance.modular.business.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.workflow.instance.modular.business.entity.BusinessLink;
import cn.stylefeng.workflow.instance.modular.business.pojo.request.BusinessLinkRequest;
import cn.stylefeng.workflow.instance.modular.business.service.BusinessLinkService;
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 BusinessLinkController {

    @Resource
    private BusinessLinkService businessLinkService;

    @PostResource(name = "添加流程和业务的关联", path = "/businessLink/add")
    public ResponseData<BusinessLink> add(@RequestBody @Validated(BusinessLinkRequest.add.class) BusinessLinkRequest businessLinkRequest) {
        businessLinkService.add(businessLinkRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除流程和业务的关联", path = "/businessLink/delete")
    public ResponseData<?> delete(@RequestBody @Validated(BusinessLinkRequest.delete.class) BusinessLinkRequest businessLinkRequest) {
        businessLinkService.del(businessLinkRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除流程和业务的关联", path = "/businessLink/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) BusinessLinkRequest businessLinkRequest) {
        businessLinkService.batchDelete(businessLinkRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑流程和业务的关联", path = "/businessLink/edit")
    public ResponseData<?> edit(@RequestBody @Validated(BusinessLinkRequest.edit.class) BusinessLinkRequest businessLinkRequest) {
        businessLinkService.edit(businessLinkRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看流程和业务的关联详情", path = "/businessLink/detail")
    public ResponseData<BusinessLink> detail(@Validated(BusinessLinkRequest.detail.class) BusinessLinkRequest businessLinkRequest) {
        return new SuccessResponseData<>(businessLinkService.detail(businessLinkRequest));
    }

    @GetResource(name = "获取流程和业务的关联列表（带分页）", path = "/businessLink/page")
    public ResponseData<PageResult<BusinessLink>> page(BusinessLinkRequest businessLinkRequest) {
        return new SuccessResponseData<>(businessLinkService.findPage(businessLinkRequest));
    }

}
