package org.wcs.serve.controller.app;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wcs.model.dto.serve.userGroup.AddUserGroupReq;
import org.wcs.model.dto.serve.userGroup.UpdateGroupPermissionReq;
import org.wcs.model.dto.serve.userGroup.UpdateUserGroupReq;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.vo.serve.AppServeResponse;
import org.wcs.model.vo.serve.userGroup.QueryOperationPermissionResp;
import org.wcs.model.vo.serve.userGroup.QueryUserGroupPermissionResp;
import org.wcs.model.vo.serve.userGroup.QueryUserGroupResp;
import org.wcs.serve.service.intf.IUserGroupService;

import java.util.List;

/**
 * 用户组相关操作
 */
@RestController
@RequestMapping("/app/userGroup")
@ResponseBody
@RequiredArgsConstructor
public class UserGroupController {

    private final IUserGroupService userGroupService;

    /**
     * 查找用户组级别比自己低的用户的用户组信息
     * @return 查询到的信息
     */
    @SaCheckPermission("userGroupManage:queryUserGroup")
    @GetMapping("/queryMinLevelUserGroup")
    public AppServeDataResponse<List<QueryUserGroupResp>> queryMinLevelUserGroup() {
        return userGroupService.queryMinLevelUserGroup();
    }

    /**
     * 查询某一用户组所拥有的菜单权限
     * @param userGroup 用户组
     * @return 查询结果
     */
    @GetMapping("/queryUserGroupPermission")
    public AppServeDataResponse<List<QueryUserGroupPermissionResp>> queryUserGroupPermission(@RequestParam("userGroup") @NotBlank(message = "用户组不能为空") String userGroup) {
        return userGroupService.queryUserGroupPermission(userGroup);
    }

    /**
     * 添加一个用户组
     * @param addUserGroupReq 新用户组信息
     * @return 添加结果
     */
    @SaCheckPermission("userGroupManage:addUserGroup")
    @PostMapping("/addUserGroup")
    public AppServeResponse addUserGroup(@RequestBody @Validated AddUserGroupReq addUserGroupReq) {
        return userGroupService.addUserGroup(addUserGroupReq);
    }

    /**
     * 删除用户组
     * @param userGroup 用户组
     * @return 结果
     */
    @SaCheckPermission("userGroupManage:deleteUserGroup")
    @DeleteMapping("/deleteUserGroup/{userGroup}")
    public AppServeResponse deleteUserGroup(@PathVariable @NotBlank(message = "用户组不能为空") String userGroup) {
        return userGroupService.deleteUserGroup(userGroup);
    }

    /**
     * 更新用户组信息
     * @param updateUserGroupReq 更新信息
     * @return 更新结果
     */
    @SaCheckPermission("userGroupManage:editUserGroup")
    @PostMapping("/updateUserGroup")
    public AppServeResponse updateUserGroup(@RequestBody @Validated UpdateUserGroupReq updateUserGroupReq) {
        return userGroupService.updateUserGroup(updateUserGroupReq);
    }

    /**
     * 更新用户组权限
     * @param updateGroupPermissionReq 更新权限信息
     * @return 更新结果
     */
    @SaCheckPermission("userGroupManage:editUserGroup")
    @PostMapping("/updateGroupPermission")
    public AppServeResponse updateGroupPermission(@RequestBody @Validated UpdateGroupPermissionReq updateGroupPermissionReq) {
        return userGroupService.updateGroupPermission(updateGroupPermissionReq);
    }

    /**
     * 添加用户组操作权限
     * @param updateGroupPermissionReq 添加权限信息
     * @return 添加结果
     */
    @SaCheckPermission("userGroupManage:editPermission")
    @PostMapping("/updateGroupOperationPermission")
    public AppServeResponse updateGroupOperationPermission(@RequestBody @Validated UpdateGroupPermissionReq updateGroupPermissionReq) {
        return userGroupService.updateGroupOperationPermission(updateGroupPermissionReq);
    }

    /**
     * 查询用户组操作权限
     * @param groupId 用户组id
     * @return 查询结果
     */
    @SaCheckPermission("userGroupManage:queryPermission")
    @GetMapping("/queryOperationPermission/{groupId}")
    public AppServeDataResponse<List<QueryOperationPermissionResp>> queryOperationPermission(@PathVariable @NotBlank(message = "用户组id不能为空") String groupId) {
        return userGroupService.queryOperationPermission(groupId);
    }





}
