package com.red.circle.other.adapter.app.sys;


import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.sys.OauthAccessTokenCO;
import com.red.circle.other.app.dto.cmd.sys.OauthCertificateCmd;
import com.red.circle.other.app.service.sys.OauthService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 系统oauth 前端控制器.
 * </p>
 *
 * @author pengshigang
 * @eo.api-type http
 * @eo.groupName 系统服务.系统Oauth
 * @eo.path /oauth
 * @since 2022-05-10
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/oauth")
public class OauthRestController extends BaseController {

  private final OauthService oauthService;

  /**
   * 登录.
   *
   * @return OauthAccessTokenCO
   * @eo.name 登录
   * @eo.url /login
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/login")
  public OauthAccessTokenCO login(@RequestBody @Validated OauthCertificateCmd cmd) {
    return oauthService.login(cmd);
  }

  /**
   * 刷新令牌.
   *
   * @return OauthAccessTokenCO
   * @eo.name 刷新令牌
   * @eo.url /reset-if-absent
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/reset-if-absent")
  public OauthAccessTokenCO resetIfAbsent(@RequestBody @Validated OauthCertificateCmd cmd) {
    return oauthService.resetIfAbsent(cmd);
  }

}
