/**
 * 聊天历史中的单条消息
 * 
 */
import { z } from "zod";

import { stringOr, stringOrEmpty, stringOrNull } from "../nullable-defaults";
import { ChatImageSchema, ChatLockDetailSchema } from "./chat_payloads";

export const ChatMessageSchema = z
  .object({
    role: stringOrEmpty,
    type: stringOr("text"),
    content: stringOrEmpty,
    id: stringOrEmpty,
    createdAt: stringOrEmpty,
    created_at: stringOrNull,
    audioUrl: stringOrNull,
    image: ChatImageSchema,
    lockDetail: ChatLockDetailSchema,
  })
  .transform(({ created_at, ...data }) => ({
    ...data,
    createdAt: data.createdAt || created_at || "",
  }));

export type ChatMessageInput = z.input<typeof ChatMessageSchema>;
export type ChatMessageData = z.output<typeof ChatMessageSchema>;
