package com.sckw.system.controller;

import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.system.model.vo.req.DataPermissionReqVo;
import com.sckw.system.service.KwsDataPermissionService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 数据权限配置
 *
 * @author system
 * @date 2026-03-26
 */
@RestController
@RequestMapping("/kwsDataPermission")
public class KwsDataPermissionController {

    @Autowired
    private KwsDataPermissionService kwsDataPermissionService;

    /**
     * 查询角色的数据权限配置
     *
     * @param roleId 角色ID
     */
    @GetMapping("/detail")
    public HttpResult detail(@RequestParam Long roleId) {
        return HttpResult.ok(kwsDataPermissionService.getDataPermission(roleId));
    }

    /**
     * 保存/更新角色数据权限
     */
    @PostMapping("/save")
    public HttpResult save(@Valid @RequestBody DataPermissionReqVo reqVo) {
        kwsDataPermissionService.saveDataPermission(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    /**
     * 查询数据权限企业树
     * 客户端：当前企业+下级企业
     * 平台端：所有入驻企业
     */
    @GetMapping("/entTree")
    public HttpResult entTree() {
        return HttpResult.ok(kwsDataPermissionService.getEntTree());
    }

}
