import { describe, expect, it } from "vitest";
import { generateLifecycle } from "./generate-lifecycle";
import type { ParsedTransition } from "./parse-model-doc";

describe("generateLifecycle", () => {
  it("generates defineLifecycle with transitions and state type", () => {
    const transitions: ParsedTransition[] = [
      { operation: "activate", from: ["draft"], to: "active", command: "activateItem" },
      {
        operation: "deactivate",
        from: ["active", "suspended"],
        to: "inactive",
        command: "deactivateItem",
      },
    ];

    const result = generateLifecycle("Item", transitions);

    expect(result).toContain("// @generated — do not edit");
    expect(result).toContain('import { defineLifecycle } from "@tailor-platform/erp-kit/core";');
    expect(result).toContain("export const itemLifecycle = defineLifecycle({");
    expect(result).toContain('    activate: { from: ["draft"], to: "active" },');
    expect(result).toContain('    deactivate: { from: ["active", "suspended"], to: "inactive" },');
    expect(result).toContain("export type ItemStatus = typeof itemLifecycle.states[number];");
  });
});
