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

import { composeDirective, PLOT_PRESETS, STYLE_PRESETS } from "./directive";

describe("composeDirective", () => {
  it("returns empty string when nothing selected", () => {
    expect(composeDirective("", [])).toBe("");
    expect(composeDirective("   ", [])).toBe("");
  });

  it("uses free text only when no presets", () => {
    expect(composeDirective("多写战斗", [])).toBe("多写战斗");
  });

  it("combines presets (in canonical order) then free text", () => {
    const result = composeDirective("多写战斗", ["fast-pace", "less-ai"]);
    const lessAi = STYLE_PRESETS.find((p) => p.id === "less-ai")!.text;
    const fastPace = STYLE_PRESETS.find((p) => p.id === "fast-pace")!.text;
    expect(result).toBe(`${lessAi}；${fastPace}；多写战斗`);
  });

  it("ignores unknown preset ids", () => {
    const lessAi = STYLE_PRESETS.find((p) => p.id === "less-ai")!.text;
    expect(composeDirective("", ["nope", "less-ai"])).toBe(lessAi);
  });

  it("resolves 剧情需求 presets alongside 文风", () => {
    const plot = PLOT_PRESETS[0]!;
    expect(composeDirective("", [plot.id])).toBe(plot.text);
  });

  it("orders 文风 presets before 剧情 presets, then free text", () => {
    const style = STYLE_PRESETS[0]!;
    const plot = PLOT_PRESETS[0]!;
    const result = composeDirective("再收紧节奏", [plot.id, style.id]);
    expect(result).toBe(`${style.text}；${plot.text}；再收紧节奏`);
  });
});
