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 'bs58';
import 'multiformats/bases/base58';
import 'varint';
import { decodeFromBase64, encodeAsBase64 } from '../../utils/encoding/base-64.js';
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 '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 withBase64(klass) {
  const name = `withBase64(${klass.name})`;
  let res;

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

        toJSON() {
          return String(this);
        }

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

        static fromBase64(str) {
          return this.from(decodeFromBase64(str));
        }

        toBase64() {
          return encodeAsBase64(this.bytes);
        }
      },
    };

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

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

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

        static fromBase64(str) {
          return this.fromJSON(JSON.parse(u8aToString(decodeFromBase64(str))));
        }

        toBase64() {
          return encodeAsBase64(this.bytes);
        }

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

    res = obj[name];
  }

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

export { withBase64 as default };
//# sourceMappingURL=with-base64.js.map
