import { vi } from "vitest";
import type { Client, Message, TextChannel } from "discord.js";

/**
 * Mock Discord client for testing
 */
export function createMockDiscordClient(): Partial<Client> {
  const mockChannel: Partial<TextChannel> = {
    send: vi.fn().mockResolvedValue({
      id: "mock-message-id",
      content: "Mock message sent",
    }),
    id: "mock-channel-id",
    name: "test-channel",
  };

  return {
    channels: {
      fetch: vi.fn().mockResolvedValue(mockChannel),
      cache: {
        get: vi.fn().mockReturnValue(mockChannel),
      },
    } as never,
    on: vi.fn(),
    once: vi.fn(),
    login: vi.fn().mockResolvedValue("mock-token"),
    destroy: vi.fn().mockResolvedValue(undefined),
  };
}

/**
 * Mock Discord message for testing command parsing
 */
export function createMockDiscordMessage(
  content: string,
  overrides?: Partial<Message>
): Partial<Message> {
  return {
    content,
    author: {
      id: "mock-user-id",
      username: "test-user",
      bot: false,
      discriminator: "0001",
      avatar: null,
      tag: "test-user#0001",
    } as never,
    channel: {
      id: "mock-channel-id",
      type: 0, // GuildText
      send: vi.fn().mockResolvedValue({
        id: "response-message-id",
        content: "Response sent",
      }),
    } as never,
    guild: {
      id: "mock-guild-id",
      name: "Test Guild",
    } as never,
    createdTimestamp: Date.now(),
    id: "mock-message-id",
    mentions: {
      has: vi.fn().mockReturnValue(false),
      users: new Map(),
    } as never,
    reply: vi.fn().mockResolvedValue({
      id: "reply-message-id",
      content: "Reply sent",
    }),
    ...overrides,
  };
}
