import { Injectable } from '@angular/core';
import {
  ActivatedRouteSnapshot,
  Resolve,
  Router,
  RouterStateSnapshot,
} from '@angular/router';
import { catchError, Observable, throwError } from 'rxjs';

import { GameService } from '../services/game.service';

@Injectable({
  providedIn: 'root',
})
export class GameResolver implements Resolve<any> {
  /**
   * Constructor
   */
  constructor(private _gameService: GameService) {}

  // -----------------------------------------------------------------------------------------------------
  // @ Public methods
  // -----------------------------------------------------------------------------------------------------

  /**
   * Resolver
   *
   * @param route
   * @param state
   */
  resolve(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ): Observable<{
    gameSetting: any;
  }> {
    return this._gameService.getGameSetting();
  }
}
