import { Prisma } from '@prisma/client'; export function asCustomFields(value: unknown): Record { if (value && typeof value === 'object' && !Array.isArray(value)) { return value as Record; } return {}; } export function toJsonCustomFields( value?: Record | null, ): Prisma.InputJsonValue { return (value ?? {}) as Prisma.InputJsonValue; } export function asAddresses(value: unknown): string[] { if (!Array.isArray(value)) return []; const out: string[] = []; for (const item of value) { const text = String(item ?? '').trim(); if (text && !out.includes(text)) out.push(text); if (out.length >= 20) break; } return out; } export function toJsonAddresses(value?: string[] | null): Prisma.InputJsonValue { return asAddresses(value ?? []); } /** Collect address-like cells from an excel row into a unique list. */ export function collectAddresses(...parts: Array): string[] { return asAddresses(parts.map((p) => (p ?? '').trim()).filter(Boolean)); }