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

@Injectable({
  providedIn: 'root'
})
export class MessageTemplatesPermissionsResolver  {
  constructor(private messageTemplatesApiService: MessageTemplatesApiService) {
  }

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