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 { FloatingIpsApiService } from '@fleio-api/openstack/floating-ips/floating-ips-api.service';

@Injectable({
  providedIn: 'root'
})
export class FloatingIpPermissionsResolver  {
  constructor(private floatingIpsApiService: FloatingIpsApiService) {
  }

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