import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {Platform} from '@ionic/angular';
import {Requestor, StorageBackend} from '@openid/appauth';
import {authFactory, paiaAuthFactory, storageFactory} from './factories';
import {DefaultAuthService} from './default-auth.service';
import {Browser} from 'ionic-appauth';
import {CapacitorBrowser} from 'ionic-appauth/lib/capacitor';
import {httpFactory} from './factories/http.factory';
import {HttpClient} from '@angular/common/http';
import {PAIAAuthService} from './paia/paia-auth.service';
import {AuthRoutingModule} from './auth-routing.module';
import {TranslateModule} from '@ngx-translate/core';
import {AuthCallbackPageComponent} from './auth-callback/page/auth-callback-page.component';
import {PAIAAuthCallbackPageComponent} from './paia/auth-callback/page/auth-callback-page.component';

@NgModule({
  declarations: [AuthCallbackPageComponent, PAIAAuthCallbackPageComponent],
  imports: [CommonModule, AuthRoutingModule, TranslateModule],
  providers: [
    {
      provide: StorageBackend,
      useFactory: storageFactory,
      deps: [Platform],
    },
    {
      provide: Requestor,
      useFactory: httpFactory,
      deps: [Platform, HttpClient],
    },
    {
      provide: Browser,
      useClass: CapacitorBrowser,
    },
    {
      provide: DefaultAuthService,
      useFactory: authFactory,
      deps: [Requestor, Browser, StorageBackend],
    },
    {
      provide: PAIAAuthService,
      useFactory: paiaAuthFactory,
      deps: [Requestor, Browser, StorageBackend],
    },
  ],
})
export class AuthModule {}
