import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { ServicesApiService } from './service-api.service';
import { IServiceUpgradeOptionsModel } from '../model/service-upgrade-options.model';

@Injectable({
  providedIn: 'root'
})
export class ServiceUpgradeOptionsResolver  {
  constructor(private servicesApiService: ServicesApiService) {
  }

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