{
  "$defs": {
    "aggregate": {
      "additionalProperties": false,
      "properties": {
        "catalog_state": {
          "$ref": "#/$defs/catalog_state"
        },
        "generated_by": {
          "const": "scripts/validate_formalization_status.py"
        },
        "generator_version": {
          "const": 2
        },
        "input_sha256": {
          "pattern": "^[0-9a-f]{64}$",
          "type": "string"
        },
        "records": {
          "items": {
            "$ref": "#/$defs/declaration_record"
          },
          "type": "array"
        },
        "schema_version": {
          "const": 1
        },
        "source_items": {
          "items": {
            "$ref": "#/$defs/source_item"
          },
          "type": "array"
        },
        "sources": {
          "items": {
            "$ref": "#/$defs/source"
          },
          "type": "array"
        },
        "topics": {
          "items": {
            "$ref": "#/$defs/topic"
          },
          "type": "array"
        }
      },
      "required": [
        "catalog_state",
        "generated_by",
        "generator_version",
        "input_sha256",
        "records",
        "schema_version",
        "source_items",
        "sources",
        "topics"
      ],
      "type": "object"
    },
    "catalog_state": {
      "enum": [
        "authoritative",
        "prototype"
      ]
    },
    "cutover_baseline": {
      "additionalProperties": false,
      "properties": {
        "baseline_commit": {
          "const": "6519099024bf156b87ac0c807c6633c513792581"
        },
        "baseline_path": {
          "const": "docs/index.md"
        },
        "cutover_record_ids": {
          "items": {
            "$ref": "#/$defs/stable_id"
          },
          "type": "array",
          "uniqueItems": true
        },
        "legacy_rows": {
          "items": {
            "$ref": "#/$defs/cutover_legacy_row"
          },
          "maxItems": 2052,
          "minItems": 2052,
          "type": "array"
        },
        "non_legacy_record_ids": {
          "items": {
            "$ref": "#/$defs/stable_id"
          },
          "type": "array",
          "uniqueItems": true
        },
        "schema_version": {
          "const": 1
        }
      },
      "required": [
        "baseline_commit",
        "baseline_path",
        "cutover_record_ids",
        "legacy_rows",
        "non_legacy_record_ids",
        "schema_version"
      ],
      "type": "object"
    },
    "cutover_certificate": {
      "additionalProperties": false,
      "properties": {
        "baseline_sha256": {
          "pattern": "^[0-9a-f]{64}$",
          "type": "string"
        },
        "cutover_record_ids_sha256": {
          "pattern": "^[0-9a-f]{64}$",
          "type": "string"
        },
        "exceptional_mappings": {
          "items": {
            "$ref": "#/$defs/cutover_exceptional_mapping"
          },
          "type": "array"
        },
        "legacy_mapping_sha256": {
          "pattern": "^[0-9a-f]{64}$",
          "type": "string"
        },
        "non_record_ordinals": {
          "items": {
            "maximum": 2052,
            "minimum": 1,
            "type": "integer"
          },
          "type": "array",
          "uniqueItems": true
        },
        "retired_declarations": {
          "items": {
            "$ref": "#/$defs/cutover_retired_declaration"
          },
          "type": "array"
        },
        "schema_version": {
          "const": 1
        }
      },
      "required": [
        "baseline_sha256",
        "cutover_record_ids_sha256",
        "exceptional_mappings",
        "legacy_mapping_sha256",
        "non_record_ordinals",
        "retired_declarations",
        "schema_version"
      ],
      "type": "object"
    },
    "cutover_exceptional_mapping": {
      "additionalProperties": false,
      "properties": {
        "expected_lean_names": {
          "items": {
            "$ref": "#/$defs/lean_name"
          },
          "minItems": 1,
          "type": "array",
          "uniqueItems": true
        },
        "ordinal": {
          "maximum": 2052,
          "minimum": 1,
          "type": "integer"
        },
        "row_sha256": {
          "pattern": "^[0-9a-f]{64}$",
          "type": "string"
        }
      },
      "required": [
        "expected_lean_names",
        "ordinal",
        "row_sha256"
      ],
      "type": "object"
    },
    "cutover_legacy_row": {
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "outcome": {
                "const": "retired"
              }
            },
            "required": [
              "outcome"
            ]
          },
          "then": {
            "properties": {
              "disposition": {
                "const": "retired_declarations"
              },
              "mapped_record_ids": {
                "maxItems": 0
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "outcome": {
                "const": "mapped"
              }
            },
            "required": [
              "outcome"
            ]
          },
          "then": {
            "properties": {
              "disposition": {
                "type": "null"
              },
              "mapped_record_ids": {
                "minItems": 1
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "outcome": {
                "const": "not_a_declaration"
              }
            },
            "required": [
              "outcome"
            ]
          },
          "then": {
            "properties": {
              "disposition": {
                "const": "non_declaration"
              },
              "mapped_record_ids": {
                "maxItems": 0
              }
            }
          }
        }
      ],
      "properties": {
        "disposition": {
          "oneOf": [
            {
              "const": "non_declaration"
            },
            {
              "const": "retired_declarations"
            },
            {
              "type": "null"
            }
          ]
        },
        "legacy_declaration_refs": {
          "items": {
            "$ref": "#/$defs/inline_text"
          },
          "type": "array"
        },
        "legacy_first_cell": {
          "$ref": "#/$defs/inline_text"
        },
        "legacy_grouping_syntax": {
          "items": {
            "enum": [
              "abbreviated",
              "brace",
              "multiple",
              "plain_etc",
              "signature",
              "slash",
              "wildcard"
            ]
          },
          "type": "array",
          "uniqueItems": true
        },
        "legacy_plain_text": {
          "pattern": "^(?![\\s\\S]*[\\u0000-\\u001F\\u007F-\\u009F])[\\s\\S]*$",
          "type": "string"
        },
        "legacy_source_line": {
          "maximum": 2730,
          "minimum": 239,
          "type": "integer"
        },
        "mapped_record_ids": {
          "items": {
            "$ref": "#/$defs/stable_id"
          },
          "type": "array",
          "uniqueItems": true
        },
        "ordinal": {
          "maximum": 2052,
          "minimum": 1,
          "type": "integer"
        },
        "outcome": {
          "enum": [
            "mapped",
            "not_a_declaration",
            "retired"
          ]
        },
        "row_sha256": {
          "pattern": "^[0-9a-f]{64}$",
          "type": "string"
        }
      },
      "required": [
        "disposition",
        "legacy_declaration_refs",
        "legacy_first_cell",
        "legacy_grouping_syntax",
        "legacy_plain_text",
        "legacy_source_line",
        "mapped_record_ids",
        "ordinal",
        "outcome",
        "row_sha256"
      ],
      "type": "object"
    },
    "cutover_retired_declaration": {
      "additionalProperties": false,
      "properties": {
        "deletion_commit": {
          "pattern": "^[0-9a-f]{40}$",
          "type": "string"
        },
        "former_lean_name": {
          "$ref": "#/$defs/lean_name"
        },
        "former_path": {
          "pattern": "^LatticeSystem/[A-Za-z0-9_./-]+\\.lean$",
          "type": "string"
        },
        "legacy_leaf": {
          "pattern": "^[A-Za-z_\\u0080-\\uFFFF][A-Za-z0-9_'\\u0080-\\uFFFF]*$",
          "type": "string"
        },
        "ordinal": {
          "maximum": 2052,
          "minimum": 1,
          "type": "integer"
        },
        "reason": {
          "$ref": "#/$defs/inline_text"
        },
        "replacement_record_ids": {
          "items": {
            "$ref": "#/$defs/stable_id"
          },
          "type": "array",
          "uniqueItems": true
        },
        "row_sha256": {
          "pattern": "^[0-9a-f]{64}$",
          "type": "string"
        }
      },
      "required": [
        "deletion_commit",
        "former_lean_name",
        "former_path",
        "legacy_leaf",
        "ordinal",
        "reason",
        "row_sha256"
      ],
      "type": "object"
    },
    "declaration_kind": {
      "enum": [
        "abbrev",
        "axiom",
        "class",
        "definition",
        "inductive",
        "instance",
        "lemma",
        "opaque",
        "structure",
        "theorem"
      ]
    },
    "declaration_record": {
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "trust_state": {
                "const": "axiom_free"
              }
            },
            "required": [
              "trust_state"
            ]
          },
          "then": {
            "properties": {
              "axiom_dependencies": {
                "maxItems": 0
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "trust_state": {
                "const": "depends_on_documented_axioms"
              }
            },
            "required": [
              "trust_state"
            ]
          },
          "then": {
            "properties": {
              "axiom_dependencies": {
                "minItems": 1
              },
              "declaration_kind": {
                "not": {
                  "const": "axiom"
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "trust_state": {
                "const": "documented_axiom"
              }
            },
            "required": [
              "trust_state"
            ]
          },
          "then": {
            "properties": {
              "axiom_dependencies": {
                "maxItems": 1,
                "minItems": 1
              },
              "declaration_kind": {
                "const": "axiom"
              },
              "implementation_state": {
                "const": "implemented"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "declaration_kind": {
                "const": "axiom"
              }
            },
            "required": [
              "declaration_kind"
            ]
          },
          "then": {
            "properties": {
              "trust_state": {
                "const": "documented_axiom"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "implementation_state": {
                "const": "in_progress"
              }
            },
            "required": [
              "implementation_state"
            ]
          },
          "then": {
            "properties": {
              "capstone": {
                "const": false
              },
              "source_coverage": {
                "const": "partial"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "capstone": {
                "const": true
              }
            },
            "required": [
              "capstone"
            ]
          },
          "then": {
            "properties": {
              "implementation_state": {
                "const": "implemented"
              },
              "source_coverage": {
                "enum": [
                  "complete",
                  "conditional_reduction"
                ]
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "origin": {
                "const": "literature"
              }
            },
            "required": [
              "origin"
            ]
          },
          "then": {
            "properties": {
              "source_coverage": {
                "not": {
                  "const": "not_applicable"
                }
              },
              "source_relations": {
                "contains": {
                  "properties": {
                    "relation": {
                      "enum": [
                        "formalizes",
                        "presents"
                      ]
                    }
                  },
                  "required": [
                    "relation"
                  ]
                },
                "maxContains": 1,
                "minContains": 1
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "origin": {
                "const": "project_original"
              }
            },
            "required": [
              "origin"
            ]
          },
          "then": {
            "allOf": [
              {
                "if": {
                  "properties": {
                    "implementation_state": {
                      "const": "implemented"
                    }
                  },
                  "required": [
                    "implementation_state"
                  ]
                },
                "then": {
                  "properties": {
                    "source_coverage": {
                      "const": "not_applicable"
                    }
                  }
                }
              }
            ],
            "properties": {
              "source_relations": {
                "not": {
                  "contains": {
                    "properties": {
                      "relation": {
                        "enum": [
                          "formalizes",
                          "presents"
                        ]
                      }
                    },
                    "required": [
                      "relation"
                    ]
                  }
                }
              }
            }
          }
        }
      ],
      "properties": {
        "axiom_dependencies": {
          "items": {
            "$ref": "#/$defs/lean_name"
          },
          "type": "array",
          "uniqueItems": true
        },
        "capstone": {
          "type": "boolean"
        },
        "declaration_kind": {
          "$ref": "#/$defs/declaration_kind"
        },
        "id": {
          "$ref": "#/$defs/stable_id"
        },
        "implementation_state": {
          "$ref": "#/$defs/implementation_state"
        },
        "lean_name": {
          "$ref": "#/$defs/lean_name"
        },
        "module": {
          "$ref": "#/$defs/module_name"
        },
        "origin": {
          "$ref": "#/$defs/origin"
        },
        "proof_guide_anchor": {
          "oneOf": [
            {
              "$ref": "#/$defs/stable_id"
            },
            {
              "type": "null"
            }
          ]
        },
        "source_coverage": {
          "$ref": "#/$defs/source_coverage"
        },
        "source_path": {
          "$ref": "#/$defs/source_path"
        },
        "source_relations": {
          "items": {
            "$ref": "#/$defs/source_relation"
          },
          "type": "array",
          "uniqueItems": true
        },
        "summary": {
          "$ref": "#/$defs/inline_text"
        },
        "topic_ids": {
          "items": {
            "$ref": "#/$defs/stable_id"
          },
          "minItems": 1,
          "type": "array",
          "uniqueItems": true
        },
        "trust_state": {
          "$ref": "#/$defs/trust_state"
        }
      },
      "required": [
        "axiom_dependencies",
        "capstone",
        "declaration_kind",
        "id",
        "implementation_state",
        "lean_name",
        "module",
        "origin",
        "proof_guide_anchor",
        "source_coverage",
        "source_path",
        "source_relations",
        "summary",
        "topic_ids",
        "trust_state"
      ],
      "type": "object"
    },
    "implementation_state": {
      "enum": [
        "implemented",
        "in_progress"
      ]
    },
    "inline_text": {
      "pattern": "^(?![\\s\\S]*[\\u0000-\\u001F\\u007F-\\u009F])[\\s\\S]+$",
      "type": "string"
    },
    "lean_name": {
      "pattern": "^LatticeSystem(?:\\.[A-Za-z_\\u0080-\\uFFFF][A-Za-z0-9_'\\u0080-\\uFFFF]*)+$",
      "type": "string"
    },
    "manifest": {
      "additionalProperties": false,
      "properties": {
        "catalog_state": {
          "$ref": "#/$defs/catalog_state"
        },
        "cutover_baseline": {
          "const": "cutover-baseline.json"
        },
        "cutover_certificate": {
          "const": "cutover-certificate.json"
        },
        "human_publication_root": {
          "pattern": "^/lattice-system/.+/$",
          "type": "string"
        },
        "machine_publication_root": {
          "pattern": "^/lattice-system/.+/$",
          "type": "string"
        },
        "record_shards": {
          "items": {
            "pattern": "^records/[a-z0-9]+(?:-[a-z0-9]+)*\\.json$",
            "type": "string"
          },
          "type": "array",
          "uniqueItems": true
        },
        "registries": {
          "additionalProperties": false,
          "properties": {
            "source_items": {
              "const": "source-items.json"
            },
            "sources": {
              "const": "sources.json"
            },
            "topics": {
              "const": "topics.json"
            }
          },
          "required": [
            "source_items",
            "sources",
            "topics"
          ],
          "type": "object"
        },
        "schema": {
          "const": "schema.json"
        },
        "schema_version": {
          "const": 1
        }
      },
      "required": [
        "catalog_state",
        "human_publication_root",
        "machine_publication_root",
        "record_shards",
        "registries",
        "schema",
        "schema_version"
      ],
      "type": "object"
    },
    "module_name": {
      "pattern": "^LatticeSystem(?:\\.[A-Z][A-Za-z0-9_]*)+$",
      "type": "string"
    },
    "origin": {
      "enum": [
        "literature",
        "project_original"
      ]
    },
    "record_shard": {
      "additionalProperties": false,
      "properties": {
        "records": {
          "items": {
            "$ref": "#/$defs/declaration_record"
          },
          "type": "array"
        },
        "schema_version": {
          "const": 1
        },
        "source_id": {
          "oneOf": [
            {
              "$ref": "#/$defs/stable_id"
            },
            {
              "type": "null"
            }
          ]
        },
        "source_unit": {
          "minLength": 1,
          "type": "string"
        }
      },
      "required": [
        "records",
        "schema_version",
        "source_id",
        "source_unit"
      ],
      "type": "object"
    },
    "source": {
      "additionalProperties": false,
      "properties": {
        "authors": {
          "items": {
            "$ref": "#/$defs/inline_text"
          },
          "minItems": 1,
          "type": "array"
        },
        "edition": {
          "$ref": "#/$defs/inline_text"
        },
        "id": {
          "$ref": "#/$defs/stable_id"
        },
        "publication": {
          "$ref": "#/$defs/inline_text"
        },
        "title": {
          "$ref": "#/$defs/inline_text"
        },
        "url": {
          "pattern": "^(?![\\s\\S]*[\\u0000-\\u001F\\u007F-\\u009F])https://[\\s\\S]+$",
          "type": "string"
        },
        "year": {
          "maximum": 9999,
          "minimum": 1000,
          "type": "integer"
        }
      },
      "required": [
        "authors",
        "id",
        "year"
      ],
      "type": "object"
    },
    "source_coverage": {
      "enum": [
        "complete",
        "conditional_reduction",
        "not_applicable",
        "partial"
      ]
    },
    "source_item": {
      "additionalProperties": false,
      "properties": {
        "equations": {
          "items": {
            "$ref": "#/$defs/inline_text"
          },
          "type": "array",
          "uniqueItems": true
        },
        "id": {
          "$ref": "#/$defs/stable_id"
        },
        "item_kind": {
          "enum": [
            "article",
            "definition",
            "equation",
            "exercise",
            "lemma",
            "proposition",
            "section",
            "theorem"
          ]
        },
        "item_number": {
          "oneOf": [
            {
              "$ref": "#/$defs/inline_text"
            },
            {
              "type": "null"
            }
          ]
        },
        "pages": {
          "oneOf": [
            {
              "$ref": "#/$defs/inline_text"
            },
            {
              "type": "null"
            }
          ]
        },
        "section": {
          "oneOf": [
            {
              "$ref": "#/$defs/inline_text"
            },
            {
              "type": "null"
            }
          ]
        },
        "source_id": {
          "$ref": "#/$defs/stable_id"
        },
        "title": {
          "$ref": "#/$defs/inline_text"
        }
      },
      "required": [
        "equations",
        "id",
        "item_kind",
        "item_number",
        "pages",
        "section",
        "source_id",
        "title"
      ],
      "type": "object"
    },
    "source_item_registry": {
      "additionalProperties": false,
      "properties": {
        "schema_version": {
          "const": 1
        },
        "source_items": {
          "items": {
            "$ref": "#/$defs/source_item"
          },
          "type": "array"
        }
      },
      "required": [
        "schema_version",
        "source_items"
      ],
      "type": "object"
    },
    "source_path": {
      "pattern": "^LatticeSystem/(?:[A-Za-z][A-Za-z0-9_]*/)*[A-Za-z][A-Za-z0-9_]*\\.lean$",
      "type": "string"
    },
    "source_registry": {
      "additionalProperties": false,
      "properties": {
        "schema_version": {
          "const": 1
        },
        "sources": {
          "items": {
            "$ref": "#/$defs/source"
          },
          "type": "array"
        }
      },
      "required": [
        "schema_version",
        "sources"
      ],
      "type": "object"
    },
    "source_relation": {
      "additionalProperties": false,
      "properties": {
        "relation": {
          "enum": [
            "attributes",
            "cross_checks",
            "formalizes",
            "presents",
            "supports"
          ]
        },
        "source_item_id": {
          "$ref": "#/$defs/stable_id"
        }
      },
      "required": [
        "relation",
        "source_item_id"
      ],
      "type": "object"
    },
    "stable_id": {
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$",
      "type": "string"
    },
    "topic": {
      "additionalProperties": false,
      "properties": {
        "description": {
          "$ref": "#/$defs/inline_text"
        },
        "id": {
          "$ref": "#/$defs/stable_id"
        },
        "label": {
          "$ref": "#/$defs/inline_text"
        }
      },
      "required": [
        "description",
        "id",
        "label"
      ],
      "type": "object"
    },
    "topic_registry": {
      "additionalProperties": false,
      "properties": {
        "schema_version": {
          "const": 1
        },
        "topics": {
          "items": {
            "$ref": "#/$defs/topic"
          },
          "type": "array"
        }
      },
      "required": [
        "schema_version",
        "topics"
      ],
      "type": "object"
    },
    "trust_state": {
      "enum": [
        "axiom_free",
        "depends_on_documented_axioms",
        "documented_axiom"
      ]
    }
  },
  "$id": "https://phasetr.github.io/lattice-system/formalization-status/v1/schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "oneOf": [
    {
      "$ref": "#/$defs/aggregate"
    },
    {
      "$ref": "#/$defs/cutover_baseline"
    },
    {
      "$ref": "#/$defs/cutover_certificate"
    },
    {
      "$ref": "#/$defs/manifest"
    },
    {
      "$ref": "#/$defs/record_shard"
    },
    {
      "$ref": "#/$defs/source_item_registry"
    },
    {
      "$ref": "#/$defs/source_registry"
    },
    {
      "$ref": "#/$defs/topic_registry"
    }
  ],
  "title": "lattice-system formalization status schema version 1",
  "type": "object"
}
