import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { ClustersApiService } from '@fleio-api/openstack/cluster/clusters-api.service';
import { IClusterResizeOptionsModel } from '@fleio-api/openstack/model/cluster-resize-options.model';

@Injectable({
  providedIn: 'root'
})
export class ClusterResizeOptionsResolver  {
  constructor(private clustersApiService: ClustersApiService) {
  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
    Observable<IClusterResizeOptionsModel> | Promise<IClusterResizeOptionsModel> | IClusterResizeOptionsModel {
    return this.clustersApiService.resizeOptions(route.params.id)
      .pipe(catchError(() => of(null))) as unknown as IClusterResizeOptionsModel;
  }
}
