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 { ProjectsApiService } from '@fleio-api/openstack/project/projects-api.service';

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

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