import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve, 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 DbaasInstanceResizeOptionsResolver implements Resolve<IDbaasInstanceModel> {
  constructor(private dbaasInstancesApiService: DbaasInstancesApiService) {
  }
  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
    Observable<IDbaasInstanceModel> | Promise<IDbaasInstanceModel> | IDbaasInstanceModel {
    return this.dbaasInstancesApiService.getResizeOptions(route.params.id)
      .pipe(catchError(() => of(null)));
  }
}
