import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { SubnetPoolsApiService } from '@fleio-api/openstack/subnet-pools/subnet-pools-api.service';
import { ISubnetPoolModel } from '@fleio-api/openstack/subnet-pools/model/subnet-pool.model';

@Injectable({
  providedIn: 'root'
})
export class SubnetPoolResolver  {
  constructor(private subnetPoolsApiService: SubnetPoolsApiService) {
  }

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