import { NgModule, ModuleWithProviders, Optional } from '@angular/core';
import { SsoInterfaceImpl } from './sso-interface-impl.service';
import { OAuthModule, AuthConfig } from 'angular-oauth2-oidc';
import { SsoInterface } from './sso.interface';
import { SsoInterfaceImplProd } from './sso-interface-impl-prod.service';

export function _ssoInterfaceImplProdBuilderFactory() {
  return new SsoInterfaceImplProd();
}

export function _ssoInterfaceImplBuilderFactory() {
  return new SsoInterfaceImpl();
}

@NgModule({
  declarations: [],
  imports: [
    OAuthModule.forRoot({
      resourceServer: { sendAccessToken: true },
    }),
  ],
  exports: [],
})
export class SsoModule {
  static forRoot(production: boolean = false): ModuleWithProviders<SsoModule> {
    return {
      ngModule: SsoModule,
      providers: [
        {
          provide: SsoInterface,
          useFactory: production ? _ssoInterfaceImplProdBuilderFactory : _ssoInterfaceImplBuilderFactory,
        },
      ],
    };
  }
}
