const ERROR = Object.freeze({
  BAD_INPUT: { error_id: "ERR_BAD_INPUT", message: "Invalid input." },
  BAD_CONFIG: { error_id: "ERR_BAD_CONFIG", message: "Invalid configuration." },
  NETWORK_ATTEMPT: { error_id: "ERR_NETWORK_ATTEMPT", message: "External network access is not allowed." },
  MERMAID_NO_TEXT: { error_id: "ERR_MERMAID_NO_TEXT", message: "Mermaid output must contain selectable text." },
  MERMAID_FOREIGN_OBJECT: { error_id: "ERR_MERMAID_FOREIGN_OBJECT", message: "Mermaid output contains forbidden elements." },
  TIMEOUT: { error_id: "ERR_TIMEOUT", message: "Render timed out." },
  INTERNAL: { error_id: "ERR_INTERNAL", message: "Render failed." }
});

function asFailure(errorDef, detailsCode) {
  return {
    error_id: errorDef.error_id,
    message: errorDef.message,
    ...(detailsCode ? { details_code: detailsCode } : {})
  };
}

module.exports = { ERROR, asFailure };

