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

import { BranchService } from '../services/branch.service';

@Injectable({
  providedIn: 'root',
})
export class BranchResolver implements Resolve<any> {
  /**
   * Constructor
   */
  constructor(private _branchService: BranchService) {}

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

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