{"size": 830, "ext": "js", "max_stars_repo_path": "server/deploychatbot/commands/games/masoi/poll/Item.js", "max_stars_repo_name": "linhheu/kb2abot", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/deploychatbot/commands/games/masoi/poll/Item.js", "max_issues_repo_name": "linhheu/kb2abot", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/deploychatbot/commands/games/masoi/poll/Item.js", "max_forks_repo_name": "linhheu/kb2abot", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 18.4444444444, "max_line_length": 64, "alphanum_fraction": 0.6313253012}
import Manager from "../../../../../roles/Manager.js";

class Item extends Manager {
	constructor({
		id,
		name
	} = {}) {
		super();
		this.id = id;
		this.name = name;
	}

	getAmount() {
		return this.items.length;
	}

	find(participant, returnParticipant = false, autoAdd = false) {
		let index = this.items.indexOf(participant);
		if (index == -1 && autoAdd) {
			this.add(participant, false);
			index = this.find(participant);
		}

		if (returnParticipant) {
			return this.items[index];
		}
		return index;
	}

	add(participant, duplicateCheck = true) {
		if (duplicateCheck) {
			const index = this.find(participant);
			if (index == -1) {
				this.items.push(participant);
				return this.bottom();
			}
			return this.items[index];
		}
		this.items.push(participant);
		return this.bottom();
	}
}

export default Item;
