import type { Column } from "../graph";

/** E-R entity layout dimensions for ELK spacing. */
export const ER_SIZES = {
  entity: {
    w: 260,
    headerH: 36,
    rowH: 24,
    paddingY: 8,
    minRows: 1,
  },
} as const;

/** Compute entity height based on column count for ELK layout. */
export function getErEntityHeight(columns?: Column[]): number {
  const rows = Math.max(
    ER_SIZES.entity.minRows,
    columns?.length ?? 0,
  );
  return (
    ER_SIZES.entity.headerH +
    rows * ER_SIZES.entity.rowH +
    ER_SIZES.entity.paddingY * 2
  );
}

/** Map DiagramNode.type (with or without er: prefix) to @xyflow/react node type string. */
export function resolveErNodeType(type: string): string {
  const bare = type.startsWith("er:") ? type.slice(3) : type;
  switch (bare) {
    case "entity":
    default:
      return "erEntity";
  }
}

/** Map DiagramEdge.type to @xyflow/react edge type string for E-R diagrams. */
export function resolveErEdgeType(_type: string | undefined): string {
  return "erRelationship";
}
