{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.ilurennik.com/format/ilu-record-0.1.schema.json",
  "title": "Ilu Rennik record, format 0.1",
  "description": "record.json in an Ilu Rennik export. The format is described at https://www.ilurennik.com/format",
  "type": "object",
  "required": [
    "format",
    "exported_at",
    "owner",
    "shelves",
    "facts",
    "sources",
    "documents",
    "grants",
    "disclosures"
  ],
  "properties": {
    "format": {
      "const": "ilu-record/0.1"
    },
    "exported_at": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "Z$"
    },
    "owner": {
      "type": "object",
      "required": [
        "name",
        "addresses"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "addresses": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "shelves": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "name",
          "elements"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "elements": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "name"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "facts": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "subject",
          "statement",
          "kind",
          "shelf",
          "element",
          "placed",
          "in_vault",
          "status",
          "held_because",
          "sealed",
          "standing",
          "first_seen",
          "last_confirmed",
          "effective",
          "owes",
          "supersedes"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "subject": {
            "type": "string"
          },
          "statement": {
            "type": "string"
          },
          "kind": {
            "enum": [
              "account_map",
              "asset_location",
              "business_owned",
              "designation",
              "document_pointer",
              "instruction",
              "letter",
              "policy_fact",
              "role"
            ]
          },
          "shelf": {
            "type": "string"
          },
          "element": {
            "type": [
              "string",
              "null"
            ]
          },
          "placed": {
            "enum": [
              "filed",
              "guessed"
            ]
          },
          "in_vault": {
            "type": "boolean"
          },
          "status": {
            "enum": [
              "active",
              "conflicted",
              "held",
              "retired"
            ]
          },
          "held_because": {
            "type": [
              "string",
              "null"
            ]
          },
          "sealed": {
            "type": "boolean"
          },
          "standing": {
            "enum": [
              "confirmed",
              "unconfirmed"
            ]
          },
          "first_seen": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "Z$"
          },
          "last_confirmed": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "Z$"
          },
          "effective": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "Z$"
          },
          "owes": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "required": [
                  "from",
                  "to"
                ],
                "properties": {
                  "from": {
                    "type": "string"
                  },
                  "to": {
                    "type": "string"
                  }
                }
              }
            ]
          },
          "supersedes": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          }
        }
      }
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "fact",
          "kind",
          "quote",
          "seen",
          "message",
          "document"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "fact": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "enum": [
              "email",
              "message",
              "document",
              "said"
            ]
          },
          "quote": {
            "type": [
              "string",
              "null"
            ]
          },
          "seen": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "Z$"
          },
          "message": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "required": [
                  "channel",
                  "from",
                  "to",
                  "subject",
                  "sent"
                ],
                "properties": {
                  "channel": {
                    "type": "string"
                  },
                  "from": {
                    "type": "string"
                  },
                  "to": {
                    "type": "string"
                  },
                  "subject": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "sent": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "Z$"
                  }
                }
              }
            ]
          },
          "document": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "string",
                "format": "uuid"
              }
            ]
          }
        }
      }
    },
    "documents": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "filename",
          "type",
          "bytes",
          "file",
          "sha256",
          "missing"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "filename": {
            "type": [
              "string",
              "null"
            ]
          },
          "type": {
            "type": [
              "string",
              "null"
            ]
          },
          "bytes": {
            "type": [
              "integer",
              "null"
            ]
          },
          "file": {
            "type": [
              "string",
              "null"
            ]
          },
          "sha256": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[0-9a-f]{64}$"
          },
          "missing": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    },
    "grants": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "reader",
          "audience",
          "email",
          "shelves",
          "amounts",
          "opened",
          "ends",
          "closed",
          "last_used",
          "times_used"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "reader": {
            "type": "string"
          },
          "audience": {
            "enum": [
              "person",
              "agent"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "shelves": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "amounts": {
            "enum": [
              "exact",
              "banded"
            ]
          },
          "opened": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "Z$"
          },
          "ends": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "Z$"
          },
          "closed": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "Z$"
          },
          "last_used": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "Z$"
          },
          "times_used": {
            "type": "integer"
          }
        }
      }
    },
    "disclosures": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "grant",
          "at",
          "question",
          "answered",
          "answer",
          "told",
          "opened_document"
        ],
        "properties": {
          "grant": {
            "type": "string",
            "format": "uuid"
          },
          "at": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "Z$"
          },
          "question": {
            "type": [
              "string",
              "null"
            ]
          },
          "answered": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "answer": {
            "type": [
              "string",
              "null"
            ]
          },
          "told": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "opened_document": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "string",
                "format": "uuid"
              }
            ]
          }
        }
      }
    }
  }
}
