import _ from 'lodash' ; import { IGame , IGameData , IGameDataFull , ISelections } from '../interfaces/IGame' ; import { Selections } from './Selections' ; export class Game implements IGame { public static parse ( data ) { return new Game ( + data . id , data . state , data . winnerId , data . orderNum , Selections . parseArray ( data . selections ) ) ; } public static parseFull ( data ) { return data . set . games . map ( gameData => Game . parse ( gameData ) ) ; } private id : number | string ; private state : number ; private winnerId : number ; private orderNumber : number ; private selections : ISelections [ ] ; constructor ( id , state , winnerId , orderNumber , selections ) { this . id = id ; this . state = state ; this . winnerId = winnerId ; this . orderNumber = orderNumber ; this . selections = selections ; } public getId ( ) { return this . id ; } public getState ( ) { return this . state ; } public getWinnerId ( ) { return this . winnerId ; } public getOrderNumber ( ) { return this . orderNumber ; } public getSelections ( ) { return this . selections ; } public getSelectionsForEntrantId ( theEntrantId ) { return _ . find ( this . selections , { entrantId : theEntrantId } ) as ISelections | undefined ; } }