{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://interchange.stellarview.net/schemas/document.schema.json",
  "title": "A document: a file that arrived, stored untouched, with its text where any could be read",
  "allOf": [
    {
      "$ref": "common.schema.json#/$defs/provenance"
    }
  ],
  "type": "object",
  "required": [
    "kind",
    "document_id",
    "event_type",
    "filename",
    "media_type",
    "bytes",
    "sha256",
    "stored",
    "text",
    "asset",
    "source",
    "read_at",
    "validated_at"
  ],
  "unevaluatedProperties": false,
  "properties": {
    "kind": {
      "const": "document"
    },
    "document_id": {
      "$ref": "common.schema.json#/$defs/uuid"
    },
    "event_type": {
      "$ref": "common.schema.json#/$defs/event_type_id"
    },
    "filename": {
      "type": "string"
    },
    "media_type": {
      "type": "string"
    },
    "bytes": {
      "type": "integer",
      "minimum": 0
    },
    "sha256": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    },
    "stored": {
      "type": "string",
      "description": "Where the original is kept (a local path today; an S3 key in the AWS design)."
    },
    "pages": {
      "type": "integer",
      "minimum": 0
    },
    "text": {
      "type": "object",
      "required": [
        "state"
      ],
      "additionalProperties": false,
      "properties": {
        "state": {
          "enum": [
            "extracted",
            "no_text_layer",
            "not_extracted"
          ]
        },
        "chars": {
          "type": "integer",
          "minimum": 0
        },
        "stored": {
          "type": "string"
        },
        "why": {
          "type": "string"
        }
      }
    },
    "asset": {
      "$ref": "common.schema.json#/$defs/asset_ref"
    },
    "source": true,
    "read_at": true,
    "validated_at": true,
    "rules": {
      "type": "object",
      "required": [
        "state",
        "note"
      ],
      "additionalProperties": false,
      "properties": {
        "state": {
          "const": "designed"
        },
        "note": {
          "type": "string"
        }
      },
      "description": "The rules the document states. Extraction is designed, not built."
    }
  }
}