import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { RbacPoliciesApiService } from '@fleio-api/openstack/rbac-policy/rbac-policies-api.service';
import { IRBACPolicyCreateOptionsModel } from '@fleio-api/openstack/rbac-policy/model/rbac-policy-create-options.model';

@Injectable({
  providedIn: 'root'
})
export class RbacPolicyCreateOptionsResolver  {
  constructor(private rbacPoliciesApiService: RbacPoliciesApiService) {
  }

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