import Video from './class.video';

global._videoList = global._videoList || {};

const videoList = global._videoList;

const videoManager = {
	register(videoId, cpn, attrs) {
		if (videoList[videoId]) {
			if (process.env !== 'prodcution') {
				console.warn(`Video id: ${videoId} has been registered.`);
			}
			return videoList[videoId];
		}

		videoList[videoId] = new Video(videoId, cpn, attrs);

		return videoList[videoId];
	},
	unRegister(videoId) {
		videoList[videoId] = null;
		delete videoList[videoId];
	},
	getVideoById(videoId) {
		return videoList[videoId] || null;
	}
};

export default videoManager;
