import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { IPermissionsModel } from '../../base-model/IPermissionsModel';
import { catchError } from 'rxjs/operators';
import { ApiUsersApiService } from '@fleio-api/openstack/api-user/api-users-api.service';

@Injectable({
  providedIn: 'root'
})
export class ApiUserPermissionsResolver  {
  constructor(private apiUsersApi: ApiUsersApiService) {
  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
    Observable<IPermissionsModel> | Promise<IPermissionsModel> | IPermissionsModel {
    return this.apiUsersApi.permissions().pipe(catchError(() => of(null)));
  }
}
