package cn.stylefeng.workflow.instance.modular.auth.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.auth.entity.FlowAuth;
import cn.stylefeng.workflow.instance.modular.auth.pojo.request.FlowAuthRequest;
import cn.stylefeng.workflow.instance.modular.auth.service.FlowAuthService;
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 FlowAuthController {

    @Resource
    private FlowAuthService flowAuthService;

    @PostResource(name = "添加流程权限", path = "/flowAuth/add")
    public ResponseData<FlowAuth> add(@RequestBody @Validated(FlowAuthRequest.add.class) FlowAuthRequest flowAuthRequest) {
        flowAuthService.add(flowAuthRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除流程权限", path = "/flowAuth/delete")
    public ResponseData<?> delete(@RequestBody @Validated(FlowAuthRequest.delete.class) FlowAuthRequest flowAuthRequest) {
        flowAuthService.del(flowAuthRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除流程权限", path = "/flowAuth/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) FlowAuthRequest flowAuthRequest) {
        flowAuthService.batchDelete(flowAuthRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "获取流程权限列表（带分页）", path = "/flowAuth/page")
    public ResponseData<PageResult<FlowAuth>> page(FlowAuthRequest flowAuthRequest) {
        return new SuccessResponseData<>(flowAuthService.findPage(flowAuthRequest));
    }

}
