import { describe, expect, it } from "vitest";
import { ForwardedMessageSnapshot, ForwardMessageRequest } from "@slackwsh/contracts";
import { buildMessagePermalink } from "./message-actions";

describe("message actions", () => {
  it("builds a channel deep link", () => {
    expect(buildMessagePermalink("https://chat.example.test", {
      workspaceId: 12,
      channelId: 34,
      messageId: 56,
    })).toBe("https://chat.example.test/channel?workspaceId=12&channelId=34&messageId=56");
  });

  it("includes a thread root when linking a reply", () => {
    const link = buildMessagePermalink("https://chat.example.test/app", {
      workspaceId: "workspace id",
      channelId: 34,
      messageId: 57,
      threadRootId: 56,
    });
    expect(link).toContain("workspaceId=workspace+id");
    expect(link).toContain("messageId=57");
    expect(link).toContain("threadId=56");
  });

  it("accepts a complete forwarded-message snapshot", () => {
    expect(ForwardedMessageSnapshot.parse({
      messageId: 1,
      channelId: 2,
      parentId: null,
      channelName: "developer",
      channelType: "private",
      authorId: 3,
      authorName: "Basit",
      authorAvatarUrl: null,
      text: "Original message",
      createdAt: new Date().toISOString(),
      attachmentNames: [],
    }).channelType).toBe("private");
  });

  it("rejects duplicate forward destinations", () => {
    const result = ForwardMessageRequest.safeParse({
      destinations: [
        { channelId: 2, clientMsgId: "00000000-0000-4000-8000-000000000001" },
        { channelId: 2, clientMsgId: "00000000-0000-4000-8000-000000000002" },
      ],
      note: "FYI",
    });
    expect(result.success).toBe(false);
  });
});
