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 { VolumeTypesApiService } from '@fleio-api/openstack/volume/volume-types-api.service';

@Injectable({
  providedIn: 'root'
})
export class VolumeTypePermissionsResolver  {
  constructor(private volumeTypesApiService: VolumeTypesApiService) {
  }

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