import { describe, it, expect } from "vitest";
import {
  FLOW_SIZES,
  resolveFlowchartNodeType,
  resolveFlowchartEdgeType,
  getFlowNodeSize,
} from "./constants";

describe("FLOW_SIZES", () => {
  it("should define sizes for all 5 flowchart node subtypes", () => {
    expect(FLOW_SIZES.process).toEqual({ w: 160, h: 60 });
    expect(FLOW_SIZES.decision).toEqual({ w: 140, h: 130 });
    expect(FLOW_SIZES.terminal).toEqual({ w: 140, h: 50 });
    expect(FLOW_SIZES.io).toEqual({ w: 160, h: 60 });
    expect(FLOW_SIZES.subprocess).toEqual({ w: 160, h: 60 });
  });
});

describe("resolveFlowchartNodeType", () => {
  it("should resolve flow:process to flowProcess", () => {
    expect(resolveFlowchartNodeType("flow:process")).toBe("flowProcess");
  });

  it("should resolve flow:decision to flowDecision", () => {
    expect(resolveFlowchartNodeType("flow:decision")).toBe("flowDecision");
  });

  it("should resolve flow:terminal to flowTerminal", () => {
    expect(resolveFlowchartNodeType("flow:terminal")).toBe("flowTerminal");
  });

  it("should resolve flow:io to flowIo", () => {
    expect(resolveFlowchartNodeType("flow:io")).toBe("flowIo");
  });

  it("should resolve flow:subprocess to flowSubprocess", () => {
    expect(resolveFlowchartNodeType("flow:subprocess")).toBe("flowSubprocess");
  });

  it("should resolve bare type without prefix", () => {
    expect(resolveFlowchartNodeType("process")).toBe("flowProcess");
    expect(resolveFlowchartNodeType("decision")).toBe("flowDecision");
    expect(resolveFlowchartNodeType("terminal")).toBe("flowTerminal");
    expect(resolveFlowchartNodeType("io")).toBe("flowIo");
    expect(resolveFlowchartNodeType("subprocess")).toBe("flowSubprocess");
  });

  it("should default unknown types to flowProcess", () => {
    expect(resolveFlowchartNodeType("unknown")).toBe("flowProcess");
    expect(resolveFlowchartNodeType("flow:unknown")).toBe("flowProcess");
  });
});

describe("resolveFlowchartEdgeType", () => {
  it("should always return flowEdge", () => {
    expect(resolveFlowchartEdgeType("sequence")).toBe("flowEdge");
    expect(resolveFlowchartEdgeType("conditional")).toBe("flowEdge");
    expect(resolveFlowchartEdgeType(undefined)).toBe("flowEdge");
  });
});

describe("getFlowNodeSize", () => {
  it("should return correct size for flowProcess", () => {
    expect(getFlowNodeSize("flowProcess")).toEqual({ w: 160, h: 60 });
  });

  it("should return correct size for flowDecision", () => {
    expect(getFlowNodeSize("flowDecision")).toEqual({ w: 140, h: 130 });
  });

  it("should return correct size for flowTerminal", () => {
    expect(getFlowNodeSize("flowTerminal")).toEqual({ w: 140, h: 50 });
  });

  it("should return correct size for flowIo", () => {
    expect(getFlowNodeSize("flowIo")).toEqual({ w: 160, h: 60 });
  });

  it("should return correct size for flowSubprocess", () => {
    expect(getFlowNodeSize("flowSubprocess")).toEqual({ w: 160, h: 60 });
  });

  it("should return null for non-flowchart types", () => {
    expect(getFlowNodeSize("archService")).toBeNull();
    expect(getFlowNodeSize("erEntity")).toBeNull();
    expect(getFlowNodeSize("default")).toBeNull();
    expect(getFlowNodeSize(undefined)).toBeNull();
  });
});
