{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hejstack.com/export-specs/aufgaben.schema.json",
  "title": "hejstack Export: aufgaben.json",
  "description": "Definitionen aller E-Mail-Aufgaben (Automatisierungen) und die gespeicherten Laufergebnisse. E-Mail-Inhalte selbst werden von hejstack nicht gespeichert und sind daher nicht Teil des Exports; Ergebnisse sind die von der Aufgabe erzeugten Texte. Exportformat 1.0, Stand 15.09.2026.",
  "type": "object",
  "required": ["format_version", "task_definitions", "task_runs"],
  "properties": {
    "format_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+$" },
    "task_definitions": { "type": "array", "items": { "$ref": "#/$defs/task_definition" } },
    "task_runs": { "type": "array", "items": { "$ref": "#/$defs/task_run" } }
  },
  "$defs": {
    "uuid": { "type": "string", "format": "uuid" },
    "task_definition": {
      "type": "object",
      "required": ["id", "owner_user_id", "name", "mode", "instruction", "created_at"],
      "properties": {
        "id": { "$ref": "#/$defs/uuid" },
        "owner_user_id": { "$ref": "#/$defs/uuid", "description": "Eigentümer (siehe nutzer.json); Aufgaben sind persönlich." },
        "name": { "type": "string", "maxLength": 120 },
        "mode": { "type": "string", "enum": ["summary", "per_email", "draft"], "description": "summary = eine Zusammenfassung, per_email = Ergebnis je E-Mail, draft = Antwortentwurf im Postfach." },
        "instruction": { "type": "string", "description": "Anweisung an das Sprachmodell (Freitext)." },
        "mailbox_connection_id": { "type": ["string", "null"], "format": "uuid", "description": "Ziel-Postfach (siehe konfiguration.json → mailboxes); null = persönliches Microsoft-365-Postfach des Eigentümers." },
        "source_filter": {
          "type": "object",
          "description": "Welche E-Mails die Aufgabe verarbeitet.",
          "properties": {
            "folder_id": { "type": ["string", "null"], "description": "Postfach-Ordner (Kennung des Mailsystems); null = Posteingang." },
            "unread_only": { "type": "boolean" },
            "unanswered_only": { "type": "boolean" },
            "window_hours": { "type": "integer", "minimum": 1, "description": "Zeitfenster in Stunden rückwärts." },
            "from_address": { "type": ["string", "null"], "description": "Nur Absender (Teilstring)." },
            "keyword": { "type": ["string", "null"], "description": "Nur E-Mails mit diesem Stichwort." },
            "cap": { "type": "integer", "minimum": 1, "description": "Maximale Anzahl E-Mails je Lauf." }
          }
        },
        "knowledge_group_ids": { "type": "array", "items": { "$ref": "#/$defs/uuid" }, "description": "Wissensgruppen, mit denen der Lauf angereichert wird." },
        "is_builtin": { "type": "boolean", "description": "Von hejstack vorgegebene Vorlage (editierbar)." },
        "position": { "type": "integer" },
        "schedule": {
          "type": "object",
          "description": "Zeitplan (Zeitzone Europe/Berlin); leer, wenn nicht zeitgesteuert.",
          "properties": {
            "kind": { "type": "string", "enum": ["hourly", "daily", "weekly", "weekdays", "weekends", "biweekly", "minutely"] },
            "minute": { "type": "integer", "minimum": 0, "maximum": 59 },
            "hour": { "type": "integer", "minimum": 0, "maximum": 23 },
            "weekday": { "type": "integer", "minimum": 0, "maximum": 6, "description": "0 = Montag … 6 = Sonntag." }
          }
        },
        "schedule_enabled": { "type": "boolean" },
        "created_at": { "type": "string", "format": "date-time" },
        "updated_at": { "type": ["string", "null"], "format": "date-time" }
      }
    },
    "task_run": {
      "type": "object",
      "required": ["id", "user_id", "status", "trigger", "created_at"],
      "properties": {
        "id": { "$ref": "#/$defs/uuid" },
        "user_id": { "$ref": "#/$defs/uuid" },
        "task_definition_id": { "type": ["string", "null"], "format": "uuid", "description": "null, wenn die Aufgabe inzwischen gelöscht wurde (title / mode sind Momentaufnahmen)." },
        "title": { "type": ["string", "null"] },
        "mode": { "type": ["string", "null"], "enum": ["summary", "per_email", "draft", null] },
        "trigger": { "type": "string", "enum": ["manual", "schedule"] },
        "status": { "type": "string", "enum": ["pending", "running", "completed", "failed", "cancelled"] },
        "model": { "type": ["string", "null"], "description": "Verwendetes Sprachmodell." },
        "source_count": { "type": "integer", "description": "Anzahl gefundener E-Mails." },
        "item_count": { "type": "integer" },
        "done_count": { "type": "integer" },
        "started_at": { "type": ["string", "null"], "format": "date-time" },
        "finished_at": { "type": ["string", "null"], "format": "date-time" },
        "error": { "type": ["string", "null"] },
        "result": { "type": ["string", "null"], "description": "Gespeichertes Ergebnis (Markdown), entschlüsselt; null, wenn nicht gespeichert oder abgelaufen." },
        "created_at": { "type": "string", "format": "date-time" }
      }
    }
  }
}
