import { vi } from 'vitest'
import {
  getCookie,
  setCookie,
  getMethod,
  getHeader,
  getHeaders,
  setHeader,
  getRequestURL,
  createError,
  defineEventHandler,
  readBody,
  getQuery,
  getRouterParam
} from 'h3'

// Register real h3 functions as globals so server code that relies on
// Nitro auto-imports can find them in the test environment.
vi.stubGlobal('getCookie', getCookie)
vi.stubGlobal('setCookie', setCookie)
vi.stubGlobal('getMethod', getMethod)
vi.stubGlobal('getHeader', getHeader)
vi.stubGlobal('getHeaders', getHeaders)
vi.stubGlobal('setHeader', setHeader)
vi.stubGlobal('getRequestURL', getRequestURL)
vi.stubGlobal('createError', createError)
vi.stubGlobal('defineEventHandler', defineEventHandler)
vi.stubGlobal('readBody', readBody)
vi.stubGlobal('getQuery', getQuery)
vi.stubGlobal('getRouterParam', getRouterParam)

vi.stubGlobal('useRuntimeConfig', () => ({
  jwtSecret: 'test-jwt-secret'
}))
