import { normalizeNum } from '../user-cache'

export function normalizeLimit(
  input: unknown,
): { context?: number; output?: number } | undefined {
  const obj =
    input && typeof input === 'object' ? (input as Record<string, unknown>) : {}
  const context = normalizeNum(obj.context)
  const output = normalizeNum(obj.output)
  if (context == null && output == null) return undefined
  return {
    ...(context != null ? { context } : {}),
    ...(output != null ? { output } : {}),
  }
}
