package com.sjyt.icom.asst.context.pools;

import com.sjyt.icom.asst.common.model.room.MeetRoom;
import com.sjyt.icom.asst.common.enums.RoomEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.DefaultPooledObject;

/**
 * <p>会议房间</p>
 *
 * @author renyanru
 * @version V1.0.0
 * @date 2022/6/16 14:21
 */
@Slf4j
public class MeetRoomFactory implements PooledObjectFactory<MeetRoom> {
    @Override
    public void activateObject(PooledObject<MeetRoom> pooledObject) throws Exception {
        MeetRoom object = pooledObject.getObject();
        object.setActive(true);
    }

    @Override
    public void destroyObject(PooledObject<MeetRoom> pooledObject) throws Exception {
        MeetRoom object = pooledObject.getObject();
        object.destroy();
    }

    @Override
    public PooledObject<MeetRoom> makeObject() throws Exception {
        MeetRoom object=new MeetRoom();
        log.info("构建会议房间对象,房间类型为：{}", RoomEnum.of(object.getType()));
        return new DefaultPooledObject<>(object);
    }

    @Override
    public void passivateObject(PooledObject<MeetRoom> pooledObject) throws Exception {
        MeetRoom object = pooledObject.getObject();
        object.setRid(null);
        object.getExtraInfos().clear();
    }

    @Override
    public boolean validateObject(PooledObject<MeetRoom> pooledObject) {
        MeetRoom object = pooledObject.getObject();
        return object.isActive();
    }
}
