{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thruput.se/agents/schemas/governance/rules.schema.json",
  "title": "Rules",
  "description": "The rules: entries whose parent is a principle, each opened by a marker and placed in a group",
  "type": "object",
  "required": [
    "rules"
  ],
  "properties": {
    "rules": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Rule"
      }
    }
  },
  "$defs": {
    "Rule": {
      "description": "One rule",
      "$ref": "entry.schema.json#/$defs/Entry",
      "required": [
        "marker",
        "group"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/RuleId"
        },
        "body": {
          "$ref": "#/$defs/DefinedProse"
        },
        "parent": {
          "$ref": "principles.schema.json#/$defs/PrincipleId"
        },
        "marker": {
          "enum": [
            "MUST",
            "MUST NOT"
          ]
        },
        "group": {
          "$ref": "#/$defs/Group"
        },
        "smells": {
          "$ref": "#/$defs/Smells"
        }
      }
    },
    "Smells": {
      "description": "Code smells that indicate this rule is being violated",
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/DefinedProse"
      }
    },
    "DefinedProse": {
      "description": "Markdown text citing at least one glossary definition in [[Id]] brackets",
      "$ref": "definitions.schema.json#/$defs/Prose",
      "$dynamicRef": "#CitedDefinition",
      "pattern": "^[^\\[]*(?:\\[[^\\[][^\\[]*)*\\[\\[[^\\[\\]]*[^\\[\\]\\s][^\\[\\]]*\\]\\][^\\[]*(?:(?:\\[\\[[^\\[\\]]*[^\\[\\]\\s][^\\[\\]]*\\]\\]|\\[[^\\[])[^\\[]*)*\\[?$"
    },
    "CitedDefinition": {
      "description": "Prose that cites at least one declared definition id. Accepts any prose on its own; the build binds the dynamic anchor to the pattern of every declared definition id",
      "$dynamicAnchor": "CitedDefinition"
    },
    "RuleId": {
      "$ref": "id.schema.json"
    },
    "Group": {
      "description": "The group a rule is placed in, by its name",
      "type": "string",
      "minLength": 1
    }
  },
  "examples": [
    {
      "rules": [
        {
          "id": "Example rule",
          "marker": "MUST",
          "group": "Example group",
          "parent": "Example principle",
          "body": "Name the [[Bad Code]] the example rule forbids."
        }
      ]
    }
  ]
}
