package com.red.circle.other.app.command.party3rd.callback.trtc;

import com.red.circle.external.inner.model.callback.trtc.TrtcCallbackEvent;
import com.red.circle.other.app.common.live.OnlineRoomCommon;
import com.red.circle.other.infra.database.cache.service.other.RoomManagerCacheService;
import com.red.circle.other.infra.database.mongo.service.live.ActiveVoiceRoomService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 进入房间.
 *
 * @author pengliang on 2021/7/24
 */
@Slf4j
@Component("EVENT_TYPE_ENTER_ROOM")
@RequiredArgsConstructor
public class EnterRoomCallbackStrategy implements TrtcCallbackStrategy {

  private final OnlineRoomCommon onlineRoomCommon;
  private final ActiveVoiceRoomService activeVoiceRoomService;
  private final RoomManagerCacheService roomManagerCacheService;

  @Override
  public void doOperation(TrtcCallbackEvent event) {
    if (activeVoiceRoomService.existsByRoomAccount(event.getRoomId())) {
      activeVoiceRoomService.updateQuantityByRoomAccount(event.getRoomId(),
          roomManagerCacheService.incrementNumberPeople(event.getRoomId()));
      return;
    }
    onlineRoomCommon.addOnlineRoomByAccount(event.getRoomId());
  }


}
