export function getDocumentUrl(localValue: unknown, type: string): string {
  if (type === 'fileDocumentLink') {
    return (localValue as string) ?? '';
  }
  return (localValue as { url?: string })?.url ?? '';
}

export function getDocumentFileName(url: string): string {
  if (!url) {
    return '';
  }
  return url.split('/').pop() ?? '';
}

export function haveDocumentValue(localValue: unknown, type: string): boolean {
  if (type === 'fileDocumentLink') {
    return !!localValue;
  }
  return !!(localValue as { url?: string })?.url;
}

export function clearDocumentValue(type: string): string | Record<string, never> {
  if (type === 'fileDocumentLink') {
    return '';
  }
  return {};
}
