import type {
  CoreServices,
  CoreServerConfig,
  CoreSingletonServices,
  CoreUserSession,
  EmailService,
  LogLevel,
  SecretService
} from '@pikku/core'
import type { Kysely } from 'kysely'
import type { UserRole, UserType } from '@heygermany/sdk'
import type { KyselyDB } from './database-types.js'
import type { ContentService } from '@pikku/core/services'
import { SQLConfig } from './config.js'
import { LocalContentConfig } from '@pikku/core/services'
import { RecognitionDossierService } from './services/recognition-dossier-service.js'
import { TranslationService } from './services/translation-service.js'
import type { auth as authFactory } from './wirings/auth.wiring.js'

export interface UserSession extends CoreUserSession {
  userId: string
  name: string
  type: UserType
  role: UserRole
}

export interface Config extends CoreServerConfig {
  domain: string
  port: number
  hostname: string
  logLevel: LogLevel
  sql: SQLConfig
  content: LocalContentConfig
  secrets: {
    mailgunApiKey: string
  }
  apiKeys: string[]
}

export interface SingletonServices extends CoreSingletonServices<Config> {
  kysely: Kysely<KyselyDB>
  // Lazy resolver for the Better Auth instance, injected by the generated
  // pikkuServices wrapper from the `auth` factory (wirings/auth.wiring.ts).
  // `await services.auth()` yields better-auth's server api/handler surface.
  auth: () => Promise<Awaited<ReturnType<typeof authFactory>>>
  content: ContentService
  subscriptionService?: SubscriptionService
  emailService: EmailService
  recognitionDossierService: RecognitionDossierService
  translation: TranslationService
}

export interface Services extends CoreServices<SingletonServices> {}
