{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.internal/paddock/drill-authoring.schema.json",
  "title": "DrillAuthoringV2",
  "type": "object",
  "required": [
    "version",
    "drillId",
    "doctrineId",
    "title",
    "ruleText",
    "factPattern",
    "entityRegistry",
    "factTable",
    "elements",
    "propositions",
    "conceptLibraryRefs"
  ],
  "properties": {
    "version": {
      "type": "string",
      "const": "2.0"
    },
    "drillId": {
      "type": "string"
    },
    "doctrineId": {
      "type": "string"
    },
    "title": {
      "type": "string"
    },
    "ruleText": {
      "type": "string"
    },
    "factPattern": {
      "type": "string"
    },
    "entityRegistry": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/entity"
      }
    },
    "factTable": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/factAtom"
      }
    },
    "elements": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/element"
      }
    },
    "propositions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/proposition"
      }
    },
    "conceptLibraryRefs": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "pedagogy": {
      "type": "object",
      "properties": {
        "ruleExplanation": {
          "type": "string"
        },
        "formulaScaffold": {
          "type": "string"
        },
        "commonMistakes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    }
  },
  "$defs": {
    "entity": {
      "type": "object",
      "required": [
        "id",
        "type",
        "display",
        "aliases"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "person",
            "organization",
            "court",
            "proceeding",
            "amount",
            "date",
            "statute",
            "other"
          ]
        },
        "display": {
          "type": "string"
        },
        "aliases": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "roles": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "attributes": {
          "type": "object"
        }
      },
      "additionalProperties": false
    },
    "factAtom": {
      "type": "object",
      "required": [
        "id",
        "subjectId",
        "predicate"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "subjectId": {
          "type": "string"
        },
        "predicate": {
          "type": "string"
        },
        "objectId": {
          "type": "string"
        },
        "objectLiteral": {
          "type": [
            "string",
            "number",
            "boolean"
          ]
        }
      },
      "oneOf": [
        {
          "required": [
            "objectId"
          ]
        },
        {
          "required": [
            "objectLiteral"
          ]
        }
      ],
      "additionalProperties": false
    },
    "slot": {
      "type": "object",
      "required": [
        "id",
        "name",
        "kind",
        "minConfidence"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "kind": {
          "type": "string",
          "enum": [
            "entity",
            "role",
            "proceeding",
            "forum",
            "legal_claim",
            "action",
            "state",
            "outcome",
            "amount",
            "date",
            "relation",
            "polarity"
          ]
        },
        "conceptIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "entityIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "roleNames": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "requiresAllConceptIds": {
          "type": "boolean",
          "default": false
        },
        "minConfidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "weight": {
          "type": "number",
          "minimum": 0
        },
        "disallowAliases": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "notes": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "proposition": {
      "type": "object",
      "required": [
        "id",
        "elementId",
        "circleLabel",
        "canonical",
        "kind",
        "requiredSlots",
        "positives",
        "paraphrasePositives",
        "nearMisses",
        "fillerNegatives",
        "whyMatters"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "elementId": {
          "type": "string"
        },
        "circleLabel": {
          "type": "string"
        },
        "canonical": {
          "type": "string"
        },
        "kind": {
          "type": "string",
          "enum": [
            "fact",
            "inference",
            "conclusion"
          ]
        },
        "requiredSlots": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4,
          "items": {
            "$ref": "#/$defs/slot"
          }
        },
        "optionalSlots": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/slot"
          }
        },
        "positives": {
          "type": "array",
          "minItems": 3,
          "items": {
            "type": "string"
          }
        },
        "paraphrasePositives": {
          "type": "array",
          "minItems": 3,
          "items": {
            "type": "string"
          }
        },
        "nearMisses": {
          "type": "array",
          "minItems": 3,
          "items": {
            "type": "string"
          }
        },
        "fillerNegatives": {
          "type": "array",
          "minItems": 3,
          "items": {
            "type": "string"
          }
        },
        "contradictions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "whyMatters": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "element": {
      "type": "object",
      "required": [
        "id",
        "label",
        "propositionIds",
        "completionRule"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "propositionIds": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "completionRule": {
          "oneOf": [
            {
              "type": "object",
              "required": [
                "mode"
              ],
              "properties": {
                "mode": {
                  "const": "all_of"
                }
              },
              "additionalProperties": false
            },
            {
              "type": "object",
              "required": [
                "mode",
                "k"
              ],
              "properties": {
                "mode": {
                  "const": "k_of_n"
                },
                "k": {
                  "type": "integer",
                  "minimum": 1
                }
              },
              "additionalProperties": false
            }
          ]
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
