/*
 * Copyright (C) 2019 Robert Bosch GmbH Copyright (C) 2019 Robert Bosch Manufacturing Solutions GmbH, Germany. All rights reserved.
 */

import { Provider } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpRequest } from '@angular/common/http';

export interface IAuthModuleOptions {
  authOptionsProvider?: Provider;
  config?: IAuthModuleConfig;
}

export interface IAuthModuleConfig {
  /**
   * Header name, that will be used for token.
   * Default: Authorization
   */
  headerName?: string;

  /**
   * auth-scheme is the string, the token will be appended to.
   * Default: Bearer
   */
  authScheme?: string;

  /**
   * AccessControl-Endpoint. Can be provided statically as string or as Observable.
   * @deprecated Use authServerBaseUrl instead.
   */
  accessControlEndpoint?: string | Observable<string>;

  /**
   * Base URL of the authorization server. Can be provided statically as string or as Observable.
   */
  authServerBaseUrl?: string | Observable<string>;

  /**
   * Optional specific base URL to get the ACL from the authorization server. Can be provided statically as string or as Observable.
   * Default: authServerBaseUrl will be used if this is not set.
   */
  authServerACLBaseUrl?: string | Observable<string>;

  /**
   * Name of ResourceSet in AccessControl. Can be provided statically as string or as Observable.
   */
  resourceSetName?: string | Observable<string>;
  // tokenEndpoint: string;
  skipWhenExpired?: boolean;

  /**
   * Control whether Authorization header with token should be added to request.
   * Default: Header will always be added.
   */
  addAuthHeader?: (req: HttpRequest<any>) => boolean;

  /**
   * Enable automatic token refresh.
   * Default: true
   */
  automaticTokenRefresh?: boolean;

  /**
   * Time in seconds, when the token will be refreshed before expiration.
   */
  refreshTokenTimeInSeconds?: number;

  /**
   * Enable console logging of authentication processes.
   * Default: false
   */
  debugAuthentication?: boolean;
}

/* tslint:disable:variable-name */
export const DefaultAuthModuleConfig: IAuthModuleConfig = {
  headerName: 'Authorization',
  // tokenEndpoint: '',
  resourceSetName: '',
  authScheme: 'Bearer',
  skipWhenExpired: false,
  automaticTokenRefresh: true,
  refreshTokenTimeInSeconds: 2 * 60,
  debugAuthentication: false,
};

/* tslint:enable:variable-name */
