import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { IAccountCapabilitiesModel } from '@fleio-api/openstack/object-store/model/account-capabilities.model';
import { AccountApiService } from '@fleio-api/openstack/object-store/account/account-api.service';

@Injectable({
  providedIn: 'root'
})
export class AccountCapabilitiesResolver  {
  constructor(private accountApiService: AccountApiService) {
  }

  // noinspection JSUnusedLocalSymbols
  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
    Observable<IAccountCapabilitiesModel> | Promise<IAccountCapabilitiesModel> | IAccountCapabilitiesModel {
    this.accountApiService.setAdditionalQueryParams(route.queryParams);
    return this.accountApiService.capabilities().pipe(catchError(() => of(null)));
  }
}
