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

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

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