'use strict';
// Following contains all states definitions
// They all receive interface from duel controller as an argument (see stateCtrl in DuelController)
// They all must implement :
//  - start  : where it prepares the game data for this step and save it dor players
//  - update : where it waits for players inputs, save them
//  - end    : where it decides what should be next state
// Those 3 methods might receive a payload but not necessarily
// The state have also direct acces to game data

import initState from './0-initState.js';
import selectFactionState from './1-selectFactionState.js';
import selectDraftState from './1-selectDraftState.js';
import selectTournamentState from './1-selectTournamentState.js';
import changeUpTo3Cards from './2-changeUpTo3Cards.js';

const GameStates = function () {
  let states = new Map();
  states.set('0_INIT', initState);
  states.set('1_SELECT_FACTION', selectFactionState);
  states.set('1_SELECT_DRAFT', selectDraftState);
  states.set('1_SELECT_TOURNAMENT', selectTournamentState);
  states.set('2_CHANGE_UP_TO_3_CARDS', changeUpTo3Cards);
  this.createState = function (state, stateCtrl) {
    let stateFunc = states.get(state);
    if (stateFunc) {
      return new stateFunc(stateCtrl);
    } else {
      console.log('ERROR :>> This is state is unknown', state);
      return new initState(stateCtrl);
    }
  };
};

export default new GameStates();
