import { Injectable } from '@angular/core';
import {
  ActivatedRouteSnapshot,
  Resolve,
  Router,
  RouterStateSnapshot,
} from '@angular/router';
import { SiteService } from 'app/modules/polyglot/domain/services/site.service';
import { ListSitesResponse } from 'app/modules/protobuf/c2se/backend/site_pb';
import { catchError, Observable, throwError } from 'rxjs';

@Injectable({
  providedIn: 'root',
})
export class SiteResolver implements Resolve<any> {
  /**
   * Constructor
   */
  constructor(private __siteService: SiteService) {}

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

  /**
   * Resolver
   *
   * @param route
   * @param state
   */
  resolve(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ):
    | Observable<ListSitesResponse.Result>
    | Promise<ListSitesResponse.Result>
    | ListSitesResponse.Result {
    return this.__siteService.listSites();
  }
}
