import { Client } from "../client.js"; class Tourmanent { /** * @param {Client} client */ constructor(client, name = undefined, nb_players = undefined, nb_players_by_game = undefined, level = undefined, started = undefined, finished = undefined, levels = undefined, id = undefined) { /** * @type {Client} */ this.client = client; this.name = name; this.nb_players = nb_players; this.nb_players_by_game = nb_players_by_game; this.level = level; this.started = started; this.finished = finished; this.levels = levels; this.state = this.get_state(); this.id = id } get_state() { if (this.finished) return "finished"; if (this.started) return "started"; else return "waiting"; } async init(id) { let response = await this.client._get(`/api/tournaments/${id}`); if (response.status === 404) return null; let response_data = await response.json(); this.name = response_data.name; this.nb_players = response_data.nb_players; this.nb_players_by_game = response_data.nb_players_by_game; this.level = response_data.level; this.started = response_data.started; this.finished = response_data.finished; this.levels = response_data.levels; this.id = response_data.id } } export { Tourmanent }