package com.red.circle.live.app.command.user.qry;

import com.red.circle.common.business.dto.cmd.app.AppRoomIdCmd;
import com.red.circle.live.domain.live.LiveMusicStatus;
import com.red.circle.live.infra.database.cache.service.LiveMusicHeartbeatService;
import com.red.circle.other.inner.endpoint.user.user.UserProfileClient;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 获取播放音乐用户.
 *
 * @author pengliang on 2024/1/8
 */
@Component
@RequiredArgsConstructor
public class LiveMusicQryExe {

  private final UserProfileClient userProfileClient;
  private final LiveMusicHeartbeatService liveMusicHeartbeatService;

  public UserProfileDTO execute(AppRoomIdCmd cmd) {
    LiveMusicStatus liveMusicStatus = liveMusicHeartbeatService.getMusicUser(cmd.getRoomId());
    if (Objects.isNull(liveMusicStatus)) {
      return null;
    }
    return userProfileClient.getByUserId(liveMusicStatus.getUserId()).getBody();
  }
}
