package com.xindazhou.framework.common.biz.system.permission;

import com.xindazhou.framework.common.biz.system.permission.dto.DeptDataPermissionRespDTO;
import com.xindazhou.framework.common.enums.RpcConstants;
import com.xindazhou.framework.common.pojo.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;


import java.util.Collection;
import java.util.Set;

@FeignClient(name = RpcConstants.SYSTEM_NAME, primary = false) // TODO hmy：fallbackFactory =

@Tag(name = "RPC 服务 - 权限")
public interface PermissionCommonApi {

    String PREFIX = RpcConstants.SYSTEM_PREFIX + "/permission";

    @GetMapping(PREFIX + "/has-any-permissions")
    @Operation(summary = "判断是否有权限，任一一个即可")
    @Parameters({
            @Parameter(name = "userId", description = "用户编号", example = "1", required = true),
            @Parameter(name = "permissions", description = "权限", example = "read,write", required = true)
    })
    CommonResult<Boolean> hasAnyPermissions(@RequestParam("userId") Long userId,
                                            @RequestParam("permissions") String... permissions);

    @GetMapping(PREFIX + "/has-any-roles")
    @Operation(summary = "判断是否有角色，任一一个即可")
    @Parameters({
            @Parameter(name = "userId", description = "用户编号", example = "1", required = true),
            @Parameter(name = "roles", description = "角色数组", example = "2", required = true)
    })
    CommonResult<Boolean> hasAnyRoles(@RequestParam("userId") Long userId,
                                      @RequestParam("roles") String... roles);

    @GetMapping(PREFIX + "/get-dept-data-permission")
    @Operation(summary = "获得登陆用户的部门数据权限")
    @Parameter(name = "userId", description = "用户编号", example = "2", required = true)
    CommonResult<DeptDataPermissionRespDTO> getDeptDataPermission(@RequestParam("userId") Long userId);

    @PostMapping(PREFIX + "/process-user-deleted")
    @Operation(summary = "处理用户删除时，删除关联授权数据")
    @Parameter(name = "userId", description = "用户编号", example = "1", required = true)
    CommonResult<Boolean> processUserDeleted(@RequestParam("userId") Long userId);

    @GetMapping(PREFIX + "/get-user-role-id-list-by-role-id")
    @Operation(summary = "获得拥有多个角色的用户编号集合")
    @Parameter(name = "roleIds", description = "角色编号集合", example = "1,2", required = true)
    CommonResult<Set<Long>> getUserRoleIdListByRoleId(@RequestParam("roleIds") Collection<Long> roleIds);

    @GetMapping(PREFIX + "/get-user-role-id-list-by-user-id")
    @Operation(summary = "获得用户拥有的角色编号集合")
    @Parameter(name = "userId", description = "用户编号", example = "1", required = true)
    CommonResult<Set<Long>> getUserRoleIdListByUserId(@RequestParam("userId") Long userId);

    @GetMapping(PREFIX + "/get-role-menu-list-by-role-id")
    @Operation(summary = "获得角色拥有的菜单编号集合")
    @Parameter(name = "roleIds", description = "角色编号集合", example = "1,2", required = true)
    CommonResult<Set<Long>> getRoleMenuListByRoleId(@RequestParam("roleIds") Collection<Long> roleIds);

    @PostMapping(PREFIX + "/assign-user-role")
    @Operation(summary = "分配用户角色")
    @Parameter(name = "userId", description = "用户编号", example = "1", required = true)
    @Parameter(name = "roleIds", description = "角色编号集合", example = "1,2", required = true)
    CommonResult<Boolean> assignUserRole(@RequestParam("userId") Long userId, @RequestParam("roleIds") Set<Long> roleIds);

    @PostMapping(PREFIX + "/assign-role-menu")
    @Operation(summary = "分配角色菜单")
    @Parameter(name = "roleId", description = "角色编号", example = "1", required = true)
    @Parameter(name = "menuIds", description = "菜单编号集合", example = "1,2", required = true)
    CommonResult<Boolean> assignRoleMenu(@RequestParam("roleId") Long roleId, @RequestParam("menuIds") Set<Long> menuIds);

    @GetMapping(PREFIX + "/get-role-menu-list-by-single-role-id")
    @Operation(summary = "获得单个角色拥有的菜单编号集合")
    @Parameter(name = "roleId", description = "角色编号", example = "1", required = true)
    CommonResult<Set<Long>> getRoleMenuListBySingleRoleId(@RequestParam("roleId") Long roleId);

}