import { describe, it, expect } from "vitest";
import { resolveDocPath } from "./generate-doc";

describe("resolveDocPath", () => {
  it("resolves command doc path", () => {
    const result = resolveDocPath("command", "CreateOrder", "modules/inventory");
    expect(result).toBe("modules/inventory/docs/commands/CreateOrder.md");
  });

  it("resolves feature doc path", () => {
    const result = resolveDocPath("feature", "stock-tracking", "modules/inventory");
    expect(result).toBe("modules/inventory/docs/features/stock-tracking.md");
  });

  it("resolves model doc path", () => {
    const result = resolveDocPath("model", "StockItem", "modules/inventory");
    expect(result).toBe("modules/inventory/docs/models/StockItem.md");
  });

  it("resolves query doc path", () => {
    const result = resolveDocPath("query", "ConvertQuantity", "modules/inventory");
    expect(result).toBe("modules/inventory/docs/queries/ConvertQuantity.md");
  });

  it("resolves actors doc path", () => {
    const result = resolveDocPath("actors", "admin", "examples/my-app");
    expect(result).toBe("examples/my-app/docs/actors/admin.md");
  });

  it("resolves business-flow doc path", () => {
    const result = resolveDocPath("business-flow", "onboarding", "examples/my-app");
    expect(result).toBe("examples/my-app/docs/business-flow/onboarding/README.md");
  });

  it("resolves story doc path with flow/name format", () => {
    const result = resolveDocPath("story", "onboarding/admin--create-user", "examples/my-app");
    expect(result).toBe(
      "examples/my-app/docs/business-flow/onboarding/story/admin--create-user.md",
    );
  });

  it("resolves screen doc path", () => {
    const result = resolveDocPath("screen", "supplier-list", "examples/my-app");
    expect(result).toBe("examples/my-app/docs/screen/supplier-list.md");
  });

  it("resolves resolver doc path", () => {
    const result = resolveDocPath("resolver", "create-supplier", "examples/my-app");
    expect(result).toBe("examples/my-app/docs/resolver/create-supplier.md");
  });

  it("throws when name is missing", () => {
    expect(() => resolveDocPath("command", undefined, "modules/inventory")).toThrow(
      "Name is required",
    );
  });

  it("throws when story name is not flow/name format", () => {
    expect(() => resolveDocPath("story", "bad-name", "examples/my-app")).toThrow(
      "Story name must be",
    );
  });
});
