export type OperationArea = 'permit' | 'integration' | 'ai' | 'system' | 'billing'
export type OperationOutcome = 'started' | 'success' | 'skipped' | 'failed'
export type OperationDetail = Record<string, string | number | boolean | null | undefined>

const SENSITIVE_KEY = /authorization|cookie|password|secret|api[_-]?key|access[_-]?token|jwt|body|content|question|answer|url/i

/** Keep operational logs compact and free of request bodies and credentials. */
export function safeOperationDetail(detail: OperationDetail = {}): Record<string, string | number | boolean | null> {
  return Object.fromEntries(Object.entries(detail).map(([key, value]) => {
    if (SENSITIVE_KEY.test(key)) return [key.slice(0, 80), '[REDACTED]']
    if (typeof value === 'string') return [key.slice(0, 80), value.slice(0, 300)]
    return [key.slice(0, 80), value ?? null]
  }).slice(0, 30))
}
