import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { CoreApiService } from '@fleio-api/core/core-api.service';
import { IExternalBillingUrlResponseModel } from '@fleio-api/core/model/external-billing-url.model';

@Injectable({
  providedIn: 'root'
})
export class ExternalBillingUrlResolver  {
  constructor(private coreApiService: CoreApiService) {
  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
    Observable<IExternalBillingUrlResponseModel> | Promise<IExternalBillingUrlResponseModel>
    | IExternalBillingUrlResponseModel {
    return this.coreApiService.getExternalBillingUrl().pipe(catchError(() => of(null)));
  }
}
