<commit_before>'use strict';

const Table = require('cli-table');
const thegamesdb = require('thegamesdb');
const gcdb = require('gamecollection-mongodb');
const utils = require('./utils');

module.exports = {
	getCollection: async () => {
		const result = await gcdb.getGames();

		let table = new Table({
			head: ['Title', 'Platform'],
			colWidths: [60, 40]
		});

		result.forEach((currentValue) => {
			table.push([currentValue.title, currentValue.platform]);
		});

		console.log(table.toString());
		utils.calculateGames(result);
	},
	getCollectionPerPlatform: async () => {
		const result = await gcdb.getGamesPerPlatform();
		let table;

		result.forEach((currentValue) => {
			table = new Table({
				head: [currentValue.platform],
				colWidths: [100]
			});

			currentValue.games.forEach((game) => {
				table.push([game.title]);
			});

			table.push([`Total: ${currentValue.games.length} games`]);
			console.log(table.toString());
		});
	},
	addGame: async (game) => {
		if (game !== undefined) {
			const thegamesdbResult = await thegamesdb.getGamesList({
				name: utils.multipleWordsInput(process.argv)
			});

			if (thegamesdbResult.length > 0) {
				const choices = thegamesdbResult.map(item => {
					return {
						name: `${item.title} | ${item.platform}`,
						value: item.id
					};
				});

				const addGamesDialog = await utils.dialog('checkbox', 'Select games to add:', 'gameIDs', choices, 10, 'You must choose at least one game');
				const addGamesConfirmDialog = await utils.dialog('confirm', 'Add selected game(s)?:', 'isAdding');

				if (addGamesConfirmDialog.isAdding) {
					for (const gameID of addGamesDialog.gameIDs) {
						let gameInformation = await thegamesdb.getGame({ id: gameID });
						await gcdb.addGame(gameInformation);
						utils.gameAdded(gameInformation.title);
					}
				}
			}
			else {
				utils.noGamesFound();
			}
		}
		else {
			utils.pleaseEnterName();
		}
	},
	removeGame: async (game) => {
		if (game !== undefined) {
			const query = {
				title: utils.multipleWordsInput(process.argv)
			};

			const filteredGames = await gcdb.getGames(query);

			if (filteredGames.length > 0) {
				const choices = filteredGames.map(item => {
					return {
						name: `${item.title} | ${item.platform}`,
						value: item._id
					};
				});

				const removeGamesDialog = await utils.dialog('checkbox', 'Remove a game:', 'removeGame', choices, 10, 'You must choose at least one game');
				const removeGamesConfirmDialog = await utils.dialog('confirm', 'Remove selected game(s)?:', 'isRemoving');

				if (removeGamesConfirmDialog.isRemoving) {
					for (const gameID of removeGamesDialog.removeGame) {
						let gameToBeRemoved = await gcdb.getGame(gameID);
						await gcdb.deleteGame(gameID);
						utils.gameRemoved(gameToBeRemoved.title);
					}
				}
			}
			else {
				utils.noGamesFound();
			}
		}
		else {
			utils.pleaseEnterName();
		}
	}
};<commit_msg>Integrate labels, code cleanup<commit_after>'use strict';

const Table = require('cli-table');
const thegamesdb = require('thegamesdb');
const gcdb = require('gamecollection-mongodb');
const labels = require('./labels');
const utils = require('./utils');

module.exports = {
	getCollection: async () => {
		const result = await gcdb.getGames();

		let table = new Table({
			head: labels.collectionTableHeader,
			colWidths: [60, 40]
		});

		result.forEach((currentValue) => {
			table.push([currentValue.title, currentValue.platform]);
		});

		console.log(table.toString());
		utils.calculateGames(result);
	},
	getCollectionPerPlatform: async () => {
		const result = await gcdb.getGamesPerPlatform();
		let table;

		result.forEach((currentValue) => {
			table = new Table({
				head: [currentValue.platform],
				colWidths: [100]
			});

			currentValue.games.forEach((game) => {
				table.push([game.title]);
			});

			table.push([labels.calculateGames(currentValue.games.length)]);
			console.log(table.toString());
		});
	},
	addGame: async (game) => {
		const thegamesdbResult = await thegamesdb.getGamesList({
			name: game
		});

		if (thegamesdbResult.length) {
			const choices = thegamesdbResult.map(item => {
				return {
					name: `${item.title} | ${item.platform}`,
					value: item.id
				};
			});

			const addGamesDialog = await utils.dialog('checkbox', labels.dialog.add.title, 'gameIDs', choices, 10, labels.dialog.add.validationMessage);
			const addGamesConfirmDialog = await utils.dialog('confirm', labels.dialog.add.comfirmTitle, 'isAdding');

			if (addGamesConfirmDialog.isAdding) {
				for (const gameID of addGamesDialog.gameIDs) {
					let gameInformation = await thegamesdb.getGame({ id: gameID });
					await gcdb.addGame(gameInformation);
					utils.gameAdded(gameInformation.title);
				}
			}
		}
		else {
			utils.noGamesFound();
		}
	},
	removeGame: async (game) => {
		const query = {
			title: game
		};

		const filteredGames = await gcdb.getGames(query);

		if (filteredGames.length) {
			const choices = filteredGames.map(item => {
				return {
					name: `${item.title} | ${item.platform}`,
					value: item._id
				};
			});

			const removeGamesDialog = await utils.dialog('checkbox', labels.dialog.remove.title, 'removeGame', choices, 10, labels.dialog.remove.validationMessage);
			const removeGamesConfirmDialog = await utils.dialog('confirm', labels.dialog.remove.comfirmTitle, 'isRemoving');

			if (removeGamesConfirmDialog.isRemoving) {
				for (const gameID of removeGamesDialog.removeGame) {
					let gameToBeRemoved = await gcdb.getGame(gameID);
					await gcdb.deleteGame(gameID);
					utils.gameRemoved(gameToBeRemoved.title);
				}
			}
		}
		else {
			utils.noGamesFound();
		}
	}
};
{'fraction_non_alphanumeric': 0.15021156558533144, 'fraction_numerical': 0.004231311706629055, 'mean_word_length': 3.6461916461916464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '541013', 'n_tokens_mistral': 2235, 'n_tokens_neox': 1823, 'n_words': 364}