'use strict';

require('../../utils/types/array.cjs');
require('crypto');
var utils_inheritance = require('../../utils/inheritance.cjs');
require('bs58');
require('multiformats/bases/base58');
require('varint');
require('../../utils/encoding/ss-58.cjs');
var types_generic_typedEnum = require('./typed-enum.cjs');
var types_generic_typedStruct = require('./typed-struct.cjs');
require('../../utils/types/object.cjs');
require('../../utils/types/iterable.cjs');
require('../../utils/types/set.cjs');
require('blake2b');
require('../../utils/types/bytes.cjs');
require('../../utils/interfaces.cjs');
require('../../utils/assert.cjs');
require('../../utils/error.cjs');
require('../../utils/types/string.cjs');
require('./with-base.cjs');
require('./with-catch-null.cjs');
require('./with-eq.cjs');
require('./any-of.cjs');
require('./with-from.cjs');
require('./with-from-json-bytes.cjs');
require('./typed-null.cjs');
require('./create-placeholder.cjs');

/**
 * Extends supplied class which must be a successor of `TypedStruct`/`TypedEnum` by removing
 * its property.
 *
 * @template C
 * @template K
 * @param {C} klass
 * @param {string} prop
 * @param {K} PropClass
 * @param {function(*, string, K): *} handleNested
 * @returns {C}
 */
function withoutProp(klass, prop, handleNested = withoutProp) {
  const name = `withoutProp(${klass.name}, ${prop})`;
  const isStruct = utils_inheritance.isEqualToOrPrototypeOf(types_generic_typedStruct, klass);
  const isEnum = utils_inheritance.isEqualToOrPrototypeOf(types_generic_typedEnum, klass);
  if (!isStruct && !isEnum) {
    throw new Error(`Unexpected class provided: \`${klass}\``);
  }

  if (isStruct) {
    const { [prop]: _, ...classes } = klass.Classes;

    const obj = {
      [name]: class extends klass {
        static Classes = classes;
      },
    };

    return obj[name];
  } else {
    let classWithProp = klass.Class;
    let variants = klass.Variants;
    if (classWithProp != null) {
      classWithProp = handleNested(klass.Class, prop);
    } else {
      variants = variants.map((variant) => handleNested(variant, prop));
    }

    const obj = {
      [name]: class extends klass {
        static Class = classWithProp;

        static Variants = variants;
      },
    };

    return obj[name];
  }
}

module.exports = withoutProp;
//# sourceMappingURL=without-prop.cjs.map
