/**
 * 发送消息请求
 *
 */
import { z } from "zod";

import { booleanOrFalse } from "../../nullable-defaults";

export const SendMessageRequestSchema = z
  .object({
    characterId: z.string().min(1),
    clientMessageId: z.uuid().optional(),
    message: z.string().max(4000).optional(),
    imageId: z.string().min(1).optional(),
    imageThumbUrl: z.string().min(1).optional(),
    imageMediumUrl: z.string().min(1).optional(),
    imageOriginalUrl: z.string().min(1).optional(),
    imageWidth: z.number().int().nonnegative().optional(),
    imageHeight: z.number().int().nonnegative().optional(),
    useWebSocket: booleanOrFalse,
  })
  .refine(
    (value) =>
      Boolean(value.message?.trim()) ||
      Boolean(
        value.imageId ||
          value.imageThumbUrl ||
          value.imageMediumUrl ||
          value.imageOriginalUrl,
      ),
    { message: "message or image is required" },
  )
  .readonly();

export type SendMessageRequestInput = z.input<typeof SendMessageRequestSchema>;
export type SendMessageRequestData = z.output<typeof SendMessageRequestSchema>;

export type SendMessageRequest = SendMessageRequestData;
