import { Provider } from '@angular/core'
import { PlatformServiceInterface } from '../../../../../../libs/common/domain/src/lib/platform.service.interface'
import {
  DISABLE_AUTH,
  Gn4PlatformService,
} from './platform/gn4-platform.service'
import { Gn4PlatformMapper } from './platform/gn4-platform.mapper'
import { RecordsRepositoryInterface } from '../../../../../../libs/common/domain/src/lib/repository/records-repository.interface'
import { Gn4Repository } from './gn4-repository'
import { AvatarServiceInterface, GravatarService } from './auth'
import { OrganizationsServiceInterface } from '../../../../../../libs/common/domain/src/lib/organizations.service.interface'
import {
  ORGANIZATIONS_STRATEGY,
  organizationsServiceFactory,
} from './organizations'
import { ElasticsearchService } from './elasticsearch'
import {
  GroupsApiService,
  SearchApiService,
} from '../../../../../../libs/data-access/gn4/src'
import { TranslateService } from '@ngx-translate/core'

interface Gn4ProvideOptions {
  disableAuth?: boolean
}

export function provideGn4(provideOptions?: Gn4ProvideOptions): Provider[] {
  return [
    {
      provide: DISABLE_AUTH,
      useValue: provideOptions?.disableAuth,
    },
    {
      provide: PlatformServiceInterface,
      useClass: Gn4PlatformService,
    },
    {
      provide: RecordsRepositoryInterface,
      useClass: Gn4Repository,
    },
    Gn4PlatformMapper,
    { provide: AvatarServiceInterface, useClass: GravatarService },
    {
      provide: OrganizationsServiceInterface,
      useFactory: organizationsServiceFactory,
      deps: [
        ORGANIZATIONS_STRATEGY,
        ElasticsearchService,
        SearchApiService,
        GroupsApiService,
        TranslateService,
        PlatformServiceInterface,
      ],
    },
  ]
}
