import 'express'
import OAuth2Server from '@node-oauth/oauth2-server'
import type SessionData from 'express-session'

// Request-scoped logger attached by @overleaf/metrics http.monitor() middleware.
// See libraries/metrics/http.js RequestLogger class.
interface RequestLogger {
  addFields(fields: Record<string, unknown>): void
  setLevel(level: string): void
  disable(): void
}

// Add properties to Express's Request object that are defined in JS middleware
// or controllers and expected to be present in controllers.
declare module 'express' {
  // eslint-disable-next-line no-unused-vars
  interface Request {
    session: SessionData
    userRestrictions?: Set
    oauth_user?: OAuth2Server.User
    logger: RequestLogger
    i18n: {
      translate(
        key: string,
        vars?: Record<string, any>,
        components?: any
      ): string
    }
  }
}
