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

import cn.hutool.core.util.ObjectUtil;
import com.sjyt.icom.asst.common.enums.RoomEnum;
import com.sjyt.icom.asst.common.model.room.OneToOneRoom;
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;

import java.util.Optional;

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

    @Override
    public AbsRoom doChain(String roomCode) {
        return Optional.ofNullable(roomCode).filter(RoomEnum.ONE2ONE.CODE::equals).map(it -> {
            AbsRoom room = null;
            try {
                room = oneRoomPool.borrowObject();
            } catch (Exception e) {
                log.error("房间创建失败：{}", e.getMessage());
            }
            return room;
        }).orElseGet(() -> handle.doChain(roomCode));
    }
}
