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.infra.database.cache.service.other.RoomManagerCacheService;
import com.red.circle.other.infra.database.mongo.service.live.ActiveVoiceRoomService;
import com.red.circle.tool.core.text.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 解散房间.
 *
 * @author pengliang on 2021/7/24
 */
@Slf4j
@Component("EVENT_TYPE_DISMISS_ROOM")
@RequiredArgsConstructor
public class DisbandRoomCallbackStrategy implements TrtcCallbackStrategy {

  private final ActiveVoiceRoomService activeVoiceRoomService;
  private final RoomManagerCacheService roomManagerCacheService;

  @Override
  public void doOperation(TrtcCallbackEvent event) {
    log.warn("解散房间：{}", event);
    if (StringUtils.isBlank(event.getRoomId())) {
      return;
    }
    activeVoiceRoomService.removeByRoomAccount(event.getRoomId());
    roomManagerCacheService.removeNumberPeople(event.getRoomId());
  }

}
