'use strict';

var types_generic_withFrom = require('./with-from.cjs');
require('../../utils/types/array.cjs');
var utils_types_bytes = require('../../utils/types/bytes.cjs');
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 utils_encoding_multibase = require('../../utils/encoding/multibase.cjs');
require('../../utils/types/object.cjs');
require('../../utils/types/iterable.cjs');
require('../../utils/types/set.cjs');
require('crypto');
require('../../utils/interfaces.cjs');
require('../../utils/assert.cjs');
require('../../utils/error.cjs');
require('../../utils/types/string.cjs');
require('blake2b');
require('./with-base.cjs');
require('./with-catch-null.cjs');
require('./with-eq.cjs');
require('./any-of.cjs');
require('./with-from-json-bytes.cjs');
require('./typed-null.cjs');
require('./create-placeholder.cjs');

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

  if (!utils_inheritance.isEqualToOrPrototypeOf(types_generic_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(utils_encoding_multibase.decodeFromMultibase(str));
        }

        toMultibaseBase58() {
          return utils_encoding_multibase.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(utils_types_bytes.u8aToString(utils_encoding_multibase.decodeFromMultibase(str))));
        }

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

    res = obj[name];
  }

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

module.exports = withMultibase;
//# sourceMappingURL=with-multibase.cjs.map
