import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { IPredefinedReplyCategoryModel } from '@fleio-api/plugins/tickets/model/predefined-reply-category.model';
import { PredefinedReplyCategoryApiService } from '@fleio-api/plugins/tickets/predefined-reply-category-api.service';

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

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