{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hejstack.com/export-specs/freigaben.schema.json",
  "title": "hejstack Export: freigaben.json",
  "description": "Wissensgruppen einer Organisation und ihre Freigaben: Zuordnung zu Teams, Freigaben an einzelne Nutzer, freigegebene Postfächer und bezogene Marktplatz-Angebote. Exportformat 1.0, Stand 15.09.2026.",
  "type": "object",
  "required": ["format_version", "knowledge_groups", "team_access"],
  "properties": {
    "format_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+$" },
    "knowledge_groups": { "type": "array", "items": { "$ref": "#/$defs/knowledge_group" } },
    "team_access": { "type": "array", "items": { "$ref": "#/$defs/team_access" }, "description": "Welche Teams auf welche Wissensgruppe zugreifen dürfen." },
    "mailbox_shares": { "type": "array", "items": { "$ref": "#/$defs/mailbox_share" }, "description": "Freigaben von Postfächern (IMAP) an Nutzer." },
    "marketplace_subscriptions": { "type": "array", "items": { "$ref": "#/$defs/marketplace_subscription" }, "description": "Bezogene Marktplatz-Angebote (Fremdwissen) und die Teams, für die sie freigegeben sind." }
  },
  "$defs": {
    "uuid": { "type": "string", "format": "uuid" },
    "knowledge_group": {
      "type": "object",
      "required": ["id", "name", "slug", "kind", "classification", "created_at"],
      "properties": {
        "id": { "$ref": "#/$defs/uuid" },
        "name": { "type": "string", "maxLength": 120 },
        "slug": { "type": "string", "maxLength": 60, "description": "Ordnername im Paket (dokumente/<slug>/, wikis/<slug>.zip)." },
        "description": { "type": ["string", "null"] },
        "kind": { "type": "string", "enum": ["folder", "wiki", "mailbox", "personal_drive", "task"], "description": "folder = Dokumentenordner, wiki = Wiki, mailbox = Postfach-Wissen, personal_drive = persönliches Laufwerk, task = Aufgabenwissen." },
        "classification": { "type": "string", "enum": ["public", "internal", "confidential"] },
        "always_include": { "type": "boolean", "description": "In jedem Chat automatisch eingebunden." },
        "owner_user_id": { "type": ["string", "null"], "format": "uuid", "description": "Eigentümer bei persönlichen Wissensgruppen (Postfach, Laufwerk); null bei Organisationswissen." },
        "shared_user_ids": { "type": "array", "items": { "$ref": "#/$defs/uuid" }, "description": "Einzelne Nutzer, für die eine persönliche Wissensgruppe freigegeben ist." },
        "blocked": { "type": "boolean", "description": "Vom Administrator gesperrt." },
        "created_at": { "type": "string", "format": "date-time" }
      }
    },
    "team_access": {
      "type": "object",
      "required": ["team_id", "knowledge_group_id"],
      "properties": {
        "team_id": { "$ref": "#/$defs/uuid" },
        "knowledge_group_id": { "$ref": "#/$defs/uuid" },
        "created_at": { "type": "string", "format": "date-time" }
      }
    },
    "mailbox_share": {
      "type": "object",
      "required": ["mailbox_id", "user_id"],
      "properties": {
        "mailbox_id": { "$ref": "#/$defs/uuid", "description": "Siehe konfiguration.json → mailboxes." },
        "user_id": { "$ref": "#/$defs/uuid" },
        "created_at": { "type": "string", "format": "date-time" }
      }
    },
    "marketplace_subscription": {
      "type": "object",
      "required": ["listing_id", "listing_title", "provider_name", "status"],
      "properties": {
        "listing_id": { "$ref": "#/$defs/uuid" },
        "listing_title": { "type": "string" },
        "provider_name": { "type": "string", "description": "Anbietende Organisation." },
        "team_ids": { "type": ["array", "null"], "items": { "$ref": "#/$defs/uuid" }, "description": "Teams mit Zugriff; null = gesamte Organisation." },
        "status": { "type": "string" },
        "linked_by": { "type": ["string", "null"], "format": "uuid" },
        "linked_at": { "type": ["string", "null"], "format": "date-time" }
      }
    }
  }
}
