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

import com.red.circle.common.business.dto.cmd.UserIdCmd;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.cmd.user.user.UserOnlineStatusUploadCmd;
import com.red.circle.other.app.service.user.user.UserOnlineService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 在线用户服务.
 *
 * @author pengliang on 2023/5/31
 * @eo.api-type http
 * @eo.groupName 用户服务.在线用户
 * @eo.path /user/online
 */
@Validated
@RestController
@RequestMapping(value = "/user/online", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class UserOnlineRestController extends BaseController {

  private final UserOnlineService userOnlineService;

  /**
   * 在线状态上传(使用/live/user/heartbeat).
   *
   * @eo.hidden
   * @eo.name 在线状态上传.
   * @eo.url /upload
   * @eo.method post
   * @eo.request-type json
   */
  @Deprecated
  @PostMapping("/upload")
  public void upload(@RequestBody @Validated UserOnlineStatusUploadCmd cmd) {
    userOnlineService.upload(cmd);
  }

  /**
   * 获取在线用户，房间会话id.
   *
   * @eo.name 获取在线用户，房间会话id.
   * @eo.url /session-id
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/session-id")
  public String getSessionId(@Validated UserIdCmd cmd) {
    return userOnlineService.getSessionId(cmd);
  }

}
