import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { IVolumeType } from '@fleio-api/openstack/model/volume-type.model';
import { VolumeTypesApiService } from '@fleio-api/openstack/volume/volume-types-api.service';

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

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