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

import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.api.oauth2.dto.*;
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.*;

import javax.validation.Valid;

@FeignClient(name = ApiConstants.NAME)
@Api(tags = "RPC 服务 - OAuth2.0 令牌")
public interface OAuth2TokenApi {

    String PREFIX = ApiConstants.PREFIX + "/oauth2/token";

    /**
     * 校验 Token 的 URL 地址，主要是提供给 Gateway 使用
     */
    @SuppressWarnings("HttpUrlsUsage")
    String URL_CHECK = "http://" + ApiConstants.NAME + PREFIX + "/check";

    /**
     * 获取客户端 的 URL 地址，主要是提供给 Gateway 使用
     */
    @SuppressWarnings("HttpUrlsUsage")
    String URL_CLIENT = "http://" + ApiConstants.NAME + PREFIX + "/client";

    @PostMapping(PREFIX + "/create")
    @ApiOperation("创建访问令牌")
    R<OAuth2AccessTokenRespDTO> createAccessToken(@Valid @RequestBody OAuth2AccessTokenCreateReqDTO reqDTO);

    @PostMapping(PREFIX + "/client/create")
    @ApiOperation("创建访问令牌")
    R<OAuth2AccessTokenRespDTO> createClientAccessToken(@Valid @RequestBody OAuth2AccessTokenClientCreateReqDTO reqDTO);

    @GetMapping(PREFIX + "/client")
    @ApiOperation("获取客户端信息")
    @ApiImplicitParam(name = "clientId", value = "客户端编码", required = true, dataTypeClass = String.class, example = "tedt")
    R<OAuth2ClientRespDTO> getClient(@RequestParam("clientId") String clientId);

    @GetMapping(PREFIX + "/check")
    @ApiOperation("校验访问令牌")
    @ApiImplicitParam(name = "accessToken", value = "访问令牌", required = true, dataTypeClass = String.class, example = "testxxx")
    R<OAuth2AccessTokenCheckRespDTO> checkAccessToken(@RequestParam("accessToken") String accessToken);

    @DeleteMapping(PREFIX + "/remove")
    @ApiOperation("移除访问令牌")
    @ApiImplicitParam(name = "accessToken", value = "访问令牌", required = true, dataTypeClass = String.class, example = "tudou")
    R<OAuth2AccessTokenRespDTO> removeAccessToken(@RequestParam("accessToken") String accessToken);

    @PutMapping(PREFIX + "/refresh")
    @ApiOperation("刷新访问令牌")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "refreshToken", value = "刷新令牌", required = true, dataTypeClass = String.class, example = "haha"),
        @ApiImplicitParam(name = "clientId", value = "客户端编号", required = true, dataTypeClass = String.class, example = "xxx")
    })
    R<OAuth2AccessTokenRespDTO> refreshAccessToken(@RequestParam("refreshToken") String refreshToken,
                                                   @RequestParam("clientId") String clientId);

}
