import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { DbaasInstancesApiService } from '@fleio-api/openstack/dbaas/dbaas-instances-api.service';
import { IDbaasInstanceModel } from '@fleio-api/openstack/model/dbaas-instance.model';

@Injectable({
  providedIn: 'root'
})
export class DbaasInstanceCreateOptionsResolver  {
  constructor(private dbaasInstancesApiService: DbaasInstancesApiService) {
  }
  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
    Observable<IDbaasInstanceModel> | Promise<IDbaasInstanceModel> | IDbaasInstanceModel {
    return this.dbaasInstancesApiService.createOptions()
      .pipe(catchError(() => of(null))) as unknown as IDbaasInstanceModel;
  }
}
