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 { RevenueReportsApiService } from '@fleio-api/utils/revenue-reports/revenue-reports-api.service';

@Injectable({
  providedIn: 'root'
})
export class RevenueReportPermissionsResolver  {
  constructor(private revenueReportsApiService: RevenueReportsApiService) {
  }

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