import withFrom from './with-from.js';
import '../../utils/types/array.js';
import { u8aToString } from '../../utils/types/bytes.js';
import { isEqualToOrPrototypeOf } from '../../utils/inheritance.js';
import 'bs58';
import 'multiformats/bases/base58';
import 'varint';
import '../../utils/encoding/ss-58.js';
import TypedEnum from './typed-enum.js';
import { decodeFromMultibase, encodeAsMultibase } from '../../utils/encoding/multibase.js';
import '../../utils/types/object.js';
import '../../utils/types/iterable.js';
import '../../utils/types/set.js';
import 'crypto';
import '../../utils/interfaces.js';
import '../../utils/assert.js';
import '../../utils/error.js';
import '../../utils/types/string.js';
import 'blake2b';
import './with-base.js';
import './with-catch-null.js';
import './with-eq.js';
import './any-of.js';
import './with-from-json-bytes.js';
import './typed-null.js';
import './create-placeholder.js';

function withMultibase(klass) {
  const name = `withMultibase(${klass.name})`;
  let res;

  if (!isEqualToOrPrototypeOf(TypedEnum, klass)) {
    const obj = {
      [name]: class extends klass {
        toString() {
          return this.toMultibaseBase58();
        }

        toJSON() {
          return String(this);
        }

        get value() {
          return this.toMultibaseBase58();
        }

        static fromMultibaseBase58(str) {
          return this.from(decodeFromMultibase(str));
        }

        toMultibaseBase58() {
          return encodeAsMultibase([], this.bytes);
        }
      },
    };

    res = obj[name];
  } else {
    const obj = {
      [name]: class extends klass {
        static Class = klass.Class;

        static Variants = !klass.Class
          ? klass.Variants?.map(withMultibase)
          : klass.Variants;

        toString() {
          return this.toMultibaseBase58();
        }

        static fromMultibaseBase58(str) {
          return this.fromJSON(JSON.parse(u8aToString(decodeFromMultibase(str))));
        }

        toMultibaseBase58() {
          return encodeAsMultibase([], this.bytes);
        }
      },
    };

    res = obj[name];
  }

  return withFrom(res, function from(value, fromFn) {
    return typeof value === 'string' ? this.fromMultibaseBase58(value) : fromFn(value);
  });
}

export { withMultibase as default };
//# sourceMappingURL=with-multibase.js.map
