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 { PredefinedReplyCategoryApiService } from '@fleio-api/plugins/tickets/predefined-reply-category-api.service';

@Injectable({
  providedIn: 'root'
})
export class PredefinedRepliesPermissionsResolver  {
  constructor(private predefinedReplyCategoryApiService: PredefinedReplyCategoryApiService) {
  }

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