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

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.room.EntryRoomResponseCO;
import com.red.circle.other.app.dto.clientobject.room.RoomOnlineUserCO;
import com.red.circle.other.app.dto.clientobject.room.RoomVoiceProfileCO;
import com.red.circle.other.app.dto.cmd.room.RegionSearchRoomQryCmd;
import com.red.circle.other.app.dto.cmd.room.RoomEntryCmd;
import com.red.circle.other.app.dto.cmd.room.RoomOnlineUserFlowQryCmd;
import com.red.circle.other.app.dto.cmd.room.SearchRoomAccountCmd;
import com.red.circle.other.app.service.room.LiveVoiceRoomService;
import com.red.circle.other.inner.model.dto.live.RoomProfileDTO;
import java.util.List;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 直播语音房间 前端控制器.
 * </p>
 *
 * @author pengliang on 2020-12-01
 * @eo.api-type http
 * @eo.groupName 直播服务.语音房间
 * @eo.path /room/live-voice
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/room/live-voice", produces = MediaType.APPLICATION_JSON_VALUE)
public class LiveVoiceRoomRestController extends BaseController {

  private final LiveVoiceRoomService liveVoiceRoomService;

  /**
   * 创建房间.
   *
   * @eo.name 创建房间.
   * @eo.url /create
   * @eo.method post
   * @eo.request-type formdata
   */
  @PostMapping("/create")
  public RoomVoiceProfileCO create(AppExtCommand cmd) {
    return liveVoiceRoomService.create(cmd);
  }

  /**
   * Qibla创建公共房间.
   *
   * @eo.name 创建房间.
   * @eo.url /create
   * @eo.method post
   * @eo.request-type formdata
   */
  @PostMapping("/create-public-room")
  public String createPublicRoomByRegion(AppExtCommand cmd) {
    return liveVoiceRoomService.createPublicRoomByRegion(cmd);
  }

  /**
   * 进入房间.
   *
   * @eo.name 进入房间.
   * @eo.url /entry
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/entry")
  public EntryRoomResponseCO entry(@RequestBody @Validated RoomEntryCmd cmd) {
    return liveVoiceRoomService.entry(cmd);
  }

  /**
   * 搜索房间信息.
   *
   * @eo.name 搜索房间信息.
   * @eo.url /search
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/search")
  public List<RoomVoiceProfileCO> search(@Validated SearchRoomAccountCmd cmd) {
    return liveVoiceRoomService.searchRoomByRoomAccount(cmd);
  }

  /**
   * 房间在线用户列表.
   *
   * @eo.name 房间在线用户列表.
   * @eo.url /online/user
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/online/user")
  public List<RoomOnlineUserCO> roomOnlineUserFlow(@Validated RoomOnlineUserFlowQryCmd cmd) {
    return liveVoiceRoomService.flowOnlineUser(cmd);
  }

  /**
   * 区域房间列表.
   *
   * @eo.name 区域房间列表.
   * @eo.url /region/list
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/region/list")
  public List<RoomVoiceProfileCO> searchRegionRoom(RegionSearchRoomQryCmd qryCmd) {

    return liveVoiceRoomService.searchRegionRoom(qryCmd);
  }

  /**
   * 最近新创建的房间.
   *
   * @eo.name 最近新创建的房间.
   * @eo.url /latest-create
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/latest-create")
  public List<RoomVoiceProfileCO> listLatestCreate(AppExtCommand cmd) {
    return liveVoiceRoomService.listNowLatestCreate(cmd);
  }

  /**
   * 获取用户当前所在房间.
   *
   * @eo.name 获取用户当前所在房间.
   * @eo.url /current/location
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/current/location")
  public RoomProfileDTO getCurrentLocation(@Validated AppUserIdCmd cmd) {
    return liveVoiceRoomService.getCurrentLocation(cmd);
  }

  /**
   * 发现列表.
   *
   * @eo.name 发现列表.
   * @eo.url /discovery
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/discovery")
  public List<RoomVoiceProfileCO> discovery(AppExtCommand cmd) {
    return liveVoiceRoomService.discovery(cmd);
  }

}
