import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { IPermissionsModel } from '../../base-model/IPermissionsModel';
import { catchError } from 'rxjs/operators';
import { TaxRulesApiService } from '@fleio-api/billing/tax-rules/tax-rules-api.service';

@Injectable({
  providedIn: 'root'
})
export class TaxRulePermissionsResolver  {
  constructor(private taxRulesApiService: TaxRulesApiService) {
  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
    Observable<IPermissionsModel> | Promise<IPermissionsModel> | IPermissionsModel {
    return this.taxRulesApiService.permissions().pipe(catchError(() => of(null)));
  }
}
