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.clientobject.LiveMicUserCO;
import com.red.circle.live.app.dto.cmd.HeartbeatUploadCmd;
import com.red.circle.live.app.service.LiveRoomUserService;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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/12/11
 * @eo.api-type http
 * @eo.groupName 直播服务.用户管理
 * @eo.path /live/user
 */
@Validated
@RestController
@RequestMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class LiveUserRestController extends BaseController {

  private final LiveRoomUserService liveRoomUserService;

  /**
   * 查询主播列表.
   *
   * @return List
   * @eo.name 查询主播列表
   * @eo.url /list
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/channel/host")
  public List<Long> channelHost(AppRoomIdCmd cmd) {
    return liveRoomUserService.channelHost(cmd);
  }

  /**
   * 在说话的用户列表.
   *
   * @return List
   * @eo.name 在说话的用户列表
   * @eo.url /list
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/speak/list")
  public List<LiveMicUserCO> listSpeakUser(AppRoomIdCmd cmd) {
    return liveRoomUserService.listSpeakUser(cmd);
  }

  /**
   * 在线用户列表.
   *
   * @return List
   * @eo.name 在线用户列表
   * @eo.url /list
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/list")
  public List<LiveMicUserCO> listUser(AppRoomIdCmd cmd) {
    return liveRoomUserService.listUser(cmd);
  }

  /**
   * 心跳.
   *
   * @eo.name 心跳.
   * @eo.url /heartbeat
   * @eo.method post
   * @eo.request-type formdata
   */
  @PostMapping("/heartbeat")
  public Map<String, Object> heartbeat(@RequestBody @Validated HeartbeatUploadCmd cmd) {
    liveRoomUserService.heartbeat(cmd);
    List<Long> userIds = Arrays.asList(1864916790666043393L, 1872476451722801154L);
    return new HashMap<>() {
      {
//        put("wallet", userIds.contains(cmd.getReqUserId()));
        put("wallet", true);
      }
    };
  }

}
