import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { IPeriodicTaskLogModel } from '@fleio-api/logger/model/periodic-task-log.model';
import { PeriodicTaskLogApiService } from '@fleio-api/logger/periodic-task-log-api.service';

@Injectable({
  providedIn: 'root'
})
export class PeriodicTaskLogResolver  {
  constructor(private periodicTaskLogApiService: PeriodicTaskLogApiService) {
  }

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