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 { ClustersApiService } from '@fleio-api/openstack/cluster/clusters-api.service';

@Injectable({
  providedIn: 'root'
})
export class ClusterPermissionsResolver  {
  constructor(private clustersApiService: ClustersApiService) {
  }

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