package cn.ey.biz.module.system.api.permission;

import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.api.permission.dto.CodeBlockDataPermissionRespDTO;
import cn.ey.biz.module.system.api.permission.dto.DeptDataPermissionRespDTO;
import cn.ey.biz.module.system.api.user.dto.AdminUserRespDTO;
import cn.ey.biz.module.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

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

@FeignClient(name = ApiConstants.NAME)
@Api(tags = "RPC 服务 - 权限")
public interface PermissionApi {

    String PREFIX = ApiConstants.PREFIX + "/permission";

    @GetMapping(PREFIX + "/user-role-id-list-by-role-id")
    @ApiOperation("获得拥有多个角色的用户编号集合")
    @ApiImplicitParam(name = "roleIds", value = "角色编号集合", example = "1,2", required = true, allowMultiple = true)
    R<Set<Long>> getUserRoleIdListByRoleIds(@RequestParam("roleIds") Collection<Long> roleIds);

    @GetMapping(PREFIX + "/has-any-permissions")
    @ApiOperation("判断是否有权限，任一一个即可")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户编号", example = "1", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "permissions", value = "权限", example = "read,write", required = true, allowMultiple = true)
    })
    R<Boolean> hasAnyPermissions(@RequestParam("userId") Long userId,
                                 @RequestParam("permissions") String... permissions);

    @GetMapping(PREFIX + "/has-any-permissions/app")
    @ApiOperation("判断是否有权限，任一一个即可")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户编号", example = "1", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "app", value = "应用编号", example = "1", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "permissions", value = "权限", example = "read,write", required = true, allowMultiple = true)
    })
    R<Boolean> hasAnyPermissions(@RequestParam("userId") Long userId,
                                 @RequestParam("app") String app,
                                 @RequestParam("permissions") String... permissions);

    @GetMapping(PREFIX + "/has-any-roles")
    @ApiOperation("判断是否有角色，任一一个即可")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户编号", example = "1", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "roles", value = "角色数组", example = "2", required = true, allowMultiple = true)
    })
    R<Boolean> hasAnyRoles(@RequestParam("userId") Long userId,
                           @RequestParam("roles") String... roles);

    @GetMapping(PREFIX + "/get-dept-data-permission")
    @ApiOperation("获得登陆用户的部门数据权限")
    @ApiImplicitParam(name = "userId", value = "用户编号", example = "2", required = true, dataTypeClass = Long.class)
    R<DeptDataPermissionRespDTO> getDeptDataPermission(@RequestParam("userId") Long userId);

    @GetMapping(PREFIX + "/get-code-block-data-permission/multi")
    @ApiOperation("获得登陆用户的code block数据权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户编号", example = "1", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "gpn", value = "用户编码", example = "2", dataTypeClass = String.class)
    })
    R<CodeBlockDataPermissionRespDTO> getCodeBlockDataPermission(@RequestParam(required = false, name="userId") Long userId, @RequestParam(required = false, name="gpn") String gpn);

    @GetMapping(PREFIX + "/get-code-block-data-permission")
    @ApiOperation("获得登陆用户的code block数据权限")
    @ApiImplicitParam(name = "userId", value = "用户编号", example = "2", required = true, dataTypeClass = Long.class)
    R<CodeBlockDataPermissionRespDTO> getCodeBlockDataPermission(@RequestParam("userId") Long userId);

    @GetMapping(PREFIX + "/users-by-role")
    @ApiOperation("根据角色ID获取用户")
    @ApiImplicitParam(name = "roleId", value = "角色编号", example = "2", required = true, dataTypeClass = Long.class)
    R<List<AdminUserRespDTO>> getUsersByRole(@RequestParam("roleId") Long roleId);

    @GetMapping(PREFIX + "/users-by-role-code")
    @ApiOperation("根据角色Code获取用户")
    @ApiImplicitParam(name = "code", value = "角色code", example = "2", required = true, dataTypeClass = String.class)
    R<List<AdminUserRespDTO>> getUsersByRoleCode(@RequestParam("code") String code);

}
