// SPDX-License-Identifier: Apache-2.0

/**
 * Copies own-prototype methods from each holder class onto a target class,
 * implementing the mixin assembly for the EVMChainAdapter split. Holder
 * classes define cohesive method groups (extending `EVMChainAdapterBase` for
 * shared `this` state); `EVMChainAdapter` merges their declarations via
 * `interface EVMChainAdapter extends ...` and adopts their implementations at
 * module load via this helper.
 *
 * Standard TS handbook mixin pattern. `constructor` is skipped — EVMChainAdapter
 * keeps its own (inherited from EVMChainAdapterBase).
 */
export function applyMixins(derivedCtor: { prototype: object }, holders: Array<{ prototype: object }>): void {
  for (const holder of holders) {
    for (const propName of Object.getOwnPropertyNames(holder.prototype)) {
      if (propName === 'constructor') continue;
      const descriptor = Object.getOwnPropertyDescriptor(holder.prototype, propName);
      if (descriptor) {
        Object.defineProperty(derivedCtor.prototype, propName, descriptor);
      }
    }
  }
}
