import { describe, it, expect } from "vitest";
import { parseModelDoc } from "./parse-model-doc";

describe("parseModelDoc", () => {
  it("extracts model name and transitions", () => {
    const md = `# Product

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

| Operation | From | To | Command |
|-----------|------|----|---------|
| activate | DRAFT | ACTIVE | ActivateProduct |
| cancel | DRAFT, ACTIVE | CANCELLED | CancelProduct |
`;

    const parsed = parseModelDoc("Product", md);

    expect(parsed.modelName).toBe("Product");
    expect(parsed.transitions).toEqual([
      { operation: "activate", from: ["DRAFT"], to: "ACTIVE", command: "ActivateProduct" },
      { operation: "cancel", from: ["DRAFT", "ACTIVE"], to: "CANCELLED", command: "CancelProduct" },
    ]);
  });

  it("returns empty transitions for non-stateful models", () => {
    const md = `# PurchaseOrderLine

## Domain Model Definitions

### Model type

Entity
`;

    const parsed = parseModelDoc("PurchaseOrderLine", md);
    expect(parsed.transitions).toEqual([]);
  });
});
