import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { ConfigurableOptionsApiService } from './configurable-option-api.service';
import { IConfigurableOptionCreateOptionsModel } from '@fleio-api/billing/model/configurable-option-create-options.model';

@Injectable({
  providedIn: 'root'
})
export class ConfigurableOptionCreateOptionsResolver  {
  constructor(private configurableOptionsApiService: ConfigurableOptionsApiService) {
  }

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