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

import { LadderService } from '../services/ladder.service';

@Injectable({
  providedIn: 'root',
})
export class LadderResolver implements Resolve<any> {
  /**
   * Constructor
   */
  constructor(private _ladderService: LadderService) {}

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

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