{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hejstack.com/export-specs/dokumente.schema.json",
  "title": "hejstack Export: dokumente.json",
  "description": "Metadaten aller Dokumente einer Organisation. Die Originaldateien liegen unter dokumente/<wissensgruppe>/<datei>. Umfasst hochgeladene Dokumente und Postfach-Wissen (source m365mail / imapmail). Inhalte angebundener Quellen (Nextcloud, OneDrive, SharePoint) werden nicht exportiert, nur ihr Verweis (exported = false). Exportformat 1.0, Stand 15.09.2026.",
  "type": "object",
  "required": ["format_version", "documents"],
  "properties": {
    "format_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+$" },
    "documents": { "type": "array", "items": { "$ref": "#/$defs/document" } }
  },
  "$defs": {
    "uuid": { "type": "string", "format": "uuid" },
    "document": {
      "type": "object",
      "required": ["id", "filename", "mimetype", "size_bytes", "knowledge_group_id", "source", "exported", "created_at"],
      "properties": {
        "id": { "$ref": "#/$defs/uuid" },
        "filename": { "type": "string", "maxLength": 255, "description": "Ursprünglicher Dateiname." },
        "mimetype": { "type": "string", "description": "MIME-Typ der Originaldatei, z. B. application/pdf." },
        "size_bytes": { "type": "integer", "minimum": 0 },
        "sha256": { "type": ["string", "null"], "pattern": "^[0-9a-f]{64}$", "description": "Prüfsumme der exportierten Datei; null, wenn nicht exportiert." },
        "path": { "type": ["string", "null"], "description": "Pfad der Datei im Paket (dokumente/<wissensgruppe>/<datei>); null, wenn nicht exportiert." },
        "exported": { "type": "boolean", "description": "false bei Verweisen auf angebundene Quellen (Datei liegt weiterhin im Quellsystem) oder fehlendem Blob." },
        "not_exported_reason": { "type": ["string", "null"], "enum": ["external_source", "missing", null], "description": "external_source = Inhalt liegt in Nextcloud/OneDrive/SharePoint; missing = Datei nicht mehr vorhanden (z. B. Verarbeitung fehlgeschlagen)." },
        "knowledge_group_id": { "$ref": "#/$defs/uuid", "description": "Wissensgruppe, siehe freigaben.json → knowledge_groups." },
        "knowledge_group_name": { "type": "string" },
        "knowledge_group_kind": { "type": "string", "enum": ["folder", "wiki", "mailbox", "personal_drive", "task"] },
        "uploaded_by": { "type": ["string", "null"], "format": "uuid", "description": "Nutzer-ID (siehe nutzer.json); null bei Synchronisation aus einer Quelle." },
        "created_at": { "type": "string", "format": "date-time", "description": "Zeitpunkt des Uploads bzw. der Aufnahme." },
        "updated_at": { "type": ["string", "null"], "format": "date-time" },
        "source": { "type": "string", "description": "Herkunft: upload (hochgeladen), m365mail / imapmail (Postfach-Wissen), nextcloud / onedrive (angebundene Quelle, nur Verweis)." },
        "external_id": { "type": ["string", "null"], "description": "Kennung im Quellsystem (Connector / Postfach)." },
        "remote_url": { "type": ["string", "null"], "format": "uri", "description": "Link zum Original im Quellsystem, falls vorhanden." },
        "source_date": { "type": ["string", "null"], "format": "date-time", "description": "Fachliches Datum des Quellobjekts, bei E-Mails das Empfangsdatum." },
        "connection_id": { "type": ["string", "null"], "format": "uuid", "description": "Angebundene Quelle, siehe konfiguration.json → connections / mailboxes." },
        "status": { "type": "string", "enum": ["pending", "extracting", "embedding", "indexed", "failed"], "description": "Verarbeitungsstatus in hejstack zum Exportzeitpunkt (Suchindex wird nicht exportiert)." },
        "error": { "type": ["string", "null"] }
      }
    }
  }
}
