import '../../generic/typed-enum.js';
import '../../generic/typed-bytes.js';
import TypedString from '../../generic/typed-string.js';
import '../../generic/typed-array.js';
import TypedTuple from '../../generic/typed-tuple.js';
import '../../generic/typed-null.js';
import '../../../utils/types/array.js';
import 'crypto';
import 'bs58';
import 'multiformats/bases/base58';
import 'varint';
import '../../../utils/encoding/ss-58.js';
import TypedNumber from '../../generic/typed-number.js';
import '../../generic/typed-set.js';
import '../../generic/typed-map.js';
import '../../generic/typed-struct.js';
import 'uuid';
import 'js-sha256';
import withQualifier from '../../generic/with-qualifier.js';
import { createConverter } from '../../generic/utils.js';
import { NamespaceDid, DockNamespaceDid, CheqdNamespaceDid } from '../onchain/typed-did/index.js';
import { CheqdMainnetDid, CheqdTestnetDid } from '../onchain/typed-did/cheqd-did.js';
import '../../../utils/types/iterable.js';
import '../../../utils/types/object.js';
import '../../../utils/interfaces.js';
import '../../../utils/assert.js';
import '../../../utils/error.js';
import '../../../utils/inheritance.js';
import '../../../utils/types/set.js';
import '../../generic/with-base.js';
import '../../../utils/types/bytes.js';
import '../../../utils/types/string.js';
import '../../generic/with-catch-null.js';
import '../../generic/with-eq.js';
import '../../generic/any-of.js';
import '../../generic/with-from.js';
import '../../generic/with-from-json-bytes.js';
import 'blake2b';
import '../../generic/create-placeholder.js';
import '../../generic/typed-bytes-array.js';
import '../onchain/typed-did/did-method-key/did-method-key-public-key.js';
import '../../../utils/encoding/base-58-btc.js';
import '../../generic/sized.js';
import '../../../utils/types/number.js';
import '../../public-keys/public-key.js';
import '../../public-keys/public-key-x25519-value.js';
import '../../public-keys/public-key-ed25519-value.js';
import '../../../vc/crypto/constants.js';
import '../../public-keys/public-key-secp256k1-value.js';
import '../../public-keys/public-key-sr25519-value.js';
import '../onchain/constants.js';
import '../onchain/typed-did/signature.js';
import '../onchain/typed-did/did-method-key/did-method-key-signature.js';
import '../../signatures/signature-value.js';
import '../../signatures/signature-ed25519-value.js';
import '../../signatures/signature-secp256k1-value.js';
import '../../signatures/signature.js';
import '../../signatures/signature-sr25519-value.js';
import '../onchain/typed-did/dock-did-value.js';
import '../../generic/typed-uuid.js';

class VerificationMethodRef extends withQualifier(TypedTuple) {
  static Qualifier = '';

  static Classes = [NamespaceDid, TypedNumber, TypedString];

  get did() {
    return this[0];
  }

  get index() {
    return this[1];
  }

  get keyIdentifier() {
    return this[2] || 'keys';
  }

  constructor(did, index, keyIdentifier = 'keys') {
    super(did, index, keyIdentifier);
  }

  static fromUnqualifiedString(str) {
    const regex = new RegExp(`^${this.Qualifier}([^#]+)#([^\\-]+)-(\\d+)$`);
    const match = str.match(regex);

    if (!match) {
      throw new Error(`Invalid format for VerificationMethodRef: \`${str}\``);
    }

    const [, did, keyIdentifier, index] = match;
    return new this(did, parseInt(index, 10), keyIdentifier);
  }

  toEncodedString() {
    const { did, index, keyIdentifier } = this;

    return `${did}#${keyIdentifier}-${index}`;
  }

  toCheqdPayload() {
    return this.toEncodedString();
  }

  toJSON() {
    return this.toEncodedString();
  }
}

class CheqdVerificationMethodRef extends VerificationMethodRef {
  static Classes = [CheqdNamespaceDid, TypedNumber, TypedString];
}

class DockVerificartionMethodRef extends VerificationMethodRef {
  static Classes = [DockNamespaceDid, TypedNumber, TypedString];
}

class CheqdTestnetVerificationMethodRef extends CheqdVerificationMethodRef {
  static Classes = [CheqdTestnetDid, TypedNumber, TypedString];
}

class CheqdMainnetVerificationMethodRef extends CheqdVerificationMethodRef {
  static Classes = [CheqdMainnetDid, TypedNumber, TypedString];
}

/**
 * Retrieve all possible stringified representations of DIDs that can be derived from the provided Dock verification method reference.
 *
 * @param {*} verMethodRef
 * @returns {Array<string>}
 */
const possibleVerificationMethodRefs = createConverter(
  String,
  DockVerificartionMethodRef,
  CheqdTestnetVerificationMethodRef,
  CheqdMainnetVerificationMethodRef,
);

export { CheqdMainnetVerificationMethodRef, CheqdTestnetVerificationMethodRef, CheqdVerificationMethodRef, DockVerificartionMethodRef, VerificationMethodRef, possibleVerificationMethodRefs };
//# sourceMappingURL=verification-method-ref.js.map
