import { Injectable } from '@angular/core';
import { IPermissionsModel } from '@fleio-api/base-model/IPermissionsModel';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { RbacPoliciesApiService } from '@fleio-api/openstack/rbac-policy/rbac-policies-api.service';

@Injectable({
  providedIn: 'root'
})
export class RbacPolicyPermissionsResolver  {
  constructor(private rbacPoliciesApiService: RbacPoliciesApiService) {
  }

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