var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var og_exports = {};
__export(og_exports, {
  auditor: () => auditor,
  resultWithValidationResultMessages: () => resultWithValidationResultMessages
});
module.exports = __toCommonJS(og_exports);
var import_for_each = __toESM(require("@babel/runtime-corejs3/core-js/instance/for-each"));
var import_entries = __toESM(require("@babel/runtime-corejs3/core-js/object/entries"));
var import_map = __toESM(require("@babel/runtime-corejs3/core-js/instance/map"));
var import_bind = __toESM(require("@babel/runtime-corejs3/core-js/instance/bind"));
var import_discord = require("./auditors/discord");
var import_facebook = require("./auditors/facebook");
var import_generic = require("./auditors/generic");
var import_linkedin = require("./auditors/linkedin");
var import_slack = require("./auditors/slack");
var import_twitter = require("./auditors/twitter");
const PROVIDERS = ["GENERIC", "DISCORD", "FACEBOOK", "LINKEDIN", "SLACK", "TWITTER"];
const formatMessages = (validationResult) => {
  var _context;
  const messages = [];
  const formatted = validationResult["error"].format();
  (0, import_for_each.default)(_context = (0, import_entries.default)(formatted)).call(_context, ([key, value]) => {
    if (key !== "_errors") {
      const errors = value["_errors"] || [];
      messages.push(`${key}: ${errors.join(", ")}`);
    }
  });
  return messages;
};
const getProviderAuditor = (provider) => {
  switch (provider) {
    case "DISCORD":
      return import_discord.DiscordAuditor;
      break;
    case "FACEBOOK":
      return import_facebook.FacebookAuditor;
      break;
    case "LINKEDIN":
      return import_linkedin.LinkedInAuditor;
      break;
    case "SLACK":
      return import_slack.SlackAuditor;
      break;
      break;
    case "TWITTER":
      return import_twitter.TwitterAuditor;
      break;
    default:
      return import_generic.GenericAuditor;
  }
};
const auditForProvider = (result, provider) => {
  const auditResult = getProviderAuditor(provider).safeParse(result);
  if (!auditResult.success) {
    return {
      provider,
      audit: {
        severity: "WARNING",
        messages: formatMessages(auditResult)
      }
    };
  }
  return {
    provider,
    audit: {
      severity: "OK",
      messages: ["All required tags provided."]
    }
  };
};
const auditor = (result, error) => {
  if (error) {
    return {
      audits: (0, import_map.default)(PROVIDERS).call(PROVIDERS, (provider) => ({
        provider,
        audit: {
          severity: "ERROR",
          messages: ["Unable to preview"]
        }
      })),
      auditedResult: result
    };
  }
  const audits = (0, import_map.default)(PROVIDERS).call(PROVIDERS, (provider) => auditForProvider(result, provider));
  return {
    audits,
    auditedResult: resultWithValidationResultMessages(audits, result)
  };
};
const resultWithValidationResultMessages = (audits, result) => {
  var _context2, _context3;
  const validationMessages = [];
  const providers = [];
  ((_context2 = audits) == null ? void 0 : (0, import_bind.default)(_context3 = Function.call).call(_context3, (0, import_map.default)(_context2), _context2))?.((providerAudit) => {
    const {
      provider,
      audit
    } = providerAudit;
    if (audit) {
      const {
        severity,
        messages
      } = audit;
      if (severity !== "OK") {
        providers.push(provider);
        validationMessages.push(messages);
      }
    }
  });
  if (validationMessages.length > 0) {
    result.success = false;
    result.error = `Audit failed for ${providers.join(", ")}. ${validationMessages.join(", ")}`;
  }
  return result;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  auditor,
  resultWithValidationResultMessages
});
//# sourceMappingURL=og.js.map
