import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { IFloatingIpCreateOptionsModel } from '@fleio-api/openstack/floating-ips/model/floating-ip-create-options.model';
import { FloatingIpsApiService } from '@fleio-api/openstack/floating-ips/floating-ips-api.service';

@Injectable({
  providedIn: 'root'
})
export class FloatingIpCreateOptionsResolver  {
  constructor(private floatingIpsApiService: FloatingIpsApiService) {
  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
    Observable<IFloatingIpCreateOptionsModel> | Promise<IFloatingIpCreateOptionsModel> | IFloatingIpCreateOptionsModel {
    return this.floatingIpsApiService.createOptions()
      .pipe(catchError(() => of(null))) as unknown as IFloatingIpCreateOptionsModel;
  }
}
