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

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.red.circle.external.inner.model.callback.trtc.EventInfo;
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 org.junit.jupiter.api.Test;

class EnterRoomCallbackStrategyTest {

  @Test
  void doOperation_shouldUpdateOnlineQuantityWithIncrementedRoomUserSize() {
    OnlineRoomCommon onlineRoomCommon = mock(OnlineRoomCommon.class);
    ActiveVoiceRoomService activeVoiceRoomService = mock(ActiveVoiceRoomService.class);
    RoomManagerCacheService roomManagerCacheService = mock(RoomManagerCacheService.class);
    EnterRoomCallbackStrategy strategy = new EnterRoomCallbackStrategy(
        onlineRoomCommon,
        activeVoiceRoomService,
        roomManagerCacheService
    );

    TrtcCallbackEvent event = new TrtcCallbackEvent();
    EventInfo eventInfo = new EventInfo();
    eventInfo.setRoomId("123456");
    eventInfo.setUserId("9527");
    eventInfo.setEventTs("1710000000");
    event.setEventInfo(eventInfo);

    when(activeVoiceRoomService.existsByRoomAccount("123456")).thenReturn(true);
    when(roomManagerCacheService.incrementNumberPeople("123456")).thenReturn(6L);

    strategy.doOperation(event);

    verify(activeVoiceRoomService).updateQuantityByRoomAccount("123456", 6L);
    verify(onlineRoomCommon, never()).addOnlineRoomByAccount("123456");
  }
}
