import {Injectable} from '@angular/core';
import {RandomGameService, RandomGameState, RandomGameStatus} from './random-game/random-game.service';
import {filter, map} from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class InfoMessagesService {

  infos$ = this.randomGameService.state$.pipe(
    map(s => this.convertToMessage(s)),
    filter(s => !!s),
  );

  constructor(private randomGameService: RandomGameService) {

  }

  private convertToMessage(s: RandomGameState): string | null {
    switch (s.status) {
      case RandomGameStatus.WaitingForPartnerRegistration:
        return `I started a game ${s.gameId} join me!`;
      case RandomGameStatus.FinishedAsWinner:
        return `I won!!!`;
      case RandomGameStatus.FinishedAsLooser:
        return `Oh no, I loosed...`;
    }
  }
}
