export const normalizeStringArray = <T extends string = string>(
  value: T[] | string | null | undefined
): T[] | null => {
  if (value == null) return null
  if (Array.isArray(value)) return value

  const trimmed = value.trim()
  if (!trimmed) return []

  try {
    const parsed = JSON.parse(trimmed)
    if (Array.isArray(parsed)) {
      return parsed.filter((item): item is T => typeof item === 'string')
    }
  } catch {
    // fall through
  }

  return [trimmed as T]
}
