package com.red.circle.other.app.command.room.query;

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.dto.clientobject.room.RoomMikeTypeCO;
import com.red.circle.other.infra.database.rds.entity.live.RoomMikeType;
import com.red.circle.other.infra.database.rds.service.live.RoomMikeTypeService;
import com.red.circle.tool.core.collection.CollectionUtils;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 查询活动房间麦类型
 *
 * @author zongpubin on 2023/3/27 18:09
 */
@Component
@RequiredArgsConstructor
public class RoomMikeTypeQryExe {

  private final RoomMikeTypeService roomMikeTypeService;

  public List<RoomMikeTypeCO> execute(AppExtCommand cmd) {
    List<RoomMikeType> roomMikeTypes = getRoomMikeTypes(cmd);
    if (CollectionUtils.isEmpty(roomMikeTypes)) {
      return CollectionUtils.newArrayList();
    }
    return roomMikeTypes.stream().map(roomMikeType -> new RoomMikeTypeCO()
        .setId(roomMikeType.getId())
        .setUserId(roomMikeType.getUserId())
        .setMikeType(roomMikeType.getMikeType())
        .setSysOrigin(roomMikeType.getSysOrigin())
        .setExpireType(roomMikeType.getExpireType())
        .setExpireTime(roomMikeType.getExpireTime())
    ).filter(Objects::nonNull).collect(Collectors.toList());
  }

  private List<RoomMikeType> getRoomMikeTypes(AppExtCommand cmd) {
    return roomMikeTypeService
        .listByUserIdRoomMikeTypes(cmd.requiredReqUserId());
  }
}
