/**
 * MessageMode Type Tests
 *
 * Tests the helper functions exported from messageMode.ts:
 * - getMessageMode: looks up a MessageMode by id
 * - formatMessageWithMode: prepends a mode prefix to a message
 *
 * What this module does:
 * - Defines the six conversation modes (chat, architect, code, debug, ask, review)
 * - Provides a lookup function to find a mode by its id
 * - Provides a formatting function that prepends the mode prefix to messages
 *
 * Manual testing checklist:
 * - [ ] Mode selector shows correct names and icons for all six modes
 * - [ ] Selecting a mode prefixes the next message with the correct prefix
 * - [ ] Switching back to Chat sends messages without any prefix
 * - [ ] Sending a message that already has the prefix does not double-prefix it
 */

import { describe, it, expect } from "vitest";
import { MESSAGE_MODES, getMessageMode, formatMessageWithMode } from "./messageMode";

describe("MESSAGE_MODES", () => {
  it("contains all six expected modes", () => {
    const ids = MESSAGE_MODES.map((m) => m.id);
    expect(ids).toEqual(["chat", "architect", "code", "debug", "ask", "review"]);
  });

  it("each mode has an id, name, description, and icon", () => {
    for (const mode of MESSAGE_MODES) {
      expect(mode.id).toBeTruthy();
      expect(mode.name).toBeTruthy();
      expect(mode.description).toBeTruthy();
      expect(mode.icon).toBeTruthy();
    }
  });
});

describe("getMessageMode", () => {
  it("returns the chat mode with no prefix", () => {
    const mode = getMessageMode("chat");
    expect(mode).toBeDefined();
    expect(mode?.id).toBe("chat");
    expect(mode?.prefix).toBeUndefined();
  });

  it("returns the architect mode with its prefix", () => {
    const mode = getMessageMode("architect");
    expect(mode?.id).toBe("architect");
    expect(mode?.prefix).toBe("[Architect Mode] ");
  });

  it("returns the code mode with its prefix", () => {
    const mode = getMessageMode("code");
    expect(mode?.id).toBe("code");
    expect(mode?.prefix).toBe("[Code Mode] ");
  });

  it("returns the debug mode with its prefix", () => {
    const mode = getMessageMode("debug");
    expect(mode?.id).toBe("debug");
    expect(mode?.prefix).toBe("[Debug Mode] ");
  });

  it("returns the ask mode with its prefix", () => {
    const mode = getMessageMode("ask");
    expect(mode?.id).toBe("ask");
    expect(mode?.prefix).toBe("[Ask Mode] ");
  });

  it("returns the review mode with its prefix", () => {
    const mode = getMessageMode("review");
    expect(mode?.id).toBe("review");
    expect(mode?.prefix).toBe("[Review Mode] ");
  });

  it("returns undefined for an unknown mode id", () => {
    expect(getMessageMode("unknown")).toBeUndefined();
  });

  it("returns undefined for an empty string", () => {
    expect(getMessageMode("")).toBeUndefined();
  });
});

describe("formatMessageWithMode", () => {
  it("prepends the prefix for code mode", () => {
    expect(formatMessageWithMode("hello", "code")).toBe("[Code Mode] hello");
  });

  it("prepends the prefix for architect mode", () => {
    expect(formatMessageWithMode("design this", "architect")).toBe("[Architect Mode] design this");
  });

  it("prepends the prefix for debug mode", () => {
    expect(formatMessageWithMode("fix this bug", "debug")).toBe("[Debug Mode] fix this bug");
  });

  it("prepends the prefix for ask mode", () => {
    expect(formatMessageWithMode("what is this?", "ask")).toBe("[Ask Mode] what is this?");
  });

  it("prepends the prefix for review mode", () => {
    expect(formatMessageWithMode("review my code", "review")).toBe("[Review Mode] review my code");
  });

  it("returns the message unchanged in chat mode (no prefix)", () => {
    expect(formatMessageWithMode("hello", "chat")).toBe("hello");
  });

  it("returns the message unchanged for unknown mode ids", () => {
    expect(formatMessageWithMode("hello", "unknown")).toBe("hello");
    expect(formatMessageWithMode("hello", "")).toBe("hello");
  });

  it("does not double-prefix a message already starting with the mode prefix", () => {
    expect(formatMessageWithMode("[Code Mode] already prefixed", "code")).toBe(
      "[Code Mode] already prefixed"
    );
  });

  it("adds the prefix to an empty string", () => {
    expect(formatMessageWithMode("", "code")).toBe("[Code Mode] ");
  });
});
