import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { HeatResourceTypesApiService } from '@fleio-api/openstack/orchestration/heat-resource-types/heat-resource-types-api.service';
import { IHeatResourceTypeModel } from '@fleio-api/openstack/orchestration/model/heat-resource-type.model';

@Injectable({
  providedIn: 'root'
})
export class HeatResourceTypeResolver  {
  constructor(private heatResourceTypesApiService: HeatResourceTypesApiService) {
  }

  // noinspection JSUnusedLocalSymbols
  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
    Observable<IHeatResourceTypeModel> | Promise<IHeatResourceTypeModel> | IHeatResourceTypeModel {
    return this.heatResourceTypesApiService.details(route.params.id).pipe(catchError(() => of(null)));

  }
}
