import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { IEmailMessageLogModel } from '@fleio-api/logger/model/email-message-log.model';
import { EmailMessageLogApiService } from '@fleio-api/logger/emai-message-log-api.service';

@Injectable({
  providedIn: 'root'
})
export class EmailMessageLogResolver  {
  constructor(private emailMessageLogApiService: EmailMessageLogApiService) {
  }

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