package com.sjyt.icom.asst.context.handle.room;

import com.sjyt.icom.asst.common.enums.RoomEnum;
import com.sjyt.icom.asst.common.model.room.MeetRoom;
import com.sjyt.icom.asst.common.model.room.AbsRoom;
import com.sjyt.icom.asst.context.pools.MeetRoomPool;
import com.sjyt.icom.asst.context.pools.One2OneRoomPool;
import com.sjyt.icom.asst.service.impl.RoomManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: Tab
 * @date: 2022-06-26 17:25
 * @since 1.0.0
 */
@Slf4j
@Component
public class RoomFactoryMeetHandle extends RoomFactoryHandle{
    @Autowired
    public RoomFactoryMeetHandle(RoomManageService roomManage, One2OneRoomPool oneRoomPool, MeetRoomPool meetRoomPool) {
        super(roomManage, oneRoomPool, meetRoomPool);
    }

    @Override
    public AbsRoom doChain(RoomFactoryEvent event) {
        if (event.getRoomEnum().equals(RoomEnum.MEET)){
            final MeetRoom meetRoom;
            try {
                meetRoom = meetRoomPool.borrowObject();
            } catch (Exception e) {
                log.error("房间创建失败：{}",e.getMessage());
                return null;
            }
            //todo 二期
            roomManage.addRoom(meetRoom);
            return meetRoom;
        }
        return handle.doChain(event);
    }
}
