'use strict';

var utils_ident_matchers = require('./matchers.cjs');
var utils_types_string = require('../types/string.cjs');

/**
 * Ensures that the given string is a valid URI. If not, throws an error.
 *
 * @param {string} uri - The URI string to validate.
 */
function ensureURI(uri) {
  if (utils_ident_matchers.URI_MATCHER.test(utils_types_string.ensureString(uri))) {
    return uri;
  }

  throw new Error(`${uri} needs to be a valid URI.`);
}

/**
 * Ensures that the given string is a valid StatusList2021Credential identifier. Throws an error if not.
 *
 * @param {string} statusListId - The identifier string to validate.
 */
function ensureStatusListId(statusListId) {
  if (utils_ident_matchers.STATUS_LIST_ID_MATCHER.test(utils_types_string.ensureString(statusListId))) {
    return statusListId;
  }

  throw new Error(
    `\`${statusListId}\` needs to be a valid \`StatusList2021Credential\` identifier.`,
  );
}

/**
 * Ensures that the given string is a valid PrivateStatusList2021Credential identifier. Throws an error if not.
 *
 * @param {string} statusListId - The identifier string to validate.
 */
function ensurePrivateStatusListId(statusListId) {
  if (utils_ident_matchers.PRIVATE_STATUS_LIST_ID_MATCHER.test(utils_types_string.ensureString(statusListId))) {
    return statusListId;
  }

  throw new Error(
    `\`${statusListId}\` needs to be a valid \`PrivateStatusList2021Credential\` identifier.`,
  );
}

/**
 * Ensures that the given string is a valid datetime according to RFC3339 format. Throws an error if not.
 *
 * @param {string} datetime - The datetime string to validate.
 * @returns {string} - The original datetime string if it's valid.
 */
function ensureValidDatetime(datetime) {
  if (utils_ident_matchers.DATETIME_MATCHER.test(utils_types_string.ensureString(datetime))) {
    return datetime;
  }

  throw new TypeError(`${datetime} needs to be a valid datetime.`);
}

exports.ensurePrivateStatusListId = ensurePrivateStatusListId;
exports.ensureStatusListId = ensureStatusListId;
exports.ensureURI = ensureURI;
exports.ensureValidDatetime = ensureValidDatetime;
//# sourceMappingURL=ensure-ident.cjs.map
