import withFrom from './with-from.js';
import '../../utils/types/array.js';
import { u8aToString, stringToU8a } from '../../utils/types/bytes.js';
import { maybeToJSONString } from '../../utils/interfaces.js';
import { isEqualToOrPrototypeOf } from '../../utils/inheritance.js';
import { decodeFromBase58, encodeAsBase58 } from '../../utils/encoding/base-58.js';
import 'multiformats/bases/base58';
import 'varint';
import '../../utils/encoding/ss-58.js';
import TypedEnum from './typed-enum.js';
import '../../utils/types/object.js';
import '../../utils/types/iterable.js';
import '../../utils/types/set.js';
import 'crypto';
import '../../utils/types/string.js';
import '../../utils/assert.js';
import '../../utils/error.js';
import 'bs58';
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 withBase58(klass) {
  const name = `withBase58(${klass.name})`;
  let res;

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

        toJSON() {
          return String(this);
        }

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

        static fromBase58(str) {
          return this.from(decodeFromBase58(str));
        }

        toBase58() {
          return encodeAsBase58(this.bytes);
        }
      },
    };

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

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

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

        static fromBase58(str) {
          return this.fromJSON(JSON.parse(u8aToString(decodeFromBase58(str))));
        }

        toBase58() {
          return encodeAsBase58(this.bytes);
        }

        get bytes() {
          return stringToU8a(maybeToJSONString(this));
        }
      },
    };

    res = obj[name];
  }

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

export { withBase58 as default };
//# sourceMappingURL=with-base58.js.map
