import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { IHeatStackModel } from '@fleio-api/openstack/orchestration/model/heat-stack.model';
import { HeatStacksApiService } from '@fleio-api/openstack/orchestration/heat-stacks/heat-stacks-api.service';

@Injectable({
  providedIn: 'root'
})
export class HeatStackResolver  {
  constructor(private heatStacksApiService: HeatStacksApiService) {
  }

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