'use strict';

require('../../generic/typed-enum.cjs');
require('../../generic/typed-bytes.cjs');
var types_generic_typedString = require('../../generic/typed-string.cjs');
require('../../generic/typed-array.cjs');
var types_generic_typedTuple = require('../../generic/typed-tuple.cjs');
require('../../generic/typed-null.cjs');
require('../../../utils/types/array.cjs');
require('crypto');
require('bs58');
require('multiformats/bases/base58');
require('varint');
require('../../../utils/encoding/ss-58.cjs');
var types_generic_typedNumber = require('../../generic/typed-number.cjs');
require('../../generic/typed-set.cjs');
require('../../generic/typed-map.cjs');
require('../../generic/typed-struct.cjs');
require('uuid');
require('js-sha256');
var types_generic_withQualifier = require('../../generic/with-qualifier.cjs');
var types_generic_utils = require('../../generic/utils.cjs');
var types_did_onchain_typedDid_index = require('../onchain/typed-did/index.cjs');
var types_did_onchain_typedDid_cheqdDid = require('../onchain/typed-did/cheqd-did.cjs');
require('../../../utils/types/iterable.cjs');
require('../../../utils/types/object.cjs');
require('../../../utils/interfaces.cjs');
require('../../../utils/assert.cjs');
require('../../../utils/error.cjs');
require('../../../utils/inheritance.cjs');
require('../../../utils/types/set.cjs');
require('../../generic/with-base.cjs');
require('../../../utils/types/bytes.cjs');
require('../../../utils/types/string.cjs');
require('../../generic/with-catch-null.cjs');
require('../../generic/with-eq.cjs');
require('../../generic/any-of.cjs');
require('../../generic/with-from.cjs');
require('../../generic/with-from-json-bytes.cjs');
require('blake2b');
require('../../generic/create-placeholder.cjs');
require('../../generic/typed-bytes-array.cjs');
require('../onchain/typed-did/did-method-key/did-method-key-public-key.cjs');
require('../../../utils/encoding/base-58-btc.cjs');
require('../../generic/sized.cjs');
require('../../../utils/types/number.cjs');
require('../../public-keys/public-key.cjs');
require('../../public-keys/public-key-x25519-value.cjs');
require('../../public-keys/public-key-ed25519-value.cjs');
require('../../../vc/crypto/constants.cjs');
require('../../public-keys/public-key-secp256k1-value.cjs');
require('../../public-keys/public-key-sr25519-value.cjs');
require('../onchain/constants.cjs');
require('../onchain/typed-did/signature.cjs');
require('../onchain/typed-did/did-method-key/did-method-key-signature.cjs');
require('../../signatures/signature-value.cjs');
require('../../signatures/signature-ed25519-value.cjs');
require('../../signatures/signature-secp256k1-value.cjs');
require('../../signatures/signature.cjs');
require('../../signatures/signature-sr25519-value.cjs');
require('../onchain/typed-did/dock-did-value.cjs');
require('../../generic/typed-uuid.cjs');

class VerificationMethodRef extends types_generic_withQualifier(types_generic_typedTuple) {
  static Qualifier = '';

  static Classes = [types_did_onchain_typedDid_index.NamespaceDid, types_generic_typedNumber, types_generic_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 = [types_did_onchain_typedDid_index.CheqdNamespaceDid, types_generic_typedNumber, types_generic_typedString];
}

class DockVerificartionMethodRef extends VerificationMethodRef {
  static Classes = [types_did_onchain_typedDid_index.DockNamespaceDid, types_generic_typedNumber, types_generic_typedString];
}

class CheqdTestnetVerificationMethodRef extends CheqdVerificationMethodRef {
  static Classes = [types_did_onchain_typedDid_cheqdDid.CheqdTestnetDid, types_generic_typedNumber, types_generic_typedString];
}

class CheqdMainnetVerificationMethodRef extends CheqdVerificationMethodRef {
  static Classes = [types_did_onchain_typedDid_cheqdDid.CheqdMainnetDid, types_generic_typedNumber, types_generic_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 = types_generic_utils.createConverter(
  String,
  DockVerificartionMethodRef,
  CheqdTestnetVerificationMethodRef,
  CheqdMainnetVerificationMethodRef,
);

exports.CheqdMainnetVerificationMethodRef = CheqdMainnetVerificationMethodRef;
exports.CheqdTestnetVerificationMethodRef = CheqdTestnetVerificationMethodRef;
exports.CheqdVerificationMethodRef = CheqdVerificationMethodRef;
exports.DockVerificartionMethodRef = DockVerificartionMethodRef;
exports.VerificationMethodRef = VerificationMethodRef;
exports.possibleVerificationMethodRefs = possibleVerificationMethodRefs;
//# sourceMappingURL=verification-method-ref.cjs.map
