{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://law.arxo.io/schema/import-ir.schema.json",
  "type": "object",
  "properties": {
    "format": {
      "const": "arxo.import/0.1"
    },
    "snapshot": {
      "$ref": "#/$defs/Snapshot"
    },
    "documents": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Document"
      }
    },
    "anchors": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Anchor"
      }
    },
    "modules": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "imports": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "imports"
        ],
        "additionalProperties": false
      }
    },
    "symbols": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Symbol"
      }
    },
    "expressions": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Expression"
      }
    },
    "declarations": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/Declaration"
      }
    },
    "dependencies": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "kind": {
            "enum": [
              "type",
              "statement",
              "definition"
            ]
          }
        },
        "required": [
          "from",
          "to",
          "kind"
        ],
        "additionalProperties": false
      }
    },
    "facts": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string"
          },
          "args": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "const": "entity"
                    },
                    "iri": {
                      "type": "string"
                    },
                    "type_symbol": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "kind",
                    "iri",
                    "type_symbol"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "kind": {
                      "const": "string"
                    },
                    "value": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "kind",
                    "value"
                  ],
                  "additionalProperties": false
                }
              ]
            }
          },
          "anchor": {
            "type": "string"
          },
          "requires": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "symbol",
          "args",
          "anchor",
          "requires"
        ],
        "additionalProperties": false
      }
    },
    "dependency_completeness": {
      "enum": [
        "module",
        "declaration"
      ]
    }
  },
  "required": [
    "format",
    "snapshot",
    "documents",
    "anchors",
    "modules",
    "symbols",
    "expressions",
    "declarations",
    "dependencies"
  ],
  "additionalProperties": false,
  "$defs": {
    "Snapshot": {
      "type": "object",
      "properties": {
        "project": {
          "type": "string"
        },
        "revision": {
          "type": "string"
        },
        "language": {
          "type": "string"
        },
        "logic": {
          "type": "string"
        },
        "adapter": {
          "type": "string"
        },
        "context_complete": {
          "type": "boolean"
        },
        "retrieved_at": {
          "type": "string"
        },
        "requires": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "project",
        "revision",
        "language",
        "logic",
        "adapter",
        "context_complete",
        "retrieved_at",
        "requires"
      ],
      "additionalProperties": false
    },
    "Document": {
      "type": "object",
      "properties": {
        "uri": {
          "type": "string"
        },
        "language": {
          "type": "string"
        },
        "official": {
          "type": "boolean"
        },
        "text": {
          "type": "string"
        },
        "content_hash": {
          "type": "string"
        }
      },
      "required": [
        "uri",
        "language",
        "official",
        "text",
        "content_hash"
      ],
      "additionalProperties": false
    },
    "Anchor": {
      "type": "object",
      "properties": {
        "document": {
          "type": "string"
        },
        "start": {
          "type": "integer",
          "minimum": 0
        },
        "end": {
          "type": "integer",
          "minimum": 0
        },
        "locator": {
          "type": "string"
        }
      },
      "required": [
        "document",
        "start",
        "end",
        "locator"
      ],
      "additionalProperties": false
    },
    "Symbol": {
      "type": "object",
      "properties": {
        "kind": {
          "enum": [
            "type",
            "predicate"
          ]
        },
        "parameters": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "label": {
          "type": "string"
        }
      },
      "required": [
        "kind",
        "parameters",
        "label"
      ],
      "additionalProperties": false
    },
    "Expression": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "var"
            },
            "binder": {
              "type": "string"
            },
            "type_symbol": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "binder",
            "type_symbol"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "atom"
            },
            "symbol": {
              "type": "string"
            },
            "args": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "kind",
            "symbol",
            "args"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "and"
            },
            "items": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "kind",
            "items"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "or"
            },
            "items": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "kind",
            "items"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "implies"
            },
            "premise": {
              "type": "string"
            },
            "conclusion": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "premise",
            "conclusion"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "forall"
            },
            "binder": {
              "type": "string"
            },
            "type_symbol": {
              "type": "string"
            },
            "body": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "binder",
            "type_symbol",
            "body"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "exists"
            },
            "binder": {
              "type": "string"
            },
            "type_symbol": {
              "type": "string"
            },
            "body": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "binder",
            "type_symbol",
            "body"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "not"
            },
            "value": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "value"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "equal"
            },
            "left": {
              "type": "string"
            },
            "right": {
              "type": "string"
            }
          },
          "required": [
            "kind",
            "left",
            "right"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "opaque"
            },
            "anchor": {
              "type": "string"
            },
            "free": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "kind",
            "anchor",
            "free"
          ],
          "additionalProperties": false
        }
      ]
    },
    "Declaration": {
      "type": "object",
      "properties": {
        "module": {
          "type": "string"
        },
        "kind": {
          "enum": [
            "theorem",
            "definition",
            "axiom",
            "instance"
          ]
        },
        "label": {
          "type": "string"
        },
        "parameters": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "type_symbol": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "type_symbol"
            ],
            "additionalProperties": false
          }
        },
        "context": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "statement": {
          "type": "string"
        },
        "anchor": {
          "type": "string"
        },
        "requires": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "module",
        "kind",
        "label",
        "parameters",
        "context",
        "statement",
        "anchor",
        "requires"
      ],
      "additionalProperties": false
    }
  }
}
