export interface AttachmentLocalPaths {
  filePath?: string | null;
  savedPath?: string | null;
}

export function mergeAttachmentLocalPaths(
  incoming: AttachmentLocalPaths,
  stored?: AttachmentLocalPaths | null
): Required<AttachmentLocalPaths> {
  const resolvePath = (incomingPath: string | null | undefined, storedPath: string | null | undefined): string | null => {
    if (typeof incomingPath === 'string' && incomingPath.trim()) {
      return incomingPath;
    }

    if (typeof storedPath === 'string' && storedPath.trim()) {
      return storedPath;
    }

    return null;
  };

  return {
    filePath: resolvePath(incoming.filePath, stored?.filePath),
    savedPath: resolvePath(incoming.savedPath, stored?.savedPath)
  };
}
