{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:ausca:offer:document-ocr:output:v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "output_digest", "delivery"],
  "properties": {
    "schema": {
      "type": "string",
      "const": "ausca.aws_documents.execution.v1"
    },
    "output_digest": {
      "$ref": "#/$defs/digest"
    },
    "delivery": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "output"],
          "properties": {
            "kind": {"type": "string", "const": "inline"},
            "output": {"$ref": "#/$defs/ocrOutput"}
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "artifact"],
          "properties": {
            "kind": {"type": "string", "const": "artifact"},
            "artifact": {"$ref": "#/$defs/artifact"}
          }
        }
      ]
    }
  },
  "$defs": {
    "digest": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "ocrOutput": {
      "type": "object",
      "additionalProperties": false,
      "required": ["schema", "source_digest", "text", "lines"],
      "properties": {
        "schema": {
          "type": "string",
          "const": "ausca.document_ocr.output.v1"
        },
        "source_digest": {"$ref": "#/$defs/digest"},
        "text": {
          "type": "string",
          "maxLength": 200000
        },
        "lines": {
          "type": "array",
          "maxItems": 20000,
          "items": {"$ref": "#/$defs/line"}
        }
      }
    },
    "line": {
      "type": "object",
      "additionalProperties": false,
      "required": ["text"],
      "properties": {
        "text": {
          "type": "string",
          "minLength": 1,
          "maxLength": 10000
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "page": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        }
      }
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "artifact_ref",
        "content_digest",
        "media_type",
        "size_bytes"
      ],
      "properties": {
        "artifact_ref": {
          "type": "string",
          "pattern": "^runx:artifact:sha256:[0-9a-f]{64}$"
        },
        "content_digest": {"$ref": "#/$defs/digest"},
        "media_type": {
          "type": "string",
          "const": "application/json"
        },
        "size_bytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 26214400
        }
      }
    }
  }
}
