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

import {
  ChatActionEventRequestSchema,
  ChatActionSchema,
} from "@/data/schemas/chat";

describe("ChatActionSchema", () => {
  it("accepts a support action without an order", () => {
    expect(
      ChatActionSchema.parse({
        actionId: "action-1",
        kind: "support",
        type: "openFeedback",
        copy: "Send the screenshot and approximate payment time here.",
        ctaLabel: "Open Feedback",
        ruleId: null,
        orderId: null,
      }),
    ).toMatchObject({ type: "openFeedback", orderId: null });
  });

  it("requires orderId only for resumePayment", () => {
    expect(() =>
      ChatActionSchema.parse({
        actionId: "action-2",
        kind: "support",
        type: "resumePayment",
        copy: "You can continue the pending order here.",
        ctaLabel: "Continue",
        ruleId: null,
        orderId: null,
      }),
    ).toThrow();
    expect(() =>
      ChatActionSchema.parse({
        actionId: "action-3",
        kind: "support",
        type: "openWallet",
        copy: "Open your wallet.",
        ctaLabel: "Open Wallet",
        ruleId: null,
        orderId: "order-not-allowed",
      }),
    ).toThrow();
  });
});

describe("ChatActionEventRequestSchema", () => {
  it("requires a UUID event id and an allowlisted event type", () => {
    expect(
      ChatActionEventRequestSchema.parse({
        eventId: "4b223884-02ec-4fd2-aacf-e84ee8ca3adb",
        actionId: "action-1",
        characterId: "elio",
        eventType: "arrived",
      }),
    ).toMatchObject({ eventType: "arrived" });
    expect(() =>
      ChatActionEventRequestSchema.parse({
        eventId: "not-a-uuid",
        actionId: "action-1",
        characterId: "elio",
        eventType: "clicked",
      }),
    ).toThrow();
  });
});
