import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { HeatTemplateVersionsApiService } from '@fleio-api/openstack/orchestration/heat-template-versions/heat-template-versions-api.service';
import { IHeatTemplateVersionModel } from '@fleio-api/openstack/orchestration/model/heat-template-version.model';

@Injectable({
  providedIn: 'root'
})
export class HeatTemplateVersionResolver  {
  constructor(private heatTemplateVersionsApiService: HeatTemplateVersionsApiService) {
  }

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