export function createNewChatMessagePreview(text, files = [], options = {}) {
  return {
    id: options.id ?? crypto.randomUUID(),
    event: "message.accepted",
    data: {
      text: String(text ?? "").trim(),
      ...(files.length ? { attachmentCount: files.length } : {}),
      optimistic: true
    },
    createdAt: options.createdAt ?? new Date().toISOString()
  };
}

export function reconcileNewChatMessagePreview(preview, attachmentCount) {
  const data = { ...preview.data };
  delete data.attachmentCount;
  if (attachmentCount > 0) data.attachmentCount = attachmentCount;
  return { ...preview, data };
}
