package com.seer.teach.user.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.user.admin.request.RoleAuthorityReq;
import com.seer.teach.user.admin.response.AuthorityResp;
import com.seer.teach.user.admin.service.AdminRoleAuthorityService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 嘉多宝宝
 * @Data: 2025-07-02 13:44
 */
@RestController
@RequestMapping("/user/role/authority")
@Tag(name = "管理端 - 角色权限管理")
@Validated
@SaCheckLogin(type = StpUtil.TYPE)
@RequiredArgsConstructor
public class AdminRoleAuthorityController {

    private final AdminRoleAuthorityService roleAuthorityService;

    @PostMapping("/createRoleAuthority")
    @LogPrint
    @Operation(summary = "添加角色权限")
    @SaCheckPermission("admin:role:authority:create")
    public ResultBean createRoleAuthority(@RequestBody @Validated RoleAuthorityReq params){
        roleAuthorityService.addRoleAuthority(params);
        return ResultBean.success();
    }

    @DeleteMapping("/deleteRoleAuthority")
    @LogPrint
    @Operation(summary = "删除角色对应的权限")
    @SaCheckPermission("admin:role:authority:delete")
    public ResultBean deleteRoleAuthority(@RequestBody @Validated RoleAuthorityReq params){
        roleAuthorityService.deleteRoleAuthority(params);
        return ResultBean.success();
    }

    @GetMapping("/{roleId}")
    @LogPrint
    @Operation(summary = "根据角色Id查询权限列表")
    @SaCheckPermission("admin:role:authority:list")
    public ResultBean<List<AuthorityResp>> getAuthorityListByRoleId(@PathVariable("roleId") Integer roleId){
        return ResultBean.success(roleAuthorityService.getAuthorityListByRoleId(roleId));
    }
}