···11+import type { IR } from '~/ir/types';
22+33+import type { HeyApiSdkPlugin } from '../types';
44+import { SdkClassModel } from './class';
55+66+export class SdkStructureModel {
77+ /** Name of the SDK. If empty, we fallback to operation tags. */
88+ private _name: string;
99+1010+ /** Root classes mapped by their names. */
1111+ roots: Map<string, SdkClassModel> = new Map();
1212+1313+ constructor(name: string) {
1414+ this._name = name;
1515+ }
1616+1717+ /**
1818+ * Inserts an operation into the structure.
1919+ *
2020+ * Parses the operation ID and organizes it into classes based on tags.
2121+ */
2222+ insert(
2323+ operation: IR.OperationObject,
2424+ plugin: HeyApiSdkPlugin['Instance'],
2525+ ): void {
2626+ const roots = this._name ? [this._name] : (operation.tags ?? ['default']);
2727+2828+ for (const name of roots) {
2929+ const model = this.root(name);
3030+ model.insert(operation, plugin);
3131+ }
3232+ }
3333+3434+ /**
3535+ * Gets or creates a root class by name.
3636+ *
3737+ * If the root doesn't exist, it's created automatically.
3838+ *
3939+ * @param name - The name of the root class
4040+ * @returns The root class instance
4141+ */
4242+ root(name: string): SdkClassModel {
4343+ if (!this.roots.has(name)) {
4444+ this.roots.set(name, new SdkClassModel(name));
4545+ }
4646+ return this.roots.get(name)!;
4747+ }
4848+4949+ /**
5050+ * Recursively walks the structure.
5151+ *
5252+ * Yields all classes in the structure.
5353+ */
5454+ *walk(): Generator<SdkClassModel> {
5555+ for (const model of this.roots.values()) {
5656+ yield* model.walk();
5757+ }
5858+ }
5959+}
···66666767/**
6868 * Returns a list of classes where this operation appears in the generated SDK.
6969+ *
7070+ * @deprecated
6971 */
7072export const operationClasses = ({
7173 operation,