const ACTION_TYPES = [
  "ALLOW_TRANSITION",
  "BLOCK_TRANSITION",
  "LOG",
  "SHOW_ERROR",
  "SHOW_WARNING",
  "SHOW_INFO",
  "NOTIFY",
  "SET_FIELD",
  "CALL_WEBHOOK",
  "EMIT_EVENT"
];
function getActionTypeOptions(t) {
  return [
    { value: "ALLOW_TRANSITION", label: t("business_rules.validation.actionTypes.ALLOW_TRANSITION") },
    { value: "BLOCK_TRANSITION", label: t("business_rules.validation.actionTypes.BLOCK_TRANSITION") },
    { value: "LOG", label: t("business_rules.validation.actionTypes.LOG") },
    { value: "SHOW_ERROR", label: t("business_rules.validation.actionTypes.SHOW_ERROR") },
    { value: "SHOW_WARNING", label: t("business_rules.validation.actionTypes.SHOW_WARNING") },
    { value: "SHOW_INFO", label: t("business_rules.validation.actionTypes.SHOW_INFO") },
    { value: "NOTIFY", label: t("business_rules.validation.actionTypes.NOTIFY") },
    { value: "SET_FIELD", label: t("business_rules.validation.actionTypes.SET_FIELD") },
    { value: "CALL_WEBHOOK", label: t("business_rules.validation.actionTypes.CALL_WEBHOOK") },
    { value: "EMIT_EVENT", label: t("business_rules.validation.actionTypes.EMIT_EVENT") }
  ];
}
function getRequiredConfigFields(actionType) {
  switch (actionType) {
    case "LOG":
    case "SHOW_ERROR":
    case "SHOW_WARNING":
    case "SHOW_INFO":
      return ["message"];
    case "NOTIFY":
      return ["message", "recipients"];
    case "SET_FIELD":
      return ["field", "value"];
    case "CALL_WEBHOOK":
      return ["url"];
    case "EMIT_EVENT":
      return ["eventName"];
    case "ALLOW_TRANSITION":
    case "BLOCK_TRANSITION":
    default:
      return [];
  }
}
function getOptionalConfigFields(actionType) {
  switch (actionType) {
    case "LOG":
      return ["level"];
    case "NOTIFY":
      return ["template"];
    case "CALL_WEBHOOK":
      return ["method", "headers", "body"];
    case "EMIT_EVENT":
      return ["payload"];
    default:
      return [];
  }
}
function validateAction(action, t) {
  const errors = [];
  const translate = t || ((key) => key);
  if (!action) {
    errors.push(translate("business_rules.validation.action.required"));
    return { valid: false, errors };
  }
  if (!action.type || typeof action.type !== "string") {
    errors.push(translate("business_rules.validation.action.typeRequired"));
  } else if (!ACTION_TYPES.includes(action.type)) {
    errors.push(translate("business_rules.validation.action.unknownType", { type: action.type, validTypes: ACTION_TYPES.join(", ") }));
  }
  const requiredFields = getRequiredConfigFields(action.type);
  if (requiredFields.length > 0) {
    if (!action.config) {
      errors.push(translate("business_rules.validation.action.configRequired", { type: action.type, fields: requiredFields.join(", ") }));
    } else {
      requiredFields.forEach((field) => {
        if (!action.config[field]) {
          errors.push(translate("business_rules.validation.action.fieldMissing", { field }));
        }
      });
    }
  }
  return {
    valid: errors.length === 0,
    errors
  };
}
function validateActionConfig(actionType, config, t) {
  const errors = [];
  const translate = t || ((key) => key);
  const requiredFields = getRequiredConfigFields(actionType);
  if (requiredFields.length > 0 && !config) {
    errors.push(translate("business_rules.validation.action.configRequiredForType", { type: actionType }));
    return { valid: false, errors };
  }
  if (config) {
    requiredFields.forEach((field) => {
      if (!config[field]) {
        errors.push(translate("business_rules.validation.action.fieldMissingShort", { field }));
      }
    });
  }
  return {
    valid: errors.length === 0,
    errors
  };
}
function validateActions(actions, t) {
  if (!actions || actions.length === 0) {
    return { valid: true, errors: [] };
  }
  const errors = [];
  const translate = t || ((key) => key);
  actions.forEach((action, index) => {
    const result = validateAction(action, t);
    if (!result.valid) {
      errors.push(translate("business_rules.validation.action.indexError", { index: index + 1, errors: result.errors.join(", ") }));
    }
  });
  return {
    valid: errors.length === 0,
    errors
  };
}
export {
  ACTION_TYPES,
  getActionTypeOptions,
  getOptionalConfigFields,
  getRequiredConfigFields,
  validateAction,
  validateActionConfig,
  validateActions
};
//# sourceMappingURL=actionValidation.js.map
