/** Shared invisible handle style — extracted to avoid object allocation on every render. */
export const HIDDEN_HANDLE = { opacity: 0 } as const;

/** Architecture diagram node dimensions for ELK layout spacing. */
export const ARCH_SIZES = {
  service: { w: 200, h: 80 },
  database: { w: 160, h: 100 },
  queue: { w: 180, h: 70 },
  loadbalancer: { w: 120, h: 120 },
  external: { w: 180, h: 80 },
} as const;

const ARCH_TYPE_MAP: Record<string, { w: number; h: number }> = {
  archService: ARCH_SIZES.service,
  archDatabase: ARCH_SIZES.database,
  archQueue: ARCH_SIZES.queue,
  archLoadBalancer: ARCH_SIZES.loadbalancer,
  archExternal: ARCH_SIZES.external,
};

/** Get architecture node dimensions by @xyflow/react node type. Returns null if not an architecture type. */
export function getArchNodeSize(
  flowType: string | undefined,
): { w: number; h: number } | null {
  if (!flowType) return null;
  return ARCH_TYPE_MAP[flowType] ?? null;
}

/** Map DiagramNode.type (with or without arch: prefix) to @xyflow/react node type string. */
export function resolveArchitectureNodeType(type: string): string {
  const bare = type.startsWith("arch:") ? type.slice(5) : type;
  switch (bare) {
    case "service":
      return "archService";
    case "database":
      return "archDatabase";
    case "queue":
      return "archQueue";
    case "loadbalancer":
      return "archLoadBalancer";
    case "external":
      return "archExternal";
    default:
      return "archService";
  }
}

/** Map DiagramEdge.type to @xyflow/react edge type string for architecture diagrams. */
export function resolveArchitectureEdgeType(
  _type: string | undefined,
): string {
  return "archConnection";
}
