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

import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.api.auth.dto.AuthMenuDTO;
import cn.ey.biz.module.system.api.auth.dto.AuthMenuDTOAndCodeBlock;
import cn.ey.biz.module.system.api.auth.dto.AuthPermissionInfoDTO;
import cn.ey.biz.module.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@FeignClient(name = ApiConstants.NAME)
@Api(tags = "RPC 服务 - 认证")
public interface AuthApi {

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

    @GetMapping(PREFIX + "/list-menus")
    @ApiOperation("查询当前用户菜单")
    R<List<AuthMenuDTO>> getMenus(@RequestParam("app") String app, @RequestParam("acceptLanguage") String acceptLanguage);

    @GetMapping(PREFIX + "/get-permission-info")
    @ApiOperation("获取登录用户的权限信息")
    R<AuthPermissionInfoDTO> getPermissionInfo(@RequestParam(name = "app", required = false) String app);

    @PostMapping(PREFIX + "/list-menus/codeblock")
    @ApiOperation("查询CodeBlock菜单")
    R<List<AuthMenuDTO>> getMenusByCodeBlock(@RequestParam("app") String app,
                                                         @RequestParam(name = "scene", defaultValue = "1") String scene,
                                                         @RequestParam("codeblock") String codeblock,
                                                         @RequestParam("acceptLanguage") String acceptLanguage,
                                                         @RequestBody(required = false)  Map<String, Object> dynamicAttr);

    @PostMapping(PREFIX + "/get-permission-info/codeblock")
    @ApiOperation("获取CodeBlock的权限信息")
    R<AuthPermissionInfoDTO> getPermissionInfoByCodeBlock(@RequestParam("app") String app,
                                                          @RequestParam(name = "scene", defaultValue = "1") String scene,
                                                          @RequestParam("codeblock") String codeblock,
                                                          @RequestBody(required = false) Map<String, Object> dynamicAttr);

    @PostMapping(PREFIX + "/list-menus/codeblockList")
    @ApiOperation("查询CodeBlockList菜单")
    R<List<AuthMenuDTOAndCodeBlock>> getMenusByCodeBlockList(@RequestParam("app") String app,
                                                         @RequestParam(name = "scene", defaultValue = "1") String scene,
                                                         @RequestParam("codeblocks") Collection<String> codeblocks,
                                                         @RequestParam("acceptLanguage") String acceptLanguage,
                                                         @RequestBody(required = false)  Map<String, Object> dynamicAttr);
}
