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

import { IndexingService } from '../services/indexing.service';

@Injectable({
  providedIn: 'root',
})
export class IndexingResolver implements Resolve<any> {
  /**
   * Constructor
   */
  constructor(private _indexingService: IndexingService) {}

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

  /**
   * Resolver
   *
   * @param route
   * @param state
   */
  resolve(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ): Observable<void> {
    return this._indexingService.getIndexingSetting();
  }
}
