package com.red.circle.live.adapter.app;

import com.red.circle.common.business.dto.cmd.app.AppRoomIdCmd;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.live.app.dto.cmd.LiveMusicStatusCmd;
import com.red.circle.live.app.service.LiveRoomUserService;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
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;

import java.util.Map;
import java.util.Objects;

/**
 * 直播房间服务.
 *
 * @author pengliang on 2023/12/11
 * @eo.api-type http
 * @eo.groupName 直播服务.直播房间
 * @eo.path /live/room
 */
@Validated
@RestController
@RequestMapping(value = "/room", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class LiveRoomRestController extends BaseController {

  private final LiveRoomUserService liveRoomUserService;

  /**
   * 退出房间.
   *
   * @eo.name 退出房间.
   * @eo.url /quit
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/quit")
  public void quit(@Validated AppRoomIdCmd cmd) {
    liveRoomUserService.quitRoom(cmd);
  }

  /**
   * 音乐播放状态上传.
   *
   * @eo.name 音乐播放状态上传.
   * @eo.url /music/status
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/music/status")
  public String musicStatus(
      @RequestBody @Validated LiveMusicStatusCmd cmd) {
    return liveRoomUserService.musicStatus(cmd).get("roomToken").toString();
  }

  /**
   * 移除房间正在播放音乐用户.
   *
   * @eo.name 移除房间正在播放音乐用户.
   * @eo.url /music/remove
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/music/remove")
  public void removeMusic(AppRoomIdCmd cmd) {
    liveRoomUserService.removeMusic(cmd);
  }

  /**
   * 获取正在播放音乐用户.
   *
   * @eo.name 获取正在播放音乐用户.
   * @eo.url /music/user-profile
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/music/user-profile")
  public UserProfileDTO getMusicUserProfile(AppRoomIdCmd cmd) {
    return liveRoomUserService.getMusicUserProfile(cmd);
  }

}
