import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { IProjectQuotasCreateOptionsModel } from '@fleio-api/openstack/project/model/project-quotas-create-options.model';
import { ProjectsApiService } from '@fleio-api/openstack/project/projects-api.service';

@Injectable({
  providedIn: 'root'
})
export class ProjectQuotasCreateOptionsResolver  {
  constructor(private projectsApiService: ProjectsApiService) {
  }

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