import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { UserProfileApiService } from './user-profile-api.service';
import { IUserProfileCreateOptionsModel } from '../model/user-profile-create-options.model';

@Injectable({
  providedIn: 'root'
})
export class UserProfileCreateOptionsResolver  {
  constructor(private userProfileApiService: UserProfileApiService) {
  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
    Observable<IUserProfileCreateOptionsModel> | Promise<IUserProfileCreateOptionsModel> |
    IUserProfileCreateOptionsModel {
    const createOpt = this.userProfileApiService.createOptions() as Observable<IUserProfileCreateOptionsModel>;
    return createOpt.pipe(catchError(() => of(null)));
  }
}
