export function normalizeBoolean(value: unknown, fallback: boolean) {
  if (typeof value === 'boolean') return value
  const text = String(value ?? '')
    .trim()
    .toLowerCase()
  if (!text) return fallback
  if (['true', '1', 'yes', 'enabled', 'active', 'on'].includes(text)) return true
  if (['false', '0', 'no', 'disabled', 'off'].includes(text)) return false
  return fallback
}

export function normalizeSessionVersion(value: unknown): number {
  const parsed = Number(value)
  return Number.isInteger(parsed) && parsed > 0 ? parsed : 1
}

export function normalizeInteger(value: unknown, fallback: number): number {
  const parsed = Number(value)
  return Number.isInteger(parsed) ? parsed : fallback
}

export function normalizePositiveInteger(value: unknown, fallback: number): number {
  const parsed = Number(value)
  return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback
}
