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

import { BasicSetting } from '../models/basic-setting';
import { BasicService } from '../services/basic.service';

@Injectable({
  providedIn: 'root',
})
export class BasicResolver implements Resolve<any> {
  /**
   * Constructor
   */
  constructor(private _basicService: BasicService) {}

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

  /**
   * Resolver
   *
   * @param route
   * @param state
   */
  resolve(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ): Observable<{
    basicSetting: BasicSetting;
  }> {
    return this._basicService.getBasicSetting();
  }
}
