import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { GatewaysApiService } from '@fleio-api/billing/gateways/gateways-api.service';
import {
  IRecurringPaymentOptionModelResponse
} from '@fleio-api/billing/model/recurring-payment-option.model';

@Injectable({
  providedIn: 'root'
})
export class RecurringPaymentOptionsResolver  {
  constructor(private gatewaysApiService: GatewaysApiService) {
  }

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