import { describe, expect, it } from "vitest";

import {
  ChatPreviewsResponseSchema,
  SendMessageRequestSchema,
} from "@/data/schemas/chat";

describe("multi-role chat schemas", () => {
  it("accepts text or image sends and rejects empty or oversized text", () => {
    expect(
      SendMessageRequestSchema.parse({ characterId: "elio", message: "Hi" }),
    ).toMatchObject({ characterId: "elio", message: "Hi" });
    expect(
      SendMessageRequestSchema.parse({
        characterId: "maya-tan",
        imageId: "image-1",
      }),
    ).toMatchObject({ characterId: "maya-tan", imageId: "image-1" });
    expect(() => SendMessageRequestSchema.parse({ characterId: "elio" })).toThrow();
    expect(() =>
      SendMessageRequestSchema.parse({
        characterId: "elio",
        message: "x".repeat(4001),
      }),
    ).toThrow();
  });

  it("parses nullable immutable previews", () => {
    const previews = ChatPreviewsResponseSchema.parse({
      items: [{ characterId: "elio", message: null }],
    });

    expect(previews.items[0]?.message).toBeNull();
    expect(Object.isFrozen(previews.items)).toBe(true);
  });
});
