{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/saturation-io/json-schema/saturation-io-document-schema.json",
  "title": "Document",
  "description": "An uploaded document and its links.",
  "x-generated": "2026-11-23",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/saturation-io-openapi.yml#/components/schemas/Document",
  "type": "object",
  "required": [
    "id",
    "name",
    "mimeType",
    "size",
    "status",
    "workspaceId",
    "containsPii",
    "links",
    "createdAt",
    "updatedAt"
  ],
  "additionalProperties": false,
  "properties": {
    "id": {
      "allOf": [
        {
          "$ref": "#/$defs/Id"
        }
      ],
      "description": "The document ID."
    },
    "name": {
      "type": "string",
      "description": "The document's display name."
    },
    "mimeType": {
      "type": "string",
      "description": "The file's MIME type."
    },
    "size": {
      "type": "integer",
      "format": "int64",
      "description": "The file size in bytes."
    },
    "status": {
      "$ref": "#/$defs/DocumentStatus"
    },
    "workspaceId": {
      "allOf": [
        {
          "$ref": "#/$defs/Id"
        }
      ],
      "description": "The workspace ID."
    },
    "pageCount": {
      "type": [
        "integer",
        "null"
      ],
      "description": "The number of pages, or null until extraction finishes."
    },
    "classification": {
      "type": [
        "string",
        "null"
      ],
      "description": "The document classification, such as `invoice` or `receipt`."
    },
    "coarseType": {
      "description": "The document category, or null until classification finishes.",
      "anyOf": [
        {
          "allOf": [
            {
              "$ref": "#/$defs/DocumentCoarseType"
            }
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "hasSensitiveInfo": {
      "type": [
        "boolean",
        "null"
      ],
      "description": "Whether the document may contain sensitive information."
    },
    "containsPii": {
      "type": "boolean",
      "description": "Whether the document holds personal information, such as a W-9 or a government ID. Its file and extracted data are not available through the API."
    },
    "description": {
      "type": [
        "string",
        "null"
      ],
      "description": "The document description."
    },
    "source": {
      "type": [
        "string",
        "null"
      ],
      "description": "How the document was added, such as `api`, `agent`, or `upload`."
    },
    "folderId": {
      "description": "The folder ID, or null for the workspace root.",
      "anyOf": [
        {
          "allOf": [
            {
              "$ref": "#/$defs/Id"
            }
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "projectId": {
      "description": "The project ID, or null for a workspace document.",
      "anyOf": [
        {
          "allOf": [
            {
              "$ref": "#/$defs/Id"
            }
          ]
        },
        {
          "type": "null"
        }
      ]
    },
    "contentHash": {
      "type": [
        "string",
        "null"
      ],
      "description": "A hash of the file contents."
    },
    "links": {
      "type": "array",
      "description": "The entities linked to this document.",
      "items": {
        "$ref": "#/$defs/DocumentTargetRef"
      }
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "When the document was created."
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "description": "When the document was last updated."
    }
  },
  "$defs": {
    "DocumentCoarseType": {
      "type": "string",
      "description": "The document category found during extraction.",
      "enum": [
        "financial",
        "tax",
        "legal",
        "insurance",
        "production",
        "other"
      ]
    },
    "DocumentStatus": {
      "type": "string",
      "description": "The document's extraction status. `ready` means extracted data is available.",
      "enum": [
        "pending",
        "processing",
        "ready",
        "failed"
      ]
    },
    "DocumentTargetKind": {
      "type": "string",
      "description": "The type of entity linked to a document. A document can have one link of each kind.",
      "enum": [
        "project",
        "contact",
        "transaction",
        "payment",
        "purchaseOrder",
        "budgetLine",
        "paymentRequest"
      ]
    },
    "DocumentTargetRef": {
      "type": "object",
      "description": "An entity linked to a document.",
      "required": [
        "kind",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "kind": {
          "$ref": "#/$defs/DocumentTargetKind"
        },
        "id": {
          "allOf": [
            {
              "$ref": "#/$defs/Id"
            }
          ],
          "description": "The linked entity's ID. Its prefix must match `kind`."
        },
        "phaseId": {
          "anyOf": [
            {
              "$ref": "#/$defs/Id"
            },
            {
              "type": "null"
            }
          ],
          "description": "The phase for a budget-line link."
        }
      }
    },
    "Id": {
      "type": "string",
      "description": "A stable resource ID, such as `prj_…`, `txn_…`, or `doc_…`."
    }
  }
}