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

export const ChatMessageSchema = z
  .object({
    role: z.string(),
    type: z.string().default("text"),
    content: z.string(),
    id: z.string().default(""),
    createdAt: z.string().default(""),
    created_at: z.string().optional(),
    audioUrl: z.string().nullable().default(null),
    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>;
