{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Lifted Public Loop Records",
  "schemaVersion": "2.0.0",
  "type": "object",
  "required": [
    "schemaVersion",
    "adoptedAt",
    "retrospectiveThrough",
    "firstContemporaneousEntry",
    "records",
    "migrationWarnings"
  ],
  "properties": {
    "schemaVersion": {
      "const": "2.0.0"
    },
    "adoptedAt": {
      "type": "string",
      "format": "date"
    },
    "retrospectiveThrough": {
      "type": "string",
      "pattern": "^[0-9]{3}$"
    },
    "firstContemporaneousEntry": {
      "type": "string",
      "pattern": "^[0-9]{3}$"
    },
    "purpose": {
      "type": "string"
    },
    "records": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/record"
      }
    },
    "migrationWarnings": {
      "type": "array",
      "items": {
        "type": "object"
      }
    }
  },
  "$defs": {
    "record": {
      "type": "object",
      "required": [
        "entry",
        "eventDate",
        "schemaVersion",
        "recordMode",
        "annotatedAt",
        "primaryBottleneck",
        "signals",
        "loopChange",
        "outcome",
        "verification",
        "capabilityNovelty",
        "provenance"
      ],
      "properties": {
        "entry": {
          "type": "string",
          "pattern": "^[0-9]{3}$"
        },
        "eventDate": {
          "type": "string",
          "format": "date"
        },
        "schemaVersion": {
          "const": "2.0.0"
        },
        "recordMode": {
          "enum": [
            "retrospective_annotation",
            "contemporaneous"
          ]
        },
        "annotatedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date"
        },
        "primaryBottleneck": {
          "enum": [
            "H",
            "A",
            "L",
            "X",
            "NONE",
            "UNKNOWN"
          ]
        },
        "signals": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "enum": [
              "C",
              "J",
              "E",
              "S"
            ]
          }
        },
        "loopChange": {
          "type": "object",
          "required": [
            "status",
            "types",
            "source"
          ],
          "properties": {
            "status": {
              "enum": [
                "adopted",
                "no_formal_intervention_record"
              ]
            },
            "types": {
              "type": "array",
              "uniqueItems": true,
              "items": {
                "enum": [
                  "protocol",
                  "tooling",
                  "measurement",
                  "workflow",
                  "taxonomy",
                  "other"
                ]
              }
            },
            "source": {
              "enum": [
                "linked_intervention_record",
                "private_ledger"
              ]
            }
          },
          "additionalProperties": false
        },
        "outcome": {
          "enum": [
            "successful",
            "partial",
            "failed",
            "mixed",
            "observational"
          ]
        },
        "verification": {
          "enum": [
            "external",
            "internal",
            "none",
            "not_applicable"
          ]
        },
        "capabilityNovelty": {
          "enum": [
            "none",
            "incremental",
            "new_capability",
            "unknown"
          ]
        },
        "provenance": {
          "type": "object",
          "required": [
            "publicArtifact",
            "sourceBasis",
            "annotationMode"
          ],
          "properties": {
            "publicArtifact": {
              "const": "preserved"
            },
            "sourceBasis": {
              "type": "string"
            },
            "annotationMode": {
              "enum": [
                "retrospective",
                "contemporaneous"
              ]
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
