import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { ISaml2IdentityProviderModel } from '@fleio-api/core/model/saml2-identity-provider.model';
import { Saml2IdentityProvidersApiService } from '@fleio-api/core/saml2-identity-providers-api.service';

@Injectable({
  providedIn: 'root'
})
export class Saml2IdentityProviderResolver  {
  constructor(private saml2IdentityProvidersApiService: Saml2IdentityProvidersApiService) {
  }

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