{
  "openapi": "3.1.0",
  "info": {
    "title": "LiteLog Public API",
    "version": "1.0",
    "description": "Public REST API for third-party integrations (property-management systems,\nmiddleware). Authentication via tenant API keys (Portal → Einstellungen →\nIntegrationen → REST-API). The raw key is shown exactly once at creation.\n\nBase URL: https://api.litelog.de/api\n\nConventions:\n- Auth header: `X-Api-Key: ll_live_…` (alternatively `Authorization: Bearer ll_live_…`)\n- Package requirement: the whole /v1 surface (incl. /v1/me) needs the\n  `public_api` entitlement. It is included from the plan \"Betrieb\"\n  (package key `standard`) upwards; in contracts of the earlier per-seat\n  model that means 6 or more seats. Below that every operation yields\n  `403 {\"error\":\"ENTITLEMENT_MISSING\",\"feature\":\"public_api\"}`.\n- Every key carries scopes; a missing scope yields 403 regardless of role.\n- Outgoing webhooks (/v1/webhooks) push events to your URL, signed with\n  HMAC-SHA256 — see the `webhooks` section of this document.\n- Writes are idempotent where a client `uuid` is accepted (tasks, properties, material).\n  The key may also be sent as header `Idempotency-Key` on `POST /v1/properties`,\n  `/v1/properties/{id}/copy`, `/v1/tasks`, `/v1/tasks/{id}/copy`, `/v1/routes/{id}/copy`,\n  `/v1/tours/{id}/copy`, `/v1/customers/{id}/copy`, `/v1/accounts/{id}/copy`, `/v1/material/counts`, `/v1/material/requests` (a UUID) and\n  `/v1/exports` (the `idempotency_key`); header and body that differ ⇒ 422.\n- Rate limit: 120 requests/min per key (429 beyond that). Every answer carries\n  `RateLimit-Policy` (`120;w=60`) and `RateLimit` (`limit=…, remaining=…, reset=…`,\n  draft-ietf-httpapi-ratelimit-headers) besides the older `X-RateLimit-*`;\n  a 429 carries `Retry-After` in seconds.\n- Answers are never cacheable: `Cache-Control: no-store`.\n- IP allowlist: a key may be restricted to addresses or CIDR networks\n  (`allowed_ips` when creating or changing the key). A call from any other\n  address ⇒ `403` \"IP address not allowed for this API key\".\n- Errors: `{ \"message\": string, \"code\": string }` with proper HTTP status.\n- Change reason: a tenant may require a reason for every settings change\n  (Portal → Compliance → \"Änderungsgrund erforderlich\"). Send it as header\n  `X-Change-Reason` (URI-encoded) or as body field `change_reason` where\n  the body accepts it. Prefix it with a reason code: `[correction] …`,\n  `[new_requirement] …`, `[customer_request] …`, `[error_fix] …`,\n  `[periodic_review] …` or `[other] …`. Missing reason ⇒ `422` with\n  `reason: CHANGE_REASON_REQUIRED`. The same applies to changes that the\n  tenant's change approval requires a request for.\n  Creating never needs a reason (initial creation): `POST /v1/tasks`,\n  `/v1/accounts`, `/v1/control-points`, `/v1/control-point-areas`,\n  `/v1/form-templates`, `/v1/form-templates/catalog/import`,\n  `/v1/workflow-rules` and `/v1/incidents/{id}/task` answer without one\n  even when the tenant requires reasons; a `change_reason` given anyway is\n  stored with the `created` row of the configuration audit trail (without\n  one the trail shows \"Initial creation\"). Creating under change approval\n  (roles, patrol routes) still files a request and needs the reason.\n  Report templates (`/v1/report-templates`) are outside change control\n  altogether: no verb needs a reason, nothing is written to the\n  configuration audit trail — as in the portal editor.\n  The main menu (`/v1/nav-layout`) never needs a reason either: it is\n  presentation only (a `X-Change-Reason` given anyway is stored).\n"
  },
  "servers": [
    {
      "url": "https://api.litelog.de/api",
      "description": "Production"
    }
  ],
  "security": [
    {
      "ApiKeyHeader": []
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key"
      }
    },
    "parameters": {
      "Page": {
        "name": "page",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "default": 1
        }
      },
      "PageSize": {
        "name": "pageSize",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 50
        }
      },
      "IdempotencyKeyUuid": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "schema": {
          "type": "string",
          "format": "uuid"
        },
        "description": "Idempotency key as a header (draft-ietf-httpapi-idempotency-key-header),\nan alternative to the body field `uuid`. Without `uuid` in the body the\nheader becomes the `uuid` (and so the id of the record); a repeated\ncall with the same key and the same body answers 200 with\n`duplicate: true` instead of creating twice. The same key with a\nDIFFERENT body ⇒ `422 IDEMPOTENCY_KEY_PAYLOAD_MISMATCH` (since\n22.10.2026; the body fingerprint — SHA-256 of the canonical JSON\nwithout the key itself — is stored on create; records created before\ncarry none and replay as before). Header and body `uuid` that differ\n⇒ `422` (`path: [\"Idempotency-Key\"]`). Must be a UUID on this endpoint.\n"
      },
      "IdempotencyKeyText": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "schema": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._:-]{8,64}$"
        },
        "description": "Idempotency key as a header, an alternative to the body field\n`idempotency_key` (same rules: 8–64 characters of A-Z a-z 0-9 . _ : -).\nWithout the body field the header is taken as it; header and body that\ndiffer ⇒ `422` (`path: [\"Idempotency-Key\"]`).\n"
      },
      "XChangeReason": {
        "name": "X-Change-Reason",
        "in": "header",
        "required": false,
        "schema": {
          "type": "string",
          "maxLength": 2000
        },
        "description": "Reason for the change, URI-encoded, prefixed with a reason code:\n`[correction]`, `[new_requirement]`, `[customer_request]`,\n`[error_fix]`, `[periodic_review]` or `[other]`, e.g.\n`%5Bcorrection%5D%20typo%20in%20name`. Required when the tenant policy\n\"Änderungsgrund erforderlich\" is on, or when the change needs an\napproval request; stored in the configuration audit trail.\n"
      }
    },
    "responses": {
      "ChangeReasonRequired": {
        "description": "The tenant requires a change reason (or the change needs an approval\nrequest) and none was given. Repeat the call with `X-Change-Reason`\n(or body `change_reason`).\n",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string",
                  "enum": [
                    "CHANGE_REASON_REQUIRED"
                  ]
                },
                "reason": {
                  "type": "string",
                  "enum": [
                    "CHANGE_REASON_REQUIRED"
                  ]
                },
                "entity_type": {
                  "type": "string",
                  "description": "Area of the change, e.g. control_point, area, account, company_settings, role."
                },
                "label": {
                  "type": "string",
                  "description": "Human-readable label of the area (German)."
                },
                "message": {
                  "type": "string"
                },
                "errorCode": {
                  "type": "string",
                  "enum": [
                    "UNPROCESSABLE_ENTITY"
                  ]
                },
                "errors": {
                  "type": "array",
                  "items": {}
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "AppViewLayout": {
        "type": "object",
        "required": [
          "version",
          "widgets"
        ],
        "additionalProperties": false,
        "description": "Array order = display order; a catalogue key left out stays enabled.",
        "properties": {
          "version": {
            "type": "integer",
            "enum": [
              1
            ]
          },
          "widgets": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "key",
                "enabled"
              ],
              "properties": {
                "key": {
                  "type": "string",
                  "enum": [
                    "status-hero",
                    "my-shift-today",
                    "quick-actions",
                    "statusgeber",
                    "workspace"
                  ]
                },
                "enabled": {
                  "type": "boolean"
                }
              }
            }
          },
          "quick_actions": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "key",
                "enabled"
              ],
              "properties": {
                "key": {
                  "type": "string",
                  "enum": [
                    "route",
                    "forms",
                    "report",
                    "task",
                    "material",
                    "status",
                    "sos",
                    "nfc"
                  ]
                },
                "enabled": {
                  "type": "boolean"
                }
              }
            }
          },
          "workspace_scope": {
            "type": "string",
            "enum": [
              "all",
              "spontaneous"
            ]
          }
        }
      },
      "Property": {
        "type": "object",
        "properties": {
          "property_id": {
            "type": "integer"
          },
          "uuid": {
            "type": "string",
            "format": "uuid",
            "description": "Stable id of the property (the `uuid` passed on creation, else server-generated). Also the id in the portal URL `/property/{uuid}`."
          },
          "name": {
            "type": "string"
          },
          "region": {
            "type": [
              "string",
              "null"
            ]
          },
          "street": {
            "type": [
              "string",
              "null"
            ]
          },
          "house_number": {
            "type": [
              "string",
              "null"
            ]
          },
          "postal_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "city": {
            "type": [
              "string",
              "null"
            ]
          },
          "country": {
            "type": [
              "string",
              "null"
            ]
          },
          "customer_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "archived": {
            "type": "boolean",
            "description": "true once `archive_at` is reached (the portal shows \"wird archiviert am\" until then)."
          },
          "archive_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Scheduled or effective archive date, null = not archived."
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "wt_exec_windows_mode": {
            "type": "string",
            "enum": [
              "off",
              "inherit",
              "custom"
            ],
            "description": "Execution windows (allowed start windows of time tracking per day\ntype). `off` = no window rule, `inherit` = tenant default from\nSettings → Defaults, `custom` = the property's own windows.\n"
          },
          "wt_exec_windows": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ExecWindows"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "ExecWindows": {
        "type": "object",
        "description": "Allowed start windows of time tracking, wall clock of the property\n(HH:mm). Outside every window a start is refused (app, NFC reader,\nkiosk, chat, clock-in) — clocking out is always allowed. A window may\nspan midnight (22:00–06:00). `weekend` = Saturday, Sunday and the\nproperty's public holidays; `null` = same windows as on weekdays.\n",
        "required": [
          "weekday"
        ],
        "properties": {
          "weekday": {
            "type": "array",
            "maxItems": 12,
            "items": {
              "$ref": "#/components/schemas/ExecWindow"
            }
          },
          "weekend": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 12,
            "items": {
              "$ref": "#/components/schemas/ExecWindow"
            }
          }
        }
      },
      "ExecWindow": {
        "type": "object",
        "required": [
          "start",
          "end"
        ],
        "properties": {
          "start": {
            "type": "string",
            "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
            "example": "06:00"
          },
          "end": {
            "type": "string",
            "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
            "example": "10:00"
          }
        }
      },
      "PropertyLocation": {
        "type": "object",
        "description": "Coordinates of the property. `point` is the marker as `[lat, lng]`\n(the app's wire convention); `area` is an optional GeoJSON polygon\nused by geofence verification — ONE ring of 4–500 positions in\nGeoJSON order `[lng, lat]`. An open ring (first ≠ last position)\nis closed server-side. No server-side geocoding: an integration\npasses the coordinates it knows.\n",
        "required": [
          "point"
        ],
        "properties": {
          "point": {
            "type": "array",
            "minItems": 2,
            "maxItems": 2,
            "items": {
              "type": "number"
            },
            "description": "[lat, lng]; lat −90…90, lng −180…180.",
            "example": [
              48.137154,
              11.576124
            ]
          },
          "area": {
            "type": [
              "object",
              "null"
            ],
            "required": [
              "type",
              "coordinates"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "Polygon"
                ]
              },
              "coordinates": {
                "type": "array",
                "minItems": 1,
                "maxItems": 1,
                "description": "Exactly one ring (no holes).",
                "items": {
                  "type": "array",
                  "minItems": 4,
                  "maxItems": 500,
                  "items": {
                    "type": "array",
                    "minItems": 2,
                    "maxItems": 2,
                    "items": {
                      "type": "number"
                    },
                    "description": "[lng, lat]"
                  }
                }
              }
            }
          }
        }
      },
      "PropertyShiftDefaults": {
        "type": "object",
        "description": "Shift defaults of the property — the same object as\nPUT /v1/… shift-defaults in the portal (check-in/check-out windows,\nrequirement modes, channels, auto check-out, minimum durations,\ninstructions). Every field optional/nullable; `null` = no default\nfor this field (the tenant default applies). Offsets in minutes\n0–1440, grace 0–240, required counts 0–999, instructions ≤ 2000\ncharacters.\n",
        "properties": {
          "checkin_start_offset_min": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 1440
          },
          "checkin_end_offset_min": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 1440
          },
          "checkin_requirement_mode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "optional",
              "minimum",
              "fixed",
              null
            ]
          },
          "required_checkins": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 999
          },
          "checkin_attendance_channels": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "checkout_start_offset_min": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 1440
          },
          "checkout_end_offset_min": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 1440
          },
          "checkout_requirement_mode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "optional",
              "minimum",
              "fixed",
              null
            ]
          },
          "required_checkouts": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 999
          },
          "checkout_attendance_channels": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "checkout_same_as_checkin": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "auto_checkout_enabled": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "auto_checkout_offset_min": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 1440
          },
          "min_duration_per_visit_minutes": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 1440
          },
          "min_duration_total_minutes": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 1440
          },
          "min_duration_grace_minutes": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 240
          },
          "instructions": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 2000
          }
        }
      },
      "PropertySettings": {
        "type": "object",
        "description": "Every property setting the API can set — the flat column names of\nthe property (`wt_*` = time tracking, `show_*` = modules,\n`*_verification` = tamper protection, `*_esignature` = digital\nsignature). All fields optional; on PATCH an omitted field is left\nuntouched and `null` clears it. Limits are the portal's.\n`location_lock` is not exposed (it mirrors the `*_verification`\nfields); `geofence_auto` is not accepted as a check-in/out method\n(derived server-side from geofence verification).\n",
        "properties": {
          "timezone": {
            "type": "string",
            "description": "IANA name, e.g. Europe/Berlin."
          },
          "notes": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 10000
          },
          "category_id": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Property category of the tenant (404 CATEGORY_NOT_FOUND otherwise)."
          },
          "responsible_account_ids": {
            "type": "array",
            "maxItems": 10,
            "uniqueItems": true,
            "items": {
              "type": "integer"
            },
            "description": "Responsible persons in rank order — active, non-customer accounts of the tenant (400 RESPONSIBLE_NOT_ASSIGNABLE otherwise)."
          },
          "workdays": {
            "type": "array",
            "maxItems": 7,
            "uniqueItems": true,
            "items": {
              "type": "integer",
              "minimum": 0,
              "maximum": 6
            },
            "description": "Working days, 0 = Sunday … 6 = Saturday."
          },
          "show_time": {
            "type": "boolean",
            "description": "Module time tracking."
          },
          "show_routes": {
            "type": "boolean",
            "description": "Module tasks & patrols."
          },
          "show_incidents": {
            "type": "boolean",
            "description": "Module incidents & forms."
          },
          "show_docs": {
            "type": "boolean",
            "description": "Module documents."
          },
          "show_chat": {
            "type": "boolean",
            "description": "Module team chat."
          },
          "show_material": {
            "type": "boolean",
            "description": "Module material."
          },
          "show_status": {
            "type": "boolean",
            "description": "Module status / proof of life."
          },
          "show_bookings": {
            "type": "boolean",
            "description": "Module bookings (vacation rentals)."
          },
          "wt_variant": {
            "type": [
              "string",
              "null"
            ],
            "description": "Default check-in method."
          },
          "wt_end_variant": {
            "type": [
              "string",
              "null"
            ],
            "description": "Default check-out method."
          },
          "wt_allowed_checkin_methods": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "button_click",
                "qr_code_static",
                "nfc_scanner_device",
                "nfc_tag",
                "manual",
                "chatbot"
              ]
            },
            "description": "App-based (button_click, manual, chatbot) and location-based methods (qr_code_static, nfc_scanner_device, nfc_tag) cannot be mixed (422)."
          },
          "wt_allowed_checkout_methods": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "button_click",
                "qr_code_static",
                "nfc_scanner_device",
                "nfc_tag",
                "manual",
                "chatbot"
              ]
            },
            "description": "Same rule as wt_allowed_checkin_methods."
          },
          "wt_allow_checkin_exceptions": {
            "type": "boolean"
          },
          "wt_allow_checkout_exceptions": {
            "type": "boolean"
          },
          "wt_force_tracking": {
            "type": "boolean",
            "description": "GPS tracking during the visit."
          },
          "web_checkin_enabled": {
            "type": "boolean",
            "description": "Web check-in without the app (NFC chip / QR code opens a portal page, the person enters their personnel number). Independent of the method lists, which only apply to app users."
          },
          "web_checkin_pin_required": {
            "type": "boolean",
            "description": "Web check-in via chip/poster or phone asks for personnel number AND PIN (same PIN as for e-signatures). The tablet at the entrance always asks for the PIN. New properties default to true."
          },
          "wt_close_at": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
            "description": "Auto close at wall-clock time (HH:mm)."
          },
          "wt_close_after_min": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "description": "Auto close after n minutes."
          },
          "wt_close_after_basis": {
            "type": "string",
            "enum": [
              "gross",
              "net"
            ]
          },
          "wt_pause_days": {
            "type": [
              "object",
              "null"
            ],
            "description": "Minimum pauses per ISO weekday ('1' = Monday … '7' = Sunday): list of { after_minutes, pause_minutes } thresholds.",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "object"
              }
            }
          },
          "wt_max_pause_min": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 1
          },
          "wt_disable_on": {
            "type": [
              "array",
              "null"
            ],
            "maxItems": 12,
            "items": {
              "$ref": "#/components/schemas/ExecWindow"
            },
            "description": "Blocked time windows (no check-in), wall clock HH:mm."
          },
          "worktime_view_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "wt_auto_close_on_next_checkin": {
            "type": "boolean"
          },
          "wt_beacon_threshold_m": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0.1,
            "maximum": 999
          },
          "wt_max_visits_per_week": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1
          },
          "wt_visit_gap_mode": {
            "type": "string",
            "enum": [
              "off",
              "inherit",
              "custom"
            ]
          },
          "wt_min_visit_gap_minutes": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 10080
          },
          "wt_min_visit_gap_minutes_weekend": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 10080
          },
          "wt_max_visit_gap_minutes": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 10080
          },
          "wt_max_visit_gap_minutes_weekend": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 10080
          },
          "wt_service_from": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
            "description": "Service window start; both or none, from < to."
          },
          "wt_service_to": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
          },
          "wt_visit_gap_grace_minutes": {
            "type": "integer",
            "minimum": 0,
            "maximum": 240
          },
          "visit_gap_rule_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Violation rule for visit gaps; must be a rule of the tenant of type attendance violation (404 unknown, 400 wrong type / not assignable)."
          },
          "wt_exec_windows_mode": {
            "type": "string",
            "enum": [
              "off",
              "inherit",
              "custom"
            ]
          },
          "wt_exec_windows": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ExecWindows"
              },
              {
                "type": "null"
              }
            ]
          },
          "wt_verification": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "none",
              "geofencing",
              "beacon",
              null
            ],
            "description": "Tamper protection for time tracking. `geofencing` also sets the location lock of the feature; `beacon` and `none` clear it."
          },
          "routes_verification": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "none",
              "geofencing",
              "beacon",
              null
            ]
          },
          "incidents_verification": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "none",
              "geofencing",
              "beacon",
              null
            ]
          },
          "forms_verification": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "none",
              "geofencing",
              "beacon",
              null
            ]
          },
          "tasks_verification": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "none",
              "geofencing",
              "beacon",
              null
            ]
          },
          "incidents_esignature": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "none",
              "required",
              null
            ],
            "description": "Digital signature on incidents."
          },
          "forms_esignature": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "none",
              "required",
              null
            ]
          },
          "tasks_esignature": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "none",
              "required",
              null
            ]
          },
          "esignature_allowed_methods": {
            "type": [
              "array",
              "null"
            ],
            "minItems": 1,
            "items": {
              "type": "string",
              "enum": [
                "password",
                "nfc",
                "qr",
                "pin"
              ]
            }
          },
          "routes_auto_end_minutes": {
            "type": "integer",
            "minimum": 30,
            "maximum": 1440,
            "description": "Patrols end automatically after n minutes. Read: the effective value (company default when routes_rules_mode is inherit)."
          },
          "routes_allow_photo_fallback": {
            "type": "boolean",
            "description": "Photo instead of a scan at a checkpoint. Read: the effective value (company default when routes_rules_mode is inherit)."
          },
          "routes_rules_mode": {
            "type": "string",
            "enum": [
              "inherit",
              "custom"
            ],
            "description": "Patrol rules: inherit = auto-end, photo fallback and patrol location lock follow the company's property defaults; custom = this property's own values. Writing routes_auto_end_minutes or routes_allow_photo_fallback without a mode makes the property custom."
          },
          "ai_incident_classification": {
            "type": "boolean"
          },
          "incident_rule_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Incident reaction rule of the tenant (404 unknown, 400 wrong type / not assignable)."
          },
          "proof_type": {
            "type": "string",
            "enum": [
              "attendance",
              "tour",
              "completion",
              "protocol"
            ],
            "description": "Proof of service the customer sees for this property: attendance, tour (patrols), completion (tasks) or protocol (forms). Default by industry (cleaning → completion, security → tour, else attendance)."
          },
          "customer_visibility": {
            "type": "string",
            "enum": [
              "pseudonym",
              "names",
              "none"
            ],
            "description": "What the customer portal shows for the proof: pseudonyms (default), real names, or nothing (the proof module is hidden for this property)."
          },
          "notification_emails": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "string",
              "format": "email"
            },
            "description": "Recipients of property notifications. Each address must already exist as a mail recipient of the tenant (422 MAIL_UNKNOWN) — the API does not create recipients."
          },
          "shift_defaults": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/PropertyShiftDefaults"
              },
              {
                "type": "null"
              }
            ]
          },
          "location": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/PropertyLocation"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "PropertyCreate": {
        "description": "Body of POST /v1/properties: master data plus any subset of\nPropertySettings. Unknown fields are rejected (422).\n",
        "allOf": [
          {
            "type": "object",
            "required": [
              "name"
            ],
            "properties": {
              "uuid": {
                "type": "string",
                "format": "uuid",
                "description": "Idempotency key chosen by the client; becomes the property's\n`uuid` and portal URL id. A repeated call with the same key\nreturns the property created first (200, `duplicate: true`)\nand ignores differing fields.\n"
              },
              "settings_from_property_id": {
                "type": "integer",
                "description": "Copy the settings of a property the key can see as the base (time tracking, verification, signature, patrols, incidents, modules, workdays, timezone, shift defaults). Explicit fields override. Master data, address, coordinates, customer, category and responsible persons are never copied. Invisible or unknown → 404."
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "street": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 200
              },
              "house_number": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 20
              },
              "postal_code": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 20
              },
              "city": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 200
              },
              "country": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "ISO 3166-1 alpha-2 (`DE`). Known country names (`Deutschland`, `Germany`) and lower case are normalised; anything else answers 422."
              },
              "region": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "ISO 3166-2 subdivision part (`BY` for Bavaria), only together\nwith `country`. With `country: DE` the public holidays of the\nregion are created automatically for the next years. Changing\n`country` or `region` later replaces the automatically created\nfuture public holidays.\n"
              },
              "customer_id": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Customer of the tenant (404 CUSTOMER_NOT_FOUND otherwise); the customer's portal access is synced to the property as in the portal."
              }
            }
          },
          {
            "$ref": "#/components/schemas/PropertySettings"
          }
        ]
      },
      "PropertyUpdate": {
        "description": "Body of PATCH /v1/properties/{id}: the same field set as\nPropertyCreate without `uuid` and `settings_from_property_id`, every\nfield optional, at least one field. Plus `change_reason` when the\ntenant runs change approval.\n",
        "allOf": [
          {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "street": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 200
              },
              "house_number": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 20
              },
              "postal_code": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 20
              },
              "city": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 200
              },
              "country": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "ISO 3166-1 alpha-2 or a known country name. Changing `country` or `region` replaces the automatically created future public holidays."
              },
              "region": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "ISO 3166-2 subdivision part, only together with `country`. Changing `country` or `region` replaces the automatically created future public holidays."
              },
              "customer_id": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "change_reason": {
                "type": "string",
                "description": "Reason for the change approval (alternatively header `X-Change-Reason`)."
              }
            }
          },
          {
            "$ref": "#/components/schemas/PropertySettings"
          }
        ]
      },
      "PropertyDetail": {
        "description": "Full property as GET /v1/properties/{id} returns it: master data,\nevery field of PropertySettings as stored, `location`,\n`responsible_account_ids`, `notification_emails`, `shift_defaults`.\n",
        "allOf": [
          {
            "$ref": "#/components/schemas/Property"
          },
          {
            "$ref": "#/components/schemas/PropertySettings"
          },
          {
            "type": "object",
            "properties": {
              "category_name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "portal_url": {
                "type": "string",
                "description": "Link to the property in the portal (`…/property/{uuid}`)."
              }
            }
          }
        ]
      },
      "PropertyCopy": {
        "description": "Body of POST /v1/properties/{id}/copy. Every field is optional; an\nempty body copies master data and settings only. Any field of\nPropertyUpdate may be given and then wins against the source.\n",
        "allOf": [
          {
            "type": "object",
            "properties": {
              "uuid": {
                "type": "string",
                "format": "uuid",
                "description": "Idempotency key (alternatively header `Idempotency-Key`); becomes the `uuid` of the copy."
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200,
                "description": "Default: name of the source + ` (Kopie)`, shortened to fit 200 characters."
              },
              "street": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 200
              },
              "house_number": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 20
              },
              "postal_code": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 20
              },
              "city": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 200
              },
              "country": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "region": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "customer_id": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Default: the customer of the source. Another customer of the tenant copies the property to that customer."
              },
              "include": {
                "type": "object",
                "additionalProperties": false,
                "description": "What to take along besides master data and settings. Default nothing.",
                "properties": {
                  "control_points": {
                    "type": "boolean"
                  },
                  "routes": {
                    "type": "boolean",
                    "description": "Needs `control_points` and `start_date`."
                  },
                  "recurring_tasks": {
                    "type": "boolean",
                    "description": "Needs `start_date`."
                  },
                  "account_assignments": {
                    "type": "boolean"
                  }
                }
              },
              "start_date": {
                "type": "string",
                "format": "date",
                "description": "Day from which copied routes and task series run (YYYY-MM-DD, not in the past)."
              },
              "change_reason": {
                "type": "string",
                "description": "Reason for the audit trail and the change approval (alternatively header `X-Change-Reason`)."
              }
            }
          },
          {
            "$ref": "#/components/schemas/PropertySettings"
          }
        ]
      },
      "PropertyCopyPart": {
        "type": [
          "object",
          "null"
        ],
        "description": "Result of one part; `null` when the part was not included.",
        "properties": {
          "copied": {
            "type": "integer"
          },
          "skipped": {
            "type": "integer",
            "description": "Deliberately not copied (ended series, no control point left) — see `issues`."
          },
          "failed": {
            "type": "integer",
            "description": "Creation refused or failed — see `issues`."
          },
          "approval_pending": {
            "type": "integer",
            "description": "Routes only: change requests created instead of routes."
          }
        }
      },
      "PropertyCopyResult": {
        "type": "object",
        "description": "What a copy took along. Nothing is dropped silently — every record that did not come along is listed in `issues`.",
        "properties": {
          "source_property_id": {
            "type": "integer"
          },
          "start_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "control_points": {
            "$ref": "#/components/schemas/PropertyCopyPart"
          },
          "routes": {
            "$ref": "#/components/schemas/PropertyCopyPart"
          },
          "recurring_tasks": {
            "$ref": "#/components/schemas/PropertyCopyPart"
          },
          "account_assignments": {
            "$ref": "#/components/schemas/PropertyCopyPart"
          },
          "issues": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "part",
                "name",
                "code",
                "message"
              ],
              "properties": {
                "part": {
                  "type": "string",
                  "enum": [
                    "control_points",
                    "routes",
                    "recurring_tasks",
                    "account_assignments"
                  ]
                },
                "name": {
                  "type": "string",
                  "description": "Name of the record in the source (`account <id>` for assignments, `*` when a whole part failed)."
                },
                "code": {
                  "type": "string",
                  "description": "E.g. `ROUTE_SERIES_ENDED`, `ROUTE_SINGLE_DATE_PASSED`, `ROUTE_WITHOUT_CONTROL_POINTS`, `ROUTE_CONTROL_POINTS_MISSING`, `ROUTE_RULE_NOT_COPIED`, `ROUTE_APPROVAL_PENDING`, `TASK_SERIES_ENDED`, `TASK_WITHOUT_BINDINGS` (not copied: it only belonged to control points or routes that were not copied), `TASK_BINDINGS_NOT_COPIED` (copied without its link), `TASK_ASSIGNEES_NOT_COPIED`, `TASK_PARTLY_COPIED`, `AREA_NOT_COPIED`, `PART_FAILED`, or the `reason` of the create path that refused the record."
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "PropertyWarning": {
        "type": "object",
        "description": "Something that did not stop the write but deserves attention:\n`geofence_without_area` (a verification is `geofencing` but no\n`location.area` was given), `settings_copied` (a template was\napplied), `rule_not_copied` (a rule of the template is not scoped\nglobally), `holidays_failed`, `customer_access_sync_failed`,\n`device_push_failed`.\n",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "PropertyBulkResult": {
        "type": "object",
        "description": "Result of POST /v1/properties/bulk. Partial success is the contract:\nafter the pre-check every row runs in its own transaction, so one\nfailing row does not undo the others. `index` is the position in the\nrequest. `reason` of a failed row: `PROPERTY_KEY_TAKEN` (uuid in use\nby a property the key cannot see), `RULE_NOT_ASSIGNABLE`,\n`CONFLICT`, `INTERNAL` (logged server-side, no detail).\n",
        "required": [
          "created",
          "duplicates",
          "failed",
          "holidays_created"
        ],
        "properties": {
          "created": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "property_id": {
                  "type": "integer"
                },
                "uuid": {
                  "type": "string",
                  "format": "uuid"
                },
                "portal_url": {
                  "type": "string"
                }
              }
            }
          },
          "duplicates": {
            "type": "array",
            "description": "Rows whose `uuid` already named a property of this key — nothing written, the existing property is returned.",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "property_id": {
                  "type": "integer"
                },
                "uuid": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          },
          "failed": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "reason": {
                  "type": "string",
                  "enum": [
                    "PROPERTY_KEY_TAKEN",
                    "IDEMPOTENCY_KEY_PAYLOAD_MISMATCH",
                    "RULE_NOT_ASSIGNABLE",
                    "CONFLICT",
                    "INTERNAL"
                  ]
                },
                "message": {
                  "type": "string"
                }
              }
            }
          },
          "holidays_created": {
            "type": "integer",
            "description": "Public holidays created over all rows."
          }
        }
      },
      "Task": {
        "type": "object",
        "properties": {
          "task_id": {
            "type": "integer"
          },
          "uuid": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "state_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "property_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "labels": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "due_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "due_time": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
            "description": "Due time of day (HH:mm, wall clock of the task's property, else the account). Only together with due_date; null = all day."
          },
          "due_end_time": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
            "description": "End of the due window (HH:mm, one-off tasks, since 2026-10-13). Only together with due_time and after it. Between due_time and due_end_time the task is \"due until\" and NOT listed under due=overdue; it counts as overdue from the minute after the end. null = due at due_time. Always null for a task with an active schedule (the rule carries end_time)."
          },
          "archived_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Soft archive (PR U) — when the task was archived; null = active. There is no DELETE for tasks; use POST /v1/tasks/{id}/archive and /restore."
          },
          "form_template_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Form template that must be filled in on completion (null = none). Ids come from GET /v1/form-templates."
          },
          "require_scan": {
            "type": "boolean",
            "description": "\"Complete only at the point\": completion requires a checkpoint scan (effective with CHECKPOINT bindings)."
          },
          "photo_required": {
            "type": "boolean",
            "description": "One photo per completion of the whole task. Waived while the required checklist (`checklist_required`) has photo points."
          },
          "checklist_required": {
            "type": "boolean",
            "description": "checklist_required = all items are required (required checklist): every point ticked or marked not applicable with a reason, every photo point has a photo; off = points may stay open, open points show in the report. Task-level photo_required is waived while the required checklist has photo points.\nThe completion record stores the checklist per point as `checklist_state`:\n`{ \"<item_id>\": true | false | { \"na\": true, \"reason\": \"<text>\" } }` —\nticked, open, or not applicable with a mandatory reason (n/a counts as\nticked and photographed). Completing against an incomplete proof\nchecklist fails with 422 `errorCode: CHECKLIST_INCOMPLETE`.\n"
          },
          "assignee_ids": {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "description": "All assigned accounts (people), in assignment order. In GET\n/v1/tasks and GET /v1/tasks/{id}; independent of\n`assignee_role_ids` — a task may carry people, roles or both.\n"
          },
          "assignee_role_ids": {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "description": "Roles responsible for the task (ids from GET /v1/roles; names\nare not repeated here). Members are the active accounts holding\nthe role that are assigned to the task's property or work\nglobally (without a property: tenant-wide). They see the task\nunder \"my tasks\", are notified like directly assigned people and\nmatch the `assignee_id` list filter. In GET /v1/tasks and GET\n/v1/tasks/{id}.\n"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "checklist": {
            "type": "array",
            "description": "The checklist of the task (one task, several points). Only in\nGET /v1/tasks/{id} — list rows do not carry it. Empty when the task\nhas no checklist or is bound to a regular form.\n",
            "items": {
              "$ref": "#/components/schemas/TaskChecklistItem"
            }
          },
          "checklist_source": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "items",
              "template",
              null
            ],
            "description": "Where the points live: `items` = plain checklist rows,\n`template` = a background form template of kind `checklist` (at\nleast one point requires a photo), `null` = no checklist (or the\ntask is bound to a regular form). Only in GET /v1/tasks/{id}.\n"
          }
        }
      },
      "TaskChecklistItem": {
        "type": "object",
        "description": "One point of a task checklist. Points are plain rows until one of them\nrequires a photo; from then on LiteLog keeps the checklist as a\nbackground form template (`template_kind: checklist`, scope `tag`,\nnever offered in the app's form hub) bound via `form_template_id`.\nThe API hides that difference: read and write the points here.\n",
        "properties": {
          "item_id": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Row id (source `items`), null for template points."
          },
          "field_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "Field id in the background template (source `template`), null for plain rows. Pass it back on PUT to keep the field (answers and translations hang on it)."
          },
          "title": {
            "type": "string",
            "maxLength": 300
          },
          "photo_required": {
            "type": "boolean"
          },
          "sort_order": {
            "type": "integer"
          }
        }
      },
      "TaskChecklistState": {
        "type": "object",
        "properties": {
          "source": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "items",
              "template",
              null
            ]
          },
          "form_template_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Always null since the one-model change (checklist templates are copied, not bound); kept for older clients."
          },
          "checklist_required": {
            "type": "boolean",
            "description": "All items are required (see Task.checklist_required); off = points may stay open."
          },
          "checklist_template_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Checklist template the points were loaded from (informational, no binding)."
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TaskChecklistItem"
            }
          }
        }
      },
      "TaskBinding": {
        "type": "object",
        "description": "Link of a task to a checkpoint (`CHECKPOINT`, carries `tag_id`) or a\npatrol route (`ROUTE`, carries `route_id`). A ROUTE binding hands the\ntask's recurrence to the route (its own schedule is deactivated).\n`role_ids` = the roles that see the task at this point (the portal's\n\"Am Punkt sichtbar für\"); `null` = the assignee of the task decides\n(only the assigned person or role sees it at the point; a task without\nassignee is seen by every role). Enforced server-side in the scan\nendpoint and the mobile offline pull.\n",
        "properties": {
          "binding_id": {
            "type": "integer"
          },
          "binding_type": {
            "type": "string",
            "enum": [
              "CHECKPOINT",
              "ROUTE"
            ]
          },
          "tag_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "route_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "property_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "role_ids": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "integer"
            },
            "description": "Roles (GET /v1/roles) that see the task here; null = the assignee of the task decides (no assignee = every role)."
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "TaskSchedule": {
        "type": "object",
        "description": "Recurrence plan (SOLL rhythm) of a task — one primary plan per task.",
        "properties": {
          "schedule_id": {
            "type": "integer"
          },
          "repeat_type": {
            "type": "string",
            "enum": [
              "none",
              "daily",
              "weekly",
              "monthly"
            ]
          },
          "weekdays": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "monthdays": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "frequency": {
            "type": "integer"
          },
          "start_date": {
            "type": "string",
            "format": "date"
          },
          "end_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "occurrence_count": {
            "type": [
              "integer",
              "null"
            ]
          },
          "start_time": {
            "type": [
              "string",
              "null"
            ],
            "description": "HH:mm — start of the occurrence."
          },
          "end_time": {
            "type": [
              "string",
              "null"
            ],
            "description": "HH:mm — optional end of the execution window, after start_time. Today's occurrence counts as overdue only after this time; null = after start_time (legacy)."
          },
          "type_freedays": {
            "type": "string",
            "enum": [
              "none",
              "disable",
              "enabled"
            ]
          },
          "anchor_mode": {
            "type": "string",
            "enum": [
              "fixed",
              "completion"
            ]
          },
          "window_mode": {
            "type": "string",
            "enum": [
              "none",
              "days",
              "month"
            ]
          },
          "tolerance_days": {
            "type": [
              "integer",
              "null"
            ]
          },
          "nonworking_rule": {
            "type": "string",
            "enum": [
              "skip",
              "prev",
              "next"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "effective_from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "readOnly": true,
            "description": "Day from which the rule valid TODAY applies (the base version's\n`start_date`, or the `effective_from` of the latest version already\nin force). `null` while the task has no rule version yet. Note that\nthe rule fields above (`weekdays`, `frequency`, …) mirror the NEWEST\nversion — a change planned via `effective_from` shows up there and\nin `upcoming_change`, while this field keeps naming the day the\ncurrent rule started.\n"
          },
          "upcoming_change": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ScheduleVersion"
              },
              {
                "type": "null"
              }
            ],
            "readOnly": true,
            "description": "A rule change that is not effective yet (`effective_from` in the\nfuture) — the newest version, with the rule fields `version_id`,\n`effective_from`, `repeat_type`, `weekdays`, `monthdays`, `frequency`,\n`start_time`, `type_freedays`, `anchor_mode`, `window_mode`,\n`tolerance_days`, `nonworking_rule`. `null` when none is planned.\nDiscard it with DELETE /v1/tasks/{id}/schedule/versions/{versionId}.\n"
          },
          "orphaned_completions": {
            "type": "integer",
            "readOnly": true,
            "description": "Only in the PUT response: completions/reports recorded on days the\nnew rule no longer produces (kept as evidence, no longer matched to\nan occurrence).\n"
          },
          "removed_exceptions": {
            "type": "integer",
            "readOnly": true,
            "description": "Only in the PUT response: per-occurrence exceptions (skip/move) that\nbecame orphaned by the new rule and were removed. Discarding the\nversion restores them.\n"
          }
        }
      },
      "ScheduleVersion": {
        "type": "object",
        "description": "One rule version of a task's series (\"change the series from a date\").\nVersions are ordered by `effective_from`; the first one is the base\nversion (starts at the plan's `start_date`) and cannot be deleted. The\nrule fields have the same meaning as in `TaskSchedule`; `weekdays` use\n0 = Sunday … 6 = Saturday (JavaScript getDay()).\n",
        "properties": {
          "version_id": {
            "type": "integer"
          },
          "effective_from": {
            "type": "string",
            "format": "date",
            "description": "First day the rule applies (anchor day)."
          },
          "repeat_type": {
            "type": "string",
            "enum": [
              "none",
              "daily",
              "weekly",
              "monthly"
            ]
          },
          "weekdays": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 0,
              "maximum": 6
            }
          },
          "monthdays": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 31
            }
          },
          "frequency": {
            "type": "integer"
          },
          "start_time": {
            "type": [
              "string",
              "null"
            ],
            "description": "HH:mm"
          },
          "end_time": {
            "type": [
              "string",
              "null"
            ],
            "description": "HH:mm — optional end of the execution window of this version."
          },
          "type_freedays": {
            "type": "string",
            "enum": [
              "none",
              "disable",
              "enabled"
            ]
          },
          "anchor_mode": {
            "type": "string",
            "enum": [
              "fixed",
              "completion"
            ]
          },
          "window_mode": {
            "type": "string",
            "enum": [
              "none",
              "days",
              "month"
            ]
          },
          "tolerance_days": {
            "type": [
              "integer",
              "null"
            ]
          },
          "nonworking_rule": {
            "type": "string",
            "enum": [
              "skip",
              "prev",
              "next"
            ]
          }
        }
      },
      "OccurrenceException": {
        "type": "object",
        "description": "A live exception for ONE occurrence of a task's series. The occurrence\nis addressed by its key `original_date` = the due day the rule\nproduced (this is also what completions, reports and deep links hang\non). `skip` = the occurrence is dropped, `move` = it is shown on\n`new_date` (optionally at `new_time`). One live exception per\n(task, original_date); posting again replaces it, DELETE undoes it.\n",
        "properties": {
          "original_date": {
            "type": "string",
            "format": "date",
            "description": "Occurrence key (the due day per rule)."
          },
          "action": {
            "type": "string",
            "enum": [
              "skip",
              "move"
            ]
          },
          "new_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Only for `move`."
          },
          "new_time": {
            "type": [
              "string",
              "null"
            ],
            "description": "HH:mm, only for `move`; `null` = the version's start_time."
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "description": "Free text (max. 500), shown in the task history."
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Only in the list response."
          }
        }
      },
      "ApprovalPending": {
        "type": "object",
        "description": "Returned (HTTP 200) instead of the normal body when the tenant's\nfour-eyes change approval covers the entity type: nothing is written\nyet, an approval request `batch_id` was filed for the portal inbox.\nThe request MUST carry a `change_reason` (body field or\n`X-Change-Reason` header, URI-encoded), otherwise 422\n`error: CHANGE_REASON_REQUIRED`. While a request for the same record\nis open, a further call answers 409 `REQUEST_PENDING`.\n",
        "properties": {
          "changed": {
            "type": "boolean",
            "enum": [
              false
            ]
          },
          "approval_pending": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "batch_id": {
            "type": "string",
            "format": "uuid"
          },
          "entity_type": {
            "type": "string",
            "example": "route_config"
          },
          "label": {
            "type": "string",
            "example": "Kontrollgang"
          }
        }
      },
      "Incident": {
        "type": "object",
        "description": "Incident (defect report). AI internals and photo/audio attachments\nstay internal. Status fields are additive (since 2026-09).\n",
        "properties": {
          "incident_id": {
            "type": "integer"
          },
          "uuid": {
            "type": "string",
            "format": "uuid"
          },
          "property_id": {
            "type": "integer"
          },
          "account_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "text": {
            "type": [
              "string",
              "null"
            ]
          },
          "category_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "category_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "severity": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "low",
              "medium",
              "high",
              "critical",
              null
            ]
          },
          "classified_by": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "ai",
              "human",
              null
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "acknowledged",
              "closed"
            ]
          },
          "acknowledged_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "closed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "archived": {
            "type": "boolean"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "lat": {
            "type": [
              "number",
              "null"
            ]
          },
          "lng": {
            "type": [
              "number",
              "null"
            ]
          },
          "source": {
            "type": "string"
          }
        }
      },
      "IncidentStatusChange": {
        "type": "object",
        "properties": {
          "incident_id": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "acknowledged",
              "closed"
            ]
          },
          "status_before": {
            "type": "string",
            "enum": [
              "open",
              "acknowledged",
              "closed"
            ]
          },
          "changed": {
            "type": "boolean",
            "description": "false = already in the target state, nothing written."
          },
          "acknowledged_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "closed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "ChipSource": {
        "type": "object",
        "description": "Where the NFC chip UID comes from — exactly one of `chip_id` (as\nscanned) or `from_tag_id` (taken over from a source tag of the\ntenant: its current binding, or after archiving the most recent UID\nrecorded in the configuration audit). Neither or both → 422.\n",
        "additionalProperties": false,
        "properties": {
          "chip_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "pattern": "^[0-9A-Fa-f:\\s-]{8,}$",
            "description": "NFC chip UID. Normalized to the form the app scans — hex, upper\ncase, no separators (`de:ad:be:ef` → `DEADBEEF`); anything that is\nnot an 8–32 character hex UID after normalization answers 422.\n"
          },
          "from_tag_id": {
            "type": "integer",
            "minimum": 1,
            "description": "Source tag (control point or work-time tag, may be archived) whose chip UID is moved."
          },
          "overwrite": {
            "type": "boolean",
            "default": false,
            "description": "Also move a chip that a third tag or account still holds."
          }
        },
        "oneOf": [
          {
            "required": [
              "chip_id"
            ]
          },
          {
            "required": [
              "from_tag_id"
            ]
          }
        ]
      },
      "ControlPoint": {
        "type": "object",
        "description": "Scan point of a property (NFC chip, QR code or GPS). The QR payload\nprinted by the portal and read by the app is `{\"uuid\": \"<uuid>\"}`.\n`chip_id` is the bound NFC chip UID (hex, upper case, no separators)\nor null; `chip_connected` mirrors it. `task_uuids` lists the tasks linked to the point\n(oldest first = the primary task shown in the app), mirrored by\n`task_ids`. `archived` = soft-deleted (portal recycle bin).\n`sort_order` is the position of the point within its area as shown\nin the portal (0 = first); null = never sorted (listed after the\nsorted points, then by name). Changing `area_id` without `sort_order`\nresets it to null.\n",
        "properties": {
          "tag_id": {
            "type": "integer"
          },
          "uuid": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "tag_type": {
            "type": "string",
            "enum": [
              "CHECKPOINT",
              "TASK_POINT"
            ]
          },
          "property_id": {
            "type": "integer"
          },
          "archived": {
            "type": "boolean"
          },
          "notes_user": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes_intern": {
            "type": [
              "string",
              "null"
            ]
          },
          "area_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "area_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "sort_order": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 10000
          },
          "latitude": {
            "type": [
              "number",
              "null"
            ]
          },
          "longitude": {
            "type": [
              "number",
              "null"
            ]
          },
          "gps_radius_m": {
            "type": [
              "number",
              "null"
            ]
          },
          "chip_connected": {
            "type": "boolean"
          },
          "chip_missing": {
            "type": "boolean",
            "readOnly": true,
            "description": "\"Chip fehlt\" hint (since 27.10.2026): the last patrol booked the\npoint with a photo instead of a scan. Cleared when a chip is bound\nagain. `chip_id` stays set, so `chip_connected` may be true too.\n"
          },
          "web_link": {
            "type": "boolean",
            "description": "Point carries a web check-in link (clocking without app)."
          },
          "chip_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "Bound NFC chip UID (hex, upper case, no separators) or null."
          },
          "task_ids": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "task_uuids": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          },
          "plan_pin": {
            "type": [
              "object",
              "null"
            ],
            "readOnly": true,
            "description": "Location of the point on a floor plan of its property (since\n25.10.2026), or null. `x`/`y` are fractions 0–1 of the image width\nand height (origin top left), never pixels. Read-only in v1; the\npin is set in the portal (or by the AI connection via\ncreate_/update_control_point).\n",
            "properties": {
              "plan_id": {
                "type": "integer"
              },
              "plan_name": {
                "type": "string"
              },
              "x": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "y": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ControlPointArea": {
        "type": "object",
        "description": "Area of a property (floor, building section, zone) that groups its\ncontrol points — one level, per property, no rights of its own. A\npoint is assigned to an area through `area_id` on POST/PATCH\n`/v1/control-points`. `sort_order` is the position shown in the portal\n(0 = first); `control_points_count` counts the active (non-archived)\npoints of the area. Reordering and deleting stay in the portal.\n",
        "properties": {
          "area_id": {
            "type": "integer"
          },
          "property_id": {
            "type": "integer"
          },
          "name": {
            "type": "string",
            "maxLength": 100
          },
          "sort_order": {
            "type": "integer"
          },
          "control_points_count": {
            "type": "integer"
          }
        }
      },
      "RouteSchedule": {
        "type": "object",
        "description": "One schedule series of a patrol route (public write contract). Times\nare wall-clock values of the route's property timezone.\n",
        "properties": {
          "start_date": {
            "type": "string",
            "format": "date"
          },
          "start_time": {
            "type": "string",
            "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
          },
          "duration_seconds": {
            "type": "integer",
            "minimum": 60,
            "maximum": 86400
          },
          "frequency": {
            "type": "integer",
            "minimum": 1,
            "maximum": 99,
            "description": "Runs per time window."
          },
          "repeat_type": {
            "type": "string",
            "enum": [
              "daily",
              "weekly",
              "monthly",
              "none"
            ]
          },
          "repeat_frequency": {
            "type": "integer",
            "minimum": 1,
            "default": 1
          },
          "weekdays": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 0,
              "maximum": 6
            },
            "description": "Weekdays for weekly schedules, 0 = Sunday … 6 = Saturday (JavaScript getDay()). Responses use the same numbering."
          },
          "monthdays": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 31
            }
          },
          "type_freedays": {
            "type": "string",
            "enum": [
              "none",
              "enabled",
              "disable"
            ],
            "default": "none"
          },
          "last_run": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "End date of the series; omitted/null = open."
          },
          "anchor_mode": {
            "type": "string",
            "enum": [
              "fixed",
              "completion"
            ],
            "default": "fixed"
          }
        }
      },
      "TourStop": {
        "type": "object",
        "description": "One stop of a tour (read shape). `stop_mode` says what the app\nexpects at the stop: `tasks` = the point tasks of the property,\n`route` = the patrol route `route_id` of that property, `checkin` =\narrival only. `offset_min` is the planned arrival in minutes after\nthe tour start, `window_min` the tolerance window in minutes from\nthat offset; both null = no time target for the stop.\n",
        "properties": {
          "sort_order": {
            "type": "integer"
          },
          "property_id": {
            "type": "integer"
          },
          "property_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "stop_mode": {
            "type": "string",
            "enum": [
              "tasks",
              "route",
              "checkin"
            ]
          },
          "route_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "route_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "offset_min": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Planned arrival, minutes after the tour start."
          },
          "window_min": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Tolerance window in minutes from `offset_min`."
          },
          "note": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "TourSchedule": {
        "type": "object",
        "description": "One schedule series of a tour (read shape). Times are wall-clock\nvalues; `weekdays` use 0 = Sunday … 6 = Saturday like `RouteSchedule`.\n",
        "properties": {
          "name": {
            "type": "string"
          },
          "start_date": {
            "type": "string",
            "format": "date"
          },
          "last_run": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "End date of the series; null = open."
          },
          "start_time": {
            "type": "string",
            "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
          },
          "duration_seconds": {
            "type": "integer",
            "minimum": 60,
            "maximum": 604800
          },
          "frequency": {
            "type": "integer"
          },
          "repeat_type": {
            "type": "string",
            "enum": [
              "daily",
              "weekly",
              "monthly",
              "none"
            ]
          },
          "repeat_frequency": {
            "type": "integer"
          },
          "weekdays": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 0,
              "maximum": 6
            }
          },
          "monthdays": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 31
            }
          },
          "type_freedays": {
            "type": "string",
            "enum": [
              "none",
              "enabled",
              "disable"
            ]
          },
          "violation_rule_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        }
      },
      "TourListItem": {
        "type": "object",
        "description": "Row of GET /v1/tours. A tour is a cross-property round with stops\n(one property per stop); `property_ids` lists the stop properties\nin stop order without duplicates. `active: false` = archived\n(POST /v1/tours/{id}/archive): no future runs are generated, past\nruns stay in the log book. `esignature_mode` null = the tenant\ndefault applies.\n",
        "properties": {
          "uuid": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "order_mode": {
            "type": "string",
            "enum": [
              "enforced",
              "free"
            ],
            "description": "`enforced` = stops in the given order, `free` = any order."
          },
          "active": {
            "type": "boolean"
          },
          "esignature_mode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "required",
              "off",
              null
            ]
          },
          "stops_total": {
            "type": "integer"
          },
          "property_ids": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Tour": {
        "allOf": [
          {
            "$ref": "#/components/schemas/TourListItem"
          },
          {
            "type": "object",
            "description": "Tour detail — the list row plus the stops in order and every schedule series.",
            "properties": {
              "stops": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/TourStop"
                }
              },
              "schedules": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/TourSchedule"
                }
              }
            }
          }
        ]
      },
      "TourStopInput": {
        "type": "object",
        "description": "One stop on write. `stop_mode: route` needs `route_id` (a patrol\nroute of `property_id`); every other mode must leave `route_id`\nout or null. A `property_id` outside the key account's property\nrestriction answers 403.\n",
        "required": [
          "property_id",
          "sort_order"
        ],
        "additionalProperties": false,
        "properties": {
          "property_id": {
            "type": "integer"
          },
          "sort_order": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000
          },
          "stop_mode": {
            "type": "string",
            "enum": [
              "tasks",
              "route",
              "checkin"
            ],
            "default": "tasks"
          },
          "route_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "offset_min": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 10080,
            "description": "Planned arrival, minutes after the tour start."
          },
          "window_min": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "maximum": 10080,
            "description": "Tolerance window in minutes from `offset_min`."
          },
          "note": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 500
          }
        }
      },
      "TourScheduleInput": {
        "type": "object",
        "description": "One schedule series on write (same fields as `TourSchedule`).\n`name` omitted = the tour name. `weekdays` 0 = Sunday … 6 =\nSaturday; `duration_seconds` 60 … 604800 (7 days).\n",
        "required": [
          "start_date",
          "start_time",
          "duration_seconds",
          "repeat_type"
        ],
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 255
          },
          "start_date": {
            "type": "string",
            "format": "date"
          },
          "start_time": {
            "type": "string",
            "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
          },
          "duration_seconds": {
            "type": "integer",
            "minimum": 60,
            "maximum": 604800
          },
          "frequency": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "default": 1,
            "description": "Runs per time window."
          },
          "repeat_type": {
            "type": "string",
            "enum": [
              "daily",
              "weekly",
              "monthly",
              "none"
            ]
          },
          "repeat_frequency": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "default": 1
          },
          "weekdays": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 0,
              "maximum": 6
            }
          },
          "monthdays": {
            "type": "array",
            "items": {
              "type": "integer",
              "minimum": 1,
              "maximum": 31
            }
          },
          "type_freedays": {
            "type": "string",
            "enum": [
              "none",
              "enabled",
              "disable"
            ],
            "default": "none"
          },
          "last_run": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "End date of the series; omitted/null = open."
          },
          "violation_rule_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        }
      },
      "TourRun": {
        "type": "object",
        "description": "Row of GET /v1/patrols?kind=tour — one run of a tour. Shares the\ncolumns of the `planned`/`free` rows: `id` = the numeric run id,\n`route_name` = the tour name, `start_ts`/`end_ts` = the scheduled\nwindow, `done` = `status: done`. `property_id`, `property_name`,\n`route_id`, `attempts_finished` and `attempts_total` are null\n(a tour spans several properties). `uuid` is the key for\nGET /v1/patrols/tour/{uuid}; `stops_done` counts departed and\nskipped stops.\n",
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "tour"
            ]
          },
          "id": {
            "type": "integer"
          },
          "uuid": {
            "type": "string",
            "format": "uuid"
          },
          "property_id": {
            "type": "null"
          },
          "property_name": {
            "type": "null"
          },
          "route_id": {
            "type": "null"
          },
          "route_name": {
            "type": "string",
            "description": "The tour name."
          },
          "start_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "end_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "done": {
            "type": "boolean"
          },
          "attempts_finished": {
            "type": "null"
          },
          "attempts_total": {
            "type": "null"
          },
          "tour_uuid": {
            "type": "string",
            "format": "uuid"
          },
          "tour_name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "planned",
              "in_progress",
              "done",
              "aborted",
              "missed"
            ]
          },
          "stops_total": {
            "type": "integer"
          },
          "stops_done": {
            "type": "integer"
          }
        }
      },
      "TourRunStop": {
        "type": "object",
        "description": "Timeline entry of one stop in GET /v1/patrols/tour/{uuid}.\n`route_log_id` links the stop's patrol run (stop_mode `route`) to\nGET /v1/patrols/planned/{id}. `status: missed` = never reached\nbefore the run ended; `arrival_source` tells how the arrival was\nbooked (`scan`, `manual`, `gps` — with `gps` the coordinates are the\ndevice position).\n",
        "properties": {
          "sort_order": {
            "type": "integer"
          },
          "property_id": {
            "type": "integer"
          },
          "property_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "stop_mode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "tasks",
              "route",
              "checkin",
              null
            ]
          },
          "route_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "route_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "route_log_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "arrived",
              "departed",
              "skipped",
              "missed"
            ]
          },
          "arrived_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "departed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "arrival_source": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "scan",
              "manual",
              "gps",
              null
            ]
          },
          "skipped_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "comment": {
            "type": [
              "string",
              "null"
            ]
          },
          "acted_by_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "tasks_done": {
            "type": [
              "integer",
              "null"
            ]
          },
          "tasks_total": {
            "type": [
              "integer",
              "null"
            ]
          },
          "latitude": {
            "type": [
              "number",
              "null"
            ]
          },
          "longitude": {
            "type": [
              "number",
              "null"
            ]
          },
          "missed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "FormResponseSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "template_id": {
            "type": "string",
            "format": "uuid"
          },
          "property_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "submitted"
            ]
          },
          "has_defect": {
            "type": "boolean"
          },
          "submitted_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "MaterialItem": {
        "type": "object",
        "properties": {
          "item_id": {
            "type": "integer"
          },
          "uuid": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "size": {
            "type": [
              "string",
              "null"
            ]
          },
          "display_name": {
            "type": "string",
            "description": "name + size, e.g. \"Handschuhe (M)\""
          },
          "unit": {
            "type": "string"
          },
          "category": {
            "type": [
              "string",
              "null"
            ]
          },
          "kind": {
            "type": "string",
            "enum": [
              "consumable",
              "equipment",
              "serialized"
            ]
          },
          "unit_price_cents": {
            "type": [
              "integer",
              "null"
            ]
          },
          "barcodes": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 80
            },
            "description": "Manufacturer barcodes on the packaging (EAN-13, EAN-8, UPC-A,\nCode 128) in normal form: surrounding whitespace and control\ncharacters are removed, a 12-digit UPC-A is stored as EAN-13\nwith a leading 0. An item carries up to 20 barcodes; within a\ncompany a barcode belongs to one item only.\n"
          },
          "archived": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "MaterialStockRow": {
        "type": "object",
        "description": "Computed stock per item: latest count anchor plus all movements after\nit. `status` mirrors the portal traffic light (`count_needed` =\nnegative stock, i.e. a count is overdue).\n",
        "properties": {
          "item_id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "unit": {
            "type": "string"
          },
          "category": {
            "type": [
              "string",
              "null"
            ]
          },
          "stock": {
            "type": "number"
          },
          "min_qty": {
            "type": [
              "number",
              "null"
            ]
          },
          "target_qty": {
            "type": [
              "number",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "low",
              "empty",
              "count_needed"
            ]
          },
          "last_count_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_movement_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "MaterialMovement": {
        "type": "object",
        "properties": {
          "uuid": {
            "type": "string",
            "format": "uuid"
          },
          "item_id": {
            "type": "integer"
          },
          "property_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "holder_type": {
            "type": "string",
            "enum": [
              "property",
              "account",
              "stock"
            ]
          },
          "qty": {
            "type": "number",
            "description": "positive = inflow, negative = outflow"
          },
          "reason": {
            "type": "string",
            "enum": [
              "refill",
              "consume",
              "delivery",
              "correction",
              "issue",
              "return",
              "loss"
            ]
          },
          "unit_price_cents": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Price stamped from the item master AT BOOKING TIME — never rewritten."
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "note": {
            "type": [
              "string",
              "null"
            ]
          },
          "ref_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "ref_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ShiftSeriesCreated": {
        "type": "object",
        "properties": {
          "series_id": {
            "type": "integer",
            "description": "The series: `series_id` of its shifts in GET /v1/shifts."
          },
          "property_id": {
            "type": "integer"
          },
          "shifts_created": {
            "type": "integer",
            "description": "Shifts that exist for the series after the call."
          },
          "generated_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Last day shifts were created for (at most 90 days ahead); null when the series starts later or the key was replayed."
          },
          "created": {
            "type": "boolean",
            "description": "false = the idempotency key was used before; nothing new was written."
          }
        }
      },
      "ShiftSeriesPeopleChange": {
        "type": "object",
        "properties": {
          "series_id": {
            "type": "integer",
            "description": "The series itself."
          },
          "property_id": {
            "type": "integer"
          },
          "mode": {
            "type": "string",
            "enum": [
              "period",
              "from"
            ],
            "description": "period = from + to only; from = from that day on, for good."
          },
          "from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "from: the day the new people start (first day of the rhythm on or after the requested day)."
          },
          "to": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "people_now": {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "description": "People of the series itself before the call."
          },
          "people_after": {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "description": "People of the series itself after the call (period: unchanged)."
          },
          "shifts_changed": {
            "type": "integer",
            "description": "Shifts whose people changed."
          },
          "shifts_unchanged": {
            "type": "integer",
            "description": "Shifts that already had these people."
          },
          "shifts_skipped_with_checkins": {
            "type": "integer",
            "description": "period: shifts left as they are because time was already recorded."
          },
          "last_shift_day": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Last day the series has a shift for; later days keep the people of the series."
          },
          "next_version": {
            "type": [
              "object",
              "null"
            ],
            "description": "A later version of the series (settings changed from a date on), not changed by this call.",
            "properties": {
              "series_id": {
                "type": "integer"
              },
              "first_day": {
                "type": "string",
                "format": "date"
              }
            }
          },
          "days_changed_separately": {
            "type": "integer",
            "description": "from: days changed separately on or after `from`; they keep their own people."
          },
          "new_series_id": {
            "type": [
              "integer",
              "null"
            ],
            "description": "from: the series that goes on with the new people (the old one ends the day before `from`); null when the series itself was changed (no shift before `from`) or for a period."
          }
        }
      },
      "Shift": {
        "type": "object",
        "description": "Planned shift instance of the Dienstplan. `series_id` references the\nrecurring series (config) the instance belongs to — usable as input\nfor POST /v1/shifts/generate and POST /v1/shift-series/{id}/people\n(a day changed separately carries the id of its one-day config; both\nroutes lead it to its series). `assignees` is the PLANNED staffing\n(SOLL); actual attendance lives under /v1/shifts/{id}/attendance.\nNote: `status` stays `scheduled` after the shift has ended — derive\nthe phase (planned/active/completed) from the timestamps; only\ncancellation changes the status.\n",
        "properties": {
          "uuid": {
            "type": "string",
            "format": "uuid"
          },
          "series_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "property_id": {
            "type": "integer"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "scheduled",
              "cancelled",
              "completed"
            ]
          },
          "start_ts": {
            "type": "string",
            "format": "date-time"
          },
          "end_ts": {
            "type": "string",
            "format": "date-time"
          },
          "checkin_start_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "checkin_end_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "checkout_start_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "checkout_end_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "checkins_count": {
            "type": "integer"
          },
          "checkouts_count": {
            "type": "integer"
          },
          "checkin_requirement_mode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "optional",
              "minimum",
              "fixed",
              null
            ]
          },
          "checkout_requirement_mode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "optional",
              "minimum",
              "fixed",
              null
            ]
          },
          "required_checkins": {
            "type": [
              "integer",
              "null"
            ]
          },
          "required_checkouts": {
            "type": [
              "integer",
              "null"
            ]
          },
          "required_headcount": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Explicit staffing target (Soll-Besetzung). null = derived from the linked work order or required_checkins (default 1)."
          },
          "required_qualifications": {
            "type": [
              "array",
              "null"
            ],
            "description": "Qualification demand (Qualifikationsbedarf): how many of the\nrequired_headcount people need which qualification. A subset of\nthe headcount (Σ count ≤ required_headcount); each\nqualification_id once (see GET /v1/qualifications). null = none.\n",
            "items": {
              "type": "object",
              "properties": {
                "qualification_id": {
                  "type": "integer"
                },
                "count": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 999
                }
              }
            }
          },
          "effective_required_headcount": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Effective staffing target as the planner computes it (explicit target, else work order demand, else required_checkins, else 1). Set in list responses; null on the single-shift read."
          },
          "assignees": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "account_id": {
                  "type": "integer"
                },
                "name": {
                  "type": "string"
                }
              }
            }
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the shift was created. A work-time entry is only linked\nwhile the shift exists: a shift created after the fact does not\npick up entries that ended more than an hour earlier (see\nGET /v1/time-entries/link-rules). Compare with `start_ts` of the\nentry to tell \"planned too late\" from a linking error.\n"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Last change recorded on the shift. A hint, not an audit trail — internal counters do not always move it."
          }
        }
      },
      "ShiftAttendanceRow": {
        "type": "object",
        "description": "Actual check-in/out of one employee on a shift.",
        "properties": {
          "account_id": {
            "type": "integer"
          },
          "account_name": {
            "type": "string"
          },
          "checkin_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "checkout_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "checkin_timing": {
            "type": [
              "string",
              "null"
            ],
            "description": "e.g. on_time / early / late"
          },
          "checkout_timing": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ShiftAttendancePerson": {
        "type": "object",
        "description": "One person on a shift, planned and actual merged (SOLL/IST). A person\ncan hold several entries on one shift: the first check-in and the\nstate of the latest entry decide. A Fehlstempel (`invalid_reason:\nshort_entry`, under 60 seconds) is listed under `time_entries` but is\nno attendance — it changes neither `status` nor the times.\n",
        "properties": {
          "account_id": {
            "type": "integer"
          },
          "account_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "planned": {
            "type": "boolean",
            "description": "false = clocked in on the shift without being planned for it."
          },
          "status": {
            "type": "string",
            "enum": [
              "present",
              "checked_out",
              "missing"
            ],
            "description": "missing = planned, but no valid entry on the shift."
          },
          "checkin_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "checkout_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "checkin_timing": {
            "type": [
              "string",
              "null"
            ],
            "description": "early / on_time / late. `null` = no verdict stored — e.g. the entry\nwas linked to the shift only at clock-out. Not a proof of\npunctuality; compare `checkin_ts` with the shift start instead.\n"
          },
          "checkout_timing": {
            "type": [
              "string",
              "null"
            ]
          },
          "checkin_deviation_ms": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Check-in minus shift start in milliseconds, negative = early. `null` = no verdict stored."
          },
          "checkout_deviation_ms": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Check-out minus shift end in milliseconds, negative = early."
          },
          "time_entries": {
            "type": "array",
            "description": "Every work-time entry of the person on this shift (see GET /v1/time-entries/{id}).",
            "items": {
              "type": "object",
              "properties": {
                "uuid": {
                  "type": "string",
                  "format": "uuid"
                },
                "start_ts": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "end_ts": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "invalid_reason": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "enum": [
                    "short_entry",
                    null
                  ]
                }
              }
            }
          }
        }
      },
      "ShiftAttendance": {
        "type": "object",
        "description": "A shift with its SOLL/IST — the planned people and everyone who clocked in on it.",
        "properties": {
          "shift": {
            "$ref": "#/components/schemas/Shift"
          },
          "people": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ShiftAttendancePerson"
            }
          }
        }
      },
      "LinkEvent": {
        "type": "object",
        "description": "One rejected or failed attempt to link a work-time entry to a planned\nshift (Zuordnungs-Protokoll). The log holds anomalies only: an entry\nwithout any shift of its property nearby, or of a person who is not\nassigned to the property, writes NO row — \"no row\" does not mean\n\"linked\".\n",
        "properties": {
          "id": {
            "type": "integer"
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "event": {
            "type": "string",
            "enum": [
              "threshold_rejected",
              "no_candidate_nearby",
              "live_link_failed",
              "linked_to_cancelled"
            ],
            "description": "`threshold_rejected` = clocked in more than 6 hours before the\nshift start. `no_candidate_nearby` = a shift of the property was\nnear, but none fitted (window or 4-hour distance).\n`live_link_failed` = the link failed at clock-in or clock-out, or\nwhen a shift was named by hand (`details.mode`: live / manual), see\n`reason_code`. `linked_to_cancelled` = the entry was put on a\ncancelled shift (offline upload).\n"
          },
          "reason_code": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "outside_window",
              "wrong_property",
              "unsupported_state",
              "manual_missing_id",
              null
            ],
            "description": "Only for `live_link_failed`."
          },
          "property_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "account_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "account_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "shift_uuid": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "The shift the row is about — for a reject the nearest shift that was refused. `null` = no shift context."
          },
          "time_entry_uuid": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "The affected work-time entry. `null` = none found."
          },
          "time_entry_derived": {
            "type": "boolean",
            "description": "true = the event was stored without the entry (`live_link_failed`,\n`linked_to_cancelled`) and the entry was found by person, property\nand stamp time instead.\n"
          },
          "time_entry_shift_uuid": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "The shift the entry hangs on TODAY. A row tells what was rejected\nat one moment; many entries are linked a little later, to this\nshift or to the neighbouring one. `null` = still without a shift,\nor no entry found. Filter with `linked`.\n"
          },
          "details": {
            "type": [
              "object",
              "null"
            ],
            "description": "Diagnostics, positive list: `mode` (live / manual), `state` (LOGIN /\nLOGOUT), `timestamp` (the stamp), `deviation_ms` and `threshold`\n(threshold_rejected), `candidate_count`, `window_candidate_count`,\n`linkable_count`. A `live_link_failed` with `state: LOGOUT` is often\nharmless — the entry usually already hangs on its shift;\n`time_entry_shift_uuid` says so.\n"
          }
        }
      },
      "EditEvent": {
        "type": "object",
        "description": "One change to a recorded work-time entry (Änderungsverlauf): who\nchanged, deleted, booked after the fact or confirmed it, with old and\nnew values and the reason. Append-only; a row survives the deletion of\nits entry. Coordinates, device ids and internal ids never leave the\nAPI.\n",
        "properties": {
          "id": {
            "type": "integer"
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "event": {
            "type": "string",
            "enum": [
              "edited",
              "deleted",
              "bulk_deleted",
              "sublogs_cleared",
              "overlap_override",
              "confirmed",
              "unconfirmed",
              "confirm_dropped",
              "created"
            ],
            "description": "`edited` = times, pause, person, property or shift link changed\n(`changes`). `deleted` = the entry was deleted. `bulk_deleted` =\nsummary row of a mass deletion (names no entry). `sublogs_cleared`\n= stamps of the entry were dropped (since 23.09.2026 only pause\nstamps). `overlap_override` = the overlap check was bypassed on\npurpose. `confirmed` / `unconfirmed` / `confirm_dropped` = release\nof the entry given, withdrawn with a reason, or lapsed through a\nlater change. `created` = a closed entry was booked after the fact\n(portal or API), never a live clock-in.\n"
          },
          "time_entry_uuid": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "The entry the row is about. `null` = the row names none (mass deletion summary)."
          },
          "time_entry_deleted": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "true = the entry is deleted or gone, false = it exists. `null` = the row names no entry."
          },
          "property_id": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Property of the entry. `null` when the entry is gone."
          },
          "account_id": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Person of the entry (not who made the change). `null` when the entry is gone."
          },
          "account_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "actor_account_id": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Who made the change. `null` = the system."
          },
          "actor_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "description": "The reason given with the change, if any."
          },
          "changes": {
            "type": [
              "object",
              "null"
            ],
            "description": "Field diff `{ field: { old, new } }`, positive list: `start_ts`,\n`end_ts`, `pause_ms`, `account_id`, `property_id`, `start_method`,\n`end_method`, `login_ts`, `logout_ts`, `confirmed_at`,\n`confirmed_by_account_id` and `shift_uuid` (the link to the planned\nshift: `old` → `new`, `null` = no shift). `null` = the event\ncarries no diff.\n",
            "additionalProperties": {
              "type": "object",
              "properties": {
                "old": {
                  "type": [
                    "string",
                    "number",
                    "null"
                  ]
                },
                "new": {
                  "type": [
                    "string",
                    "number",
                    "null"
                  ]
                }
              }
            }
          },
          "details": {
            "type": [
              "object",
              "null"
            ],
            "description": "Positive list: `source` (manual / api), `end_mode`, `scope` and\n`count` (sublogs_cleared), `cause` (confirm_dropped), `requested`\nand `deleted` (bulk_deleted).\n"
          }
        }
      },
      "WorkDay": {
        "type": "object",
        "description": "One calendar day of one person: target (contract), plan (shifts) and\nactual (recorded time). The rows are the UNION of days with a contract\ntarget, an approved absence, a planned shift or a recorded entry.\nDay rule: contract and absence count by calendar day; a planned shift\ncounts fully on its START day in the timezone of the property (night\nshifts too); an entry counts on its start day in the timezone of the\naccount.\n",
        "properties": {
          "account_id": {
            "type": "integer"
          },
          "account_name": {
            "type": "string"
          },
          "day": {
            "type": "string",
            "format": "date"
          },
          "contract_ms": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Contract target of the day in milliseconds; 0 on a day with an approved absence. `null` = no work-schedule model."
          },
          "absence_type": {
            "type": [
              "string",
              "null"
            ],
            "description": "Type of the approved absence covering the day, else `null`."
          },
          "absence_paid": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether the absence counts as paid. `null` without an absence."
          },
          "planned_ms": {
            "type": "integer",
            "description": "Sum of the planned shift time (assigned, not cancelled)."
          },
          "planned_shifts": {
            "type": "integer"
          },
          "actual_ms": {
            "type": "integer",
            "description": "Recorded work time; a running entry counts up to now."
          },
          "pause_ms": {
            "type": "integer"
          },
          "entries": {
            "type": "integer"
          },
          "first_start_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_end_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "running": {
            "type": "boolean",
            "description": "At least one entry of the day is still open."
          },
          "diff_plan_ms": {
            "type": "integer",
            "description": "Actual minus plan."
          },
          "diff_contract_ms": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Actual minus contract target. `null` without a model."
          },
          "paid_ms": {
            "type": "integer",
            "description": "Paid time — the actual, plus the day target on a day with a PAID absence and no entry."
          }
        }
      },
      "LinkRules": {
        "type": "object",
        "description": "The rules by which a work-time entry is linked to a planned shift, as\ndata. The same constants the server links with.\n",
        "properties": {
          "same_property": {
            "type": "boolean",
            "description": "An entry is only ever linked to a shift of the same property."
          },
          "person_needs_property_access": {
            "type": "boolean",
            "description": "The person must be assigned to the property, otherwise no shift is a candidate."
          },
          "cancelled_shifts_excluded": {
            "type": "boolean",
            "description": "Cancelled shifts are never a candidate."
          },
          "max_link_distance_ms": {
            "type": "integer",
            "description": "Largest distance between clock-in and shift start, in either direction (4 hours). Exception on the late side, see late_link_min_remaining_ms."
          },
          "late_link_min_remaining_ms": {
            "type": "integer",
            "description": "A clock-in later than max_link_distance_ms after the shift start\nis still linked while at least this much of the planned shift\nlies ahead (2 hours). Shifts of up to six hours are unaffected.\n"
          },
          "max_pre_shift_deviation_ms": {
            "type": "integer",
            "description": "Largest lead of a clock-in before the shift start (6 hours; also capped by the shift length)."
          },
          "recheck_interval_minutes": {
            "type": "integer",
            "description": "Unlinked entries are evaluated again this often."
          },
          "recheck_max_entry_age_ms": {
            "type": "integer",
            "description": "…but only entries that started within this time (24 hours)…"
          },
          "recheck_ended_within_ms": {
            "type": "integer",
            "description": "…and are still open or ended at most this long ago (1 hour). An\nentry outside both windows is never linked afterwards: a shift\ncreated later does not pick it up.\n"
          }
        }
      },
      "TimeEntry": {
        "type": "object",
        "description": "Work-time entry. `end_ts: null` = still running. Durations\n(pause/work/total, milliseconds) are ALWAYS server-computed — the\nproperty's minimum-pause rules are enforced on every write.\n",
        "properties": {
          "uuid": {
            "type": "string",
            "format": "uuid"
          },
          "account_id": {
            "type": "integer"
          },
          "account_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "account_custom_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "personnel number"
          },
          "property_id": {
            "type": "integer"
          },
          "start_ts": {
            "type": "string",
            "format": "date-time"
          },
          "end_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "pause_ms": {
            "type": "integer"
          },
          "work_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "total_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "shift_uuid": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "linked planned shift"
          },
          "invalid_reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "short_entry",
              null
            ],
            "description": "Fehlstempel marker. `short_entry` = closed after less than 60 seconds\n(accidental double scan). The entry stays listed but is excluded from\nevery sum, proof and export. `null` = valid entry.\n"
          },
          "start_method": {
            "type": [
              "string",
              "null"
            ],
            "description": "How the entry was started: button_click, qr_code_static, nfc_tag,\nnfc_scanner_device, geofence_auto, chatbot or manual. `null` = not\nrecorded.\n"
          },
          "end_method": {
            "type": [
              "string",
              "null"
            ],
            "description": "How the entry was ended (same values). `null` = still running or not recorded."
          },
          "source": {
            "type": [
              "string",
              "null"
            ],
            "description": "Origin of the entry: device (app), web (web check-in), manual\n(booked by hand in the portal or via this API), api, autoclose,\nsystem, resync, coverage, public_qr.\n"
          },
          "start_location_status": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "ONSITE",
              "OFFSITE",
              null
            ],
            "description": "Result of the location check at clock-in. Coordinates are never returned."
          },
          "end_location_status": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "ONSITE",
              "OFFSITE",
              null
            ],
            "description": "Result of the location check at clock-out."
          },
          "clock_corrected": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "true = the times were corrected because the device clock was off."
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "TimeEntryDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/TimeEntry"
          },
          {
            "type": "object",
            "properties": {
              "timeline": {
                "type": "array",
                "description": "Read-only event timeline incl. pauses (PAUSE_START/PAUSE_END).",
                "items": {
                  "type": "object",
                  "properties": {
                    "state": {
                      "type": "string",
                      "description": "LOGIN / LOGOUT / PAUSE_START / PAUSE_END / …"
                    },
                    "timestamp": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "reason": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "timing_status": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "deviation_ms": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "ReportTypeInfo": {
        "type": "object",
        "description": "A report type the key's account may request.",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "time_entries",
              "attendance",
              "patrol_coverage",
              "incidents",
              "tasks",
              "form_responses",
              "workdays",
              "service_level_summary"
            ]
          },
          "formats": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "pdf",
                "csv",
                "xlsx"
              ]
            }
          },
          "default_format": {
            "type": "string",
            "enum": [
              "pdf",
              "csv",
              "xlsx"
            ]
          },
          "max_days": {
            "type": "integer",
            "description": "Longest period in calendar days, both ends included."
          },
          "range": {
            "type": "string",
            "enum": [
              "days",
              "period"
            ],
            "description": "`days`: the report covers `from`…`to`. `period`: it covers the billing period that contains `to` (service_level_summary)."
          },
          "property_id": {
            "type": "string",
            "enum": [
              "required",
              "optional",
              "not_supported"
            ],
            "description": "`required` for accounts restricted to certain properties."
          },
          "account_id": {
            "type": "string",
            "enum": [
              "any",
              "own_only",
              "not_supported"
            ],
            "description": "`any` only with the right to see other people's times."
          }
        }
      },
      "ExportRun": {
        "type": "object",
        "properties": {
          "run_id": {
            "type": "string",
            "format": "uuid"
          },
          "type": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "time_entries",
              "attendance",
              "patrol_coverage",
              "incidents",
              "tasks",
              "form_responses",
              "workdays",
              "service_level_summary",
              null
            ]
          },
          "format": {
            "type": "string",
            "enum": [
              "pdf",
              "csv",
              "xlsx"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "ready",
              "failed",
              "cancelled"
            ]
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "finished_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "row_count": {
            "type": [
              "integer",
              "null"
            ]
          },
          "file_size_bytes": {
            "type": [
              "integer",
              "null"
            ]
          },
          "error_code": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "TOO_LARGE",
              "FAILED",
              null
            ],
            "description": "Only when `failed`. `TOO_LARGE` — shorten the period."
          },
          "download_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Only when `ready`. Public link (no login) to the file. Valid until\n`download_url_expires_at` (60 minutes). With less than 5 minutes\nleft, the next GET issues a new link and the old one stops\nworking. An expired link answers 410.\n"
          },
          "file_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Only when `ready`. The same file as a direct download from the API\nhost (`https://api.litelog.de/api/d/<token>`) — for programs and\ncurl. `download_url` points at the portal, which only redirects in\na browser. Expires together with `download_url`.\n"
          },
          "download_url_expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "ReportExportError": {
        "type": "object",
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "REPORT_TYPE_UNKNOWN",
              "REPORT_FORMAT_UNSUPPORTED",
              "REPORT_RANGE_TOO_LONG",
              "PROPERTY_REQUIRED",
              "NOT_PERMITTED",
              "EXPORT_LIMIT_REACHED",
              "IDEMPOTENCY_KEY_REUSED",
              "NOT_FOUND",
              "INVALID_INPUT",
              "EXPORT_UNAVAILABLE"
            ]
          },
          "message": {
            "type": "string",
            "description": "Fixed English text."
          },
          "details": {
            "type": "object",
            "description": "Code-chosen values only: `known_types`, `supported_formats`,\n`max_days`, `field`, `reason` (NOT_PERMITTED: subcontractor,\npermission, feature_disabled, package, property, person,\nrestricted_account), `limit` + `max` (EXPORT_LIMIT_REACHED:\nstarts_per_key, parallel_per_account, parallel_per_company,\nper_company_per_day).\n",
            "additionalProperties": true
          }
        }
      },
      "WebhookEventType": {
        "type": "string",
        "enum": [
          "form_response.submitted",
          "incident.created",
          "task.completed",
          "task.completion.cancelled",
          "task.completion.reassigned",
          "patrol.completed",
          "patrol.missed",
          "time_entry.started",
          "time_entry.stopped"
        ]
      },
      "WebhookSubscription": {
        "type": "object",
        "description": "An outgoing webhook. The secret is never part of it.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "maxLength": 120
          },
          "url": {
            "type": "string",
            "description": "https only, port 443, no IP address, no credentials."
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WebhookEventType"
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "paused",
              "disabled"
            ]
          },
          "disabled_reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "too_many_failures",
              "endpoint_gone",
              null
            ],
            "description": "Set when LiteLog switched the webhook off."
          },
          "secret_prefix": {
            "type": "string",
            "description": "First 12 characters of the secret, to recognise it."
          },
          "previous_secret_expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "After a renewal with a grace period: until when deliveries also carry\n`X-LiteLog-Signature-Previous`, signed with the previous secret. null\nwhen there is no grace period running.\n"
          },
          "consecutive_failures": {
            "type": "integer"
          },
          "last_success_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_failure_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookSubscriptionWithSecret": {
        "description": "Answer to creating a webhook and to `rotate_secret` — the only time the secret is readable.",
        "allOf": [
          {
            "$ref": "#/components/schemas/WebhookSubscription"
          },
          {
            "type": "object",
            "properties": {
              "secret": {
                "type": "string",
                "description": "`whsec_…` — store it now, it is not shown again."
              }
            }
          }
        ]
      },
      "WebhookDeliveryLogEntry": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "event_id": {
            "type": "string",
            "format": "uuid"
          },
          "event_type": {
            "$ref": "#/components/schemas/WebhookEventType"
          },
          "is_test": {
            "type": "boolean"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "running",
              "delivered",
              "failed",
              "dead",
              "skipped"
            ]
          },
          "attempts": {
            "type": "integer"
          },
          "last_status_code": {
            "type": [
              "integer",
              "null"
            ]
          },
          "last_error": {
            "type": [
              "string",
              "null"
            ],
            "description": "Short code, never text of the receiver: `http_status`, `redirect`, `gone`,\n`timeout`, `network`, `dns_failed`, `forbidden_address`; for `skipped`\nthe reason (`no_property_access`, `time_events_not_permitted`,\n`outside_person_scope`, `account_inactive`, `not_entitled`,\n`subscription_paused`, `subscription_disabled`, …).\n"
          },
          "duration_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "next_attempt_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "delivered_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookTestResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "status_code": {
            "type": [
              "integer",
              "null"
            ]
          },
          "duration_ms": {
            "type": "integer"
          },
          "error_code": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "WebhookEnvelope": {
        "type": "object",
        "description": "Body of every webhook request. Signed byte for byte as sent.",
        "required": [
          "id",
          "type",
          "api_version",
          "created_at",
          "occurred_at",
          "data",
          "links"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Event id — the same on every retry; use it to ignore duplicates."
          },
          "type": {
            "$ref": "#/components/schemas/WebhookEventType"
          },
          "api_version": {
            "type": "string",
            "enum": [
              "v1"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "When LiteLog recorded the event."
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time",
            "description": "When it happened."
          },
          "data": {
            "type": "object",
            "description": "IDs, time and property only — no names, no free text, no coordinates.\nPer type:\n- `form_response.submitted`: `form_response_id` (uuid), `form_template_id` (uuid), `property_id`, `account_id`, `has_defect`\n- `incident.created`: `incident_id`, `property_id`, `control_point_id`\n- `task.completed`: `task_id` (uuid), `task_completion_id` (uuid or null for a completion on the task board), `property_id`, `occurrence_date`\n- `task.completion.cancelled`: `task_id` (uuid), `task_completion_id` (uuid), `property_id`, `occurrence_date`, `cancelled_at`, `system` (true = cancelled by the system after a rejected mandatory signature), `reason_code` (`signature_rejected`, `correction`, `other`, …; never the free text). A `task.completed` of a cancelled completion is not delivered (skipped: `completion_cancelled`).\n- `task.completion.reassigned`: `task_id` (uuid), `task_completion_id` (uuid), `property_id`, `occurrence_date` (after the correction), `previous_occurrence_date`, `reassigned_at`, `reason_code` (never the free text). The completion itself did not change; `task.completed` is not sent again.\n- `patrol.completed` / `patrol.missed`: `patrol_id`, `route_id`, `property_id`\n- `time_entry.started` / `time_entry.stopped`: `time_entry_id` (uuid), `account_id`, `property_id`\n"
          },
          "links": {
            "type": "object",
            "properties": {
              "self": {
                "type": "string",
                "description": "Where to read the record with an API key, e.g. /api/v1/incidents/{id}."
              }
            }
          }
        }
      },
      "Qualification": {
        "type": "object",
        "description": "Entry of the tenant's qualification catalog.",
        "properties": {
          "qualification_id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "account_count": {
            "type": "integer",
            "description": "Employees holding this qualification."
          },
          "staffing_count": {
            "type": "integer",
            "description": "Work-order staffing demand rows that reference it. Only in the catalog list (GET /v1/qualifications)."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AccountQualification": {
        "type": "object",
        "description": "One qualification assigned to an employee account.",
        "properties": {
          "qualification_id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "valid_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date",
            "description": "Last valid day (inclusive); null = no expiry. An expired qualification does not count when shifts are staffed."
          }
        }
      },
      "AccountProperties": {
        "type": "object",
        "description": "`GET` / `PUT /v1/accounts/{id}/properties`: which properties an\nemployee may access.\n",
        "properties": {
          "account_id": {
            "type": "integer"
          },
          "all_properties": {
            "type": "boolean",
            "description": "true = every property of the tenant; `property_ids` is then empty."
          },
          "property_ids": {
            "type": "array",
            "items": {
              "type": "integer"
            },
            "description": "Assigned, non-archived properties in ascending order."
          }
        }
      },
      "AccountDetail": {
        "type": "object",
        "description": "`GET /v1/accounts/{id}`: the list fields plus ownership, qualifications\nand custom-field values. `custom_fields` is keyed by the field `key`\n(not the label) and only contains fields that have a value.\n",
        "properties": {
          "account_id": {
            "type": "integer"
          },
          "uuid": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "username": {
            "type": "string"
          },
          "custom_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "Personnel number."
          },
          "role_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "role_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "language": {
            "type": [
              "string",
              "null"
            ]
          },
          "archived": {
            "type": "boolean"
          },
          "owner_account_id": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Root account of the subcontractor this person belongs to; null = own staff."
          },
          "qualifications": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AccountQualification"
            }
          },
          "custom_fields": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Values of the active custom fields by `key`."
          }
        }
      },
      "CustomFieldDefinition": {
        "type": "object",
        "description": "A tenant-defined field of the employee record (Portal → Settings).",
        "properties": {
          "key": {
            "type": "string",
            "description": "Stable identifier used in `custom_fields`."
          },
          "label_de": {
            "type": "string"
          },
          "label_en": {
            "type": [
              "string",
              "null"
            ]
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "textarea",
              "number",
              "date",
              "select",
              "boolean"
            ]
          },
          "options": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            },
            "description": "Allowed values for `select`, else null."
          },
          "required": {
            "type": "boolean"
          },
          "sort_order": {
            "type": "integer"
          }
        }
      },
      "CustomFieldValues": {
        "type": "object",
        "description": "Custom-field values by `key`. `null` clears a value. Numbers and\nbooleans are accepted for fields of that type and stored as text.\nUnknown keys and an empty required field answer 422.\n",
        "additionalProperties": {
          "type": [
            "string",
            "number",
            "boolean",
            "null"
          ]
        }
      },
      "NavLayoutItem": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "A key from `catalog.keys` (e.g. `dashboard.view`, `attendance.live`, `proof.tasks_list`)."
          },
          "label": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1,
            "maxLength": 40,
            "description": "Own name; null/missing = default name in the portal language."
          },
          "icon": {
            "type": [
              "string",
              "null"
            ],
            "description": "A name from `catalog.icons`; null/missing = default icon."
          },
          "accent": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "attendance",
              "time",
              "tasks",
              "reports",
              "control",
              "neutral",
              null
            ],
            "description": "Own color; null/missing = default color."
          }
        }
      },
      "NavLayoutPanel": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sections"
        ],
        "description": "Sections of one panel, top to bottom. At most 12 sections and 60 entries in all per panel; section ids unique per panel.",
        "properties": {
          "sections": {
            "type": "array",
            "maxItems": 12,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "id",
                "label",
                "items"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^[a-z0-9][a-z0-9-]{0,35}$",
                  "description": "Section id; default sections use `catalog.default_section_ids` (then `label: null` = translated default heading)."
                },
                "label": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "minLength": 1,
                  "maxLength": 40
                },
                "items": {
                  "type": "array",
                  "maxItems": 60,
                  "items": {
                    "$ref": "#/components/schemas/NavLayoutItem"
                  }
                }
              }
            }
          }
        }
      },
      "NavLayout": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "version",
          "dashboard"
        ],
        "description": "Company default of the portal main menu. Stores catalogue keys only —\nrights and modules still decide what each person sees; a layout can\nreorder, rename, recolor and hide, never reveal. A panel missing from\n`panels` keeps the LiteLog default (`catalog.default_layout`).\n",
        "properties": {
          "version": {
            "type": "integer",
            "enum": [
              1
            ]
          },
          "rail": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "order",
              "hidden"
            ],
            "description": "Main items on the far left.",
            "properties": {
              "order": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "dashboard",
                    "personal",
                    "tasks",
                    "reports",
                    "empfango",
                    "documents",
                    "material",
                    "stammdaten",
                    "roster",
                    "attendance"
                  ]
                },
                "description": "Order; items not listed follow in default order."
              },
              "hidden": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "dashboard",
                    "personal",
                    "tasks",
                    "reports",
                    "empfango",
                    "documents",
                    "material",
                    "stammdaten",
                    "roster",
                    "attendance"
                  ]
                },
                "description": "Hidden items; `dashboard` (catalog.protected_rail_ids) can never be hidden (422)."
              },
              "more": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "dashboard",
                    "personal",
                    "tasks",
                    "reports",
                    "empfango",
                    "documents",
                    "material",
                    "stammdaten",
                    "roster",
                    "attendance"
                  ]
                },
                "description": "Items under \"More\" at the end of the rail; `dashboard` always stays in the rail (422). `roster` and `attendance` appear only when listed in `order` or `more`."
              },
              "items": {
                "type": "object",
                "additionalProperties": false,
                "description": "Own name, icon or color per rail item (keys = rail ids).",
                "properties": {
                  "dashboard": {
                    "$ref": "#/components/schemas/NavRailItemOverride"
                  },
                  "personal": {
                    "$ref": "#/components/schemas/NavRailItemOverride"
                  },
                  "tasks": {
                    "$ref": "#/components/schemas/NavRailItemOverride"
                  },
                  "reports": {
                    "$ref": "#/components/schemas/NavRailItemOverride"
                  },
                  "empfango": {
                    "$ref": "#/components/schemas/NavRailItemOverride"
                  },
                  "documents": {
                    "$ref": "#/components/schemas/NavRailItemOverride"
                  },
                  "material": {
                    "$ref": "#/components/schemas/NavRailItemOverride"
                  },
                  "stammdaten": {
                    "$ref": "#/components/schemas/NavRailItemOverride"
                  },
                  "roster": {
                    "$ref": "#/components/schemas/NavRailItemOverride"
                  },
                  "attendance": {
                    "$ref": "#/components/schemas/NavRailItemOverride"
                  }
                }
              }
            }
          },
          "dashboard": {
            "$ref": "#/components/schemas/NavLayoutPanel"
          },
          "panels": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "personal": {
                "$ref": "#/components/schemas/NavLayoutPanel"
              },
              "calendar": {
                "$ref": "#/components/schemas/NavLayoutPanel"
              },
              "empfango": {
                "$ref": "#/components/schemas/NavLayoutPanel"
              },
              "documents": {
                "$ref": "#/components/schemas/NavLayoutPanel"
              },
              "stammdaten": {
                "$ref": "#/components/schemas/NavLayoutPanel"
              },
              "roster": {
                "$ref": "#/components/schemas/NavLayoutPanel"
              },
              "attendance": {
                "$ref": "#/components/schemas/NavLayoutPanel"
              }
            }
          },
          "company_updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Set by the server on every saving change; ignored on input."
          }
        }
      },
      "NavRailItemOverride": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "label": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1,
            "maxLength": 40
          },
          "icon": {
            "type": [
              "string",
              "null"
            ],
            "description": "A name from `catalog.icons`."
          },
          "accent": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "attendance",
              "time",
              "tasks",
              "reports",
              "control",
              "neutral",
              null
            ]
          },
          "term": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "patrols",
              "defects",
              "shift_plan",
              null
            ],
            "description": "Industry name of the item (\"Kontrollgänge\", \"Mängel\", \"Schichtplan\"), translated by the portal; `label` wins."
          }
        }
      },
      "NavLayoutCatalog": {
        "type": "object",
        "description": "Every value a layout accepts — derived from the code, never hand-kept.",
        "properties": {
          "version": {
            "type": "integer",
            "enum": [
              1
            ]
          },
          "keys": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Catalogue keys (one key = one portal view)."
          },
          "panel_ids": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "`dashboard` lives in `layout.dashboard`, the others in `layout.panels`."
          },
          "rail_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "protected_rail_ids": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Rail items that can never be hidden."
          },
          "required_keys": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Keys the portal editor keeps in the dashboard panel."
          },
          "accents": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "icons": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "default_section_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "limits": {
            "type": "object",
            "properties": {
              "sections_max": {
                "type": "integer"
              },
              "items_max": {
                "type": "integer"
              },
              "label_max": {
                "type": "integer"
              },
              "section_id_pattern": {
                "type": "string"
              }
            }
          },
          "default_layout": {
            "$ref": "#/components/schemas/NavLayout"
          },
          "preset_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "standard",
                "attendance",
                "time",
                "tasks",
                "security"
              ]
            },
            "description": "Menu templates. One applies while no company menu is saved."
          },
          "presets": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/NavLayout"
            },
            "description": "The menu of every template, keyed by `preset_ids`."
          }
        }
      },
      "ReportTemplateSection": {
        "type": "object",
        "description": "One section of a report template. `table`, `incident-feed` and\n`performance-card` sections take a `source` (a generator key from\n`GET /v1/report-templates/catalog`) and an optional `fields` whitelist:\nthe columns to render, in order. An empty or missing `fields` means\nevery column of the source. A key the catalog does not list for that\nsource answers 400.\n",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "cover",
              "kpi-grid",
              "table",
              "map",
              "incident-feed",
              "route-trace",
              "route-events",
              "text",
              "signature",
              "heatmap",
              "trend-line",
              "performance-card",
              "logo",
              "header-meta",
              "shift-plan",
              "custom-html"
            ]
          },
          "source": {
            "type": "string",
            "description": "Generator key, e.g. `worktime.history`."
          },
          "fields": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Column keys of `source`, in render order. Leave out `property_name` to drop the object column."
          },
          "filters": {
            "type": "object",
            "additionalProperties": true,
            "description": "Section-scoped filter overrides on top of `default_filters`."
          },
          "title": {
            "type": "string"
          },
          "subtitle": {
            "type": "string"
          },
          "body": {
            "type": "string",
            "description": "`text` sections only; whitespace is kept."
          },
          "options": {
            "type": "object",
            "properties": {
              "groupBy": {
                "type": "string"
              },
              "sortBy": {
                "type": "string"
              },
              "limit": {
                "type": "integer",
                "minimum": 1
              },
              "leftLabel": {
                "type": "string",
                "description": "`signature` sections: label under the left line."
              },
              "rightLabel": {
                "type": "string"
              }
            }
          }
        }
      },
      "ReportTemplateLayout": {
        "type": "object",
        "properties": {
          "logo": {
            "type": "boolean"
          },
          "cover": {
            "type": "boolean"
          },
          "headerText": {
            "type": "string"
          },
          "footerText": {
            "type": "string"
          },
          "primaryColor": {
            "type": "string"
          },
          "pageSize": {
            "type": "string",
            "enum": [
              "A4",
              "Letter"
            ]
          },
          "orientation": {
            "type": "string",
            "enum": [
              "portrait",
              "landscape"
            ]
          },
          "dateFormat": {
            "type": "string",
            "enum": [
              "DD.MM.YYYY",
              "DD.MM.YY",
              "YYYY-MM-DD"
            ]
          },
          "dateTimeFormat": {
            "type": "string",
            "enum": [
              "DD.MM.YYYY HH:mm",
              "DD.MM.YYYY HH:mm:ss",
              "YYYY-MM-DD HH:mm"
            ]
          }
        }
      },
      "ReportTemplateWrite": {
        "type": "object",
        "description": "Body of `POST` (name required) and `PATCH` (every field optional). Unknown fields answer 422.",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "report_group": {
            "type": "string",
            "enum": [
              "operational",
              "health",
              "custom",
              "live"
            ]
          },
          "sections": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReportTemplateSection"
            }
          },
          "layout": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ReportTemplateLayout"
              },
              {
                "type": "null"
              }
            ]
          },
          "default_filters": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Filters every export with this template starts from (e.g. `{ property_id: 12 }`); the export call may override them."
          },
          "is_shared": {
            "type": "boolean",
            "description": "`true` = every account of the company with the reports right sees and uses it; `false` = only the creating account (the key's account). Default `false` for new templates, `true` for an edited stock template."
          }
        }
      },
      "ReportTemplate": {
        "type": "object",
        "description": "A report template as the portal editor (Exports → Templates) saves it.\n`id` is a UUID — or `default:<slug>` for a stock template the company\nhas not edited yet (virtual, read-only; `created_at`/`updated_at` are\nnull). PATCHing a virtual id creates the company's own copy and\nanswers with its UUID; the same `default:<slug>` keeps resolving to\nthat copy afterwards.\n",
        "properties": {
          "id": {
            "type": "string",
            "description": "UUID or `default:<slug>`."
          },
          "name": {
            "type": "string"
          },
          "picker_label": {
            "type": [
              "string",
              "null"
            ],
            "description": "Plain-language wording for a template picker; null when `name` says it all."
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "report_group": {
            "type": "string",
            "enum": [
              "operational",
              "health",
              "custom",
              "live"
            ]
          },
          "sections": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReportTemplateSection"
            }
          },
          "layout": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ReportTemplateLayout"
              },
              {
                "type": "null"
              }
            ]
          },
          "default_filters": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          },
          "archived_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "is_shared": {
            "type": "boolean"
          },
          "is_default": {
            "type": "boolean",
            "description": "Stock template (virtual or the company's edited copy). Cannot be deleted."
          },
          "schema_version": {
            "type": "integer"
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_used_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_by_account_id": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "ReportTemplateCatalogSource": {
        "type": "object",
        "description": "A data source a template section can render, with the columns and KPIs it offers.",
        "properties": {
          "key": {
            "type": "string",
            "description": "Generator key, e.g. `worktime.history`, `incidents.list`, `tasks.list`."
          },
          "label": {
            "type": "string"
          },
          "fields": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "key": {
                  "type": "string",
                  "description": "Column key for `sections[].fields`, e.g. `property_name`."
                },
                "label": {
                  "type": "string",
                  "description": "Column header in the requested locale."
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "string",
                    "number",
                    "date",
                    "duration",
                    "boolean",
                    "json"
                  ]
                }
              }
            }
          },
          "kpis": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "key": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/v1/me": {
      "get": {
        "summary": "Introspect the calling key (setup/debug)",
        "description": "No scope required. Returns the tenant id, the account the key is\nbound to, the key's name, prefix and scopes, and — since 30.10.2026 —\na `tenant` block with the licence package and the features it\nunlocks, so a `403 ENTITLEMENT_MISSING` or a hidden module can be\nexplained without a database lookup: `package` (starter | standard |\npremium), `variant`, `model`, `model_enforced`, `package_gates`,\n`legacy_unrestricted` (true for tenants without a licence model —\nevery feature reads true then), `features` (one boolean per\nentitlement feature key, e.g. `public_api`, `esignature`,\n`work_orders`, `lone_worker`, `mcp_connect`) and `company_features`\n(the tenant's own switches: `statusgeber_enabled`,\n`subcontractors_enabled`, `worktime_services_enabled`,\n`material_enabled`, `service_level_enabled`, `esignature_enabled`,\n`worktime_confirmation_enabled`, `mcp_enabled`; absent switches\nreport their default — off, except `service_level_enabled` and\n`mcp_enabled` which default to on).\n",
        "responses": {
          "200": {
            "description": "`{ tenant_id, account_id, key: {name, prefix, scopes[]},\ntenant: {package, variant, model, model_enforced, package_gates,\nlegacy_unrestricted, features: {<feature>: boolean},\ncompany_features: {<switch>: boolean}} }`\n"
          }
        }
      }
    },
    "/v1/properties": {
      "get": {
        "summary": "List properties (master data)",
        "description": "Requires scope `properties:read`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "archived",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged property list.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Property"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a property with all of its settings (PMS master-data sync, branch roll-out)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKeyUuid"
          }
        ],
        "description": "Requires scope `properties:write` and the role right to create\nproperties. The body carries the master data plus ANY subset of the\nproperty settings (see `PropertySettings`): modules, time tracking\nincl. execution windows, visit gaps, service window, pauses and\nblocked windows, tamper protection, digital signature, patrol\nsettings, incidents, workdays, timezone, category, responsible\npersons, notification recipients, shift defaults and coordinates.\nUnset settings take the tenant's industry defaults.\n\nThe property, its time-tracking tag, the audit row and every\nsetting are written in ONE transaction — on any error nothing is\nleft behind. After the commit, fail-soft: public holidays\n(`country: DE` + `region` → `holidays_created`), the customer's\nportal access and the device push; problems there come back as\n`warnings[]`, never as an error.\n\n`settings_from_property_id` copies the settings of a property the\nkey can see as the base; explicit fields override; master data,\naddress, coordinates, customer, category and responsible persons are\nnever copied. Creation is NOT subject to change approval (there is\nno current state to protect); PATCH is.\n\nA key restricted to certain properties gains access to the property\nit creates (it shows up in GET /v1/properties afterwards).\n\nIdempotency: pass a client-generated `uuid`. The same `uuid` again\nanswers 200 with `duplicate: true` and the property created first —\ndiffering fields of the replay are ignored. A `uuid` already taken\nby a property the key cannot see (other tenant, hidden property)\nanswers 409 `PROPERTY_KEY_TAKEN` — checked first, nothing is written.\n\nError codes of this surface travel in `reason` (`errorCode` carries\nthe generic family such as `NOT_FOUND`, `CONFLICT`,\n`UNPROCESSABLE_ENTITY`). Tamper protection `geofencing` also sets\nthe property's location lock; `beacon` does not.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PropertyCreate"
              },
              "example": {
                "uuid": "6f1c2a0e-3b7d-4c8e-9f10-2a3b4c5d6e7f",
                "name": "Filiale Nord",
                "street": "Musterstraße",
                "house_number": "1",
                "postal_code": "80331",
                "city": "München",
                "country": "DE",
                "region": "BY",
                "timezone": "Europe/Berlin",
                "settings_from_property_id": 123,
                "responsible_account_ids": [
                  5
                ],
                "workdays": [
                  1,
                  2,
                  3,
                  4,
                  5
                ],
                "show_time": true,
                "show_routes": true,
                "wt_allowed_checkin_methods": [
                  "nfc_tag",
                  "qr_code_static"
                ],
                "wt_allowed_checkout_methods": [
                  "nfc_tag",
                  "qr_code_static"
                ],
                "wt_verification": "geofencing",
                "routes_verification": "geofencing",
                "routes_auto_end_minutes": 120,
                "shift_defaults": {
                  "checkin_start_offset_min": 15,
                  "checkin_end_offset_min": 15
                },
                "location": {
                  "point": [
                    48.137154,
                    11.576124
                  ],
                  "area": {
                    "type": "Polygon",
                    "coordinates": [
                      [
                        [
                          11.575,
                          48.136
                        ],
                        [
                          11.577,
                          48.136
                        ],
                        [
                          11.577,
                          48.138
                        ],
                        [
                          11.575,
                          48.138
                        ],
                        [
                          11.575,
                          48.136
                        ]
                      ]
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Replay of an earlier call with the same `uuid` and the same body — the property created first, nothing written.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PropertyDetail"
                    },
                    "duplicate": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Created property.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PropertyDetail"
                    },
                    "created": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "holidays_created": {
                      "type": "integer"
                    },
                    "warnings": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PropertyWarning"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`RESPONSIBLE_NOT_ASSIGNABLE` (a responsible account is not of the tenant, archived or a customer account — the foreign ids are not echoed), or a rule id (`incident_rule_id`, `visit_gap_rule_id`) of the wrong type / not assignable to properties."
          },
          "404": {
            "description": "`CUSTOMER_NOT_FOUND`, `CATEGORY_NOT_FOUND`, `settings_from_property_id` unknown / not visible to the key, or a rule id that does not exist in the tenant."
          },
          "409": {
            "description": "`PROPERTY_KEY_TAKEN` — the `uuid` names a property the key cannot see. No field of that property is returned."
          },
          "422": {
            "description": "Validation (unknown field, mixed check-in method groups, `region` without `country`, service window half given, bad polygon); `MAIL_UNKNOWN` — a notification address is no mail recipient of the tenant, `errors: [{code: MAIL_UNKNOWN, email}]` names each unknown address; `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH` — the `uuid` was already used with a different request body (since 22.10.2026), nothing written."
          }
        }
      }
    },
    "/v1/properties/bulk": {
      "post": {
        "summary": "Create up to 100 properties in one call",
        "description": "Requires scope `properties:write`. Every row has the shape of\nPOST /v1/properties (own `uuid` per row, unique within the call).\n\nPre-check for ALL rows first (customer, template property, category,\nresponsible persons, rule ids, notification addresses) — a failure\nthere answers 400/404/422 with the same `reason` as the single\nendpoint, the message prefixed with the row (`properties[2]: …`),\nand NOTHING is written. Then every row runs in\nits own transaction: partial success is the contract, a failing row\ndoes not undo the others (see `PropertyBulkResult`). Rows whose\n`uuid` already names a property of this key come back under\n`duplicates`.\n\nTypical use: roll out five branches with the settings of an existing\nproperty — `settings_from_property_id` per row plus the branch's\nmaster data.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "properties"
                ],
                "additionalProperties": false,
                "properties": {
                  "properties": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 100,
                    "items": {
                      "$ref": "#/components/schemas/PropertyCreate"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Per-row result, also when some rows failed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PropertyBulkResult"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Pre-check failed: `RESPONSIBLE_NOT_ASSIGNABLE` or a rule of the wrong type in a row (`properties[i]: …`) — nothing written."
          },
          "404": {
            "description": "Pre-check failed: customer, template property, category or rule of a row (`properties[i]: …`) — nothing written."
          },
          "422": {
            "description": "Validation, duplicate `uuid` within the call, `MAIL_UNKNOWN` of a row (`properties[i]: …`) — nothing written. A `uuid` reused with a different body is NOT a 422 of the call: that row lands in `failed[]` with `reason: IDEMPOTENCY_KEY_PAYLOAD_MISMATCH` (since 22.10.2026)."
          }
        }
      }
    },
    "/v1/properties/{id}": {
      "get": {
        "summary": "Get one property with all of its settings",
        "description": "Requires scope `properties:read`. Every setting the API can set,\nas stored: modules, time tracking, verification, signature, patrol\nand incident settings, workdays, timezone, category, responsible\npersons, notification recipients, shift defaults, coordinates and\n`portal_url`. Unknown, foreign and hidden properties answer alike\n(404).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The property.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PropertyDetail"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found (or not visible to the key)."
          }
        }
      },
      "patch": {
        "summary": "Update property master data and any of its settings",
        "description": "Requires scope `properties:write` and the role right to update\nproperties. The same field set as POST /v1/properties (see\n`PropertyUpdate`) without `uuid` and `settings_from_property_id`:\nname/address, `customer_id`, `notes`, `timezone`, modules, every\n`wt_*` field incl. the execution windows, verification, signature,\npatrol and incident settings, workdays, category, responsible\npersons, notification recipients, shift defaults and coordinates.\nOmitted fields stay untouched, `null` clears a field; the same\nvalidation as on create applies after overlaying the current row.\nEvery change lands in the property's settings history.\n\nChanging `country` or `region` replaces the automatically created\nfuture public holidays: the old region's are removed, the new\nregion's created (`country: DE` + `region`); manually created\nholidays stay. Without `region` or with a country other than DE the\nfuture automatic holidays are only removed.\n\nSubject to the tenant's change approval for property settings: when\nit is switched on and a gated field changes (modules time/patrols/\nincidents, verification, signature, check-in/out methods, GPS\ntracking, beacon threshold, photo fallback, AI classification,\ngeometry), the call needs `change_reason` (body or header\n`X-Change-Reason`, else 422 `CHANGE_REASON_REQUIRED`) and answers 200\nwith `{\"changed\":false,\"approval_pending\":true,\"batch_id\":…,\n\"entity_type\":\"property_settings\",\"label\":…}` — written only after\napproval in the portal. A second gated PATCH while that request is\nstill open answers 409 `REQUEST_PENDING`. Non-gated fields (name,\naddress, notes, …) are written directly.\n\nExample (tender: weekdays 06–10 / 17–21, weekends + holidays\nadditionally 12–14):\n`{\"wt_exec_windows_mode\":\"custom\",\"wt_exec_windows\":{\"weekday\":[{\"start\":\"06:00\",\"end\":\"10:00\"},{\"start\":\"17:00\",\"end\":\"21:00\"}],\"weekend\":[{\"start\":\"06:00\",\"end\":\"10:00\"},{\"start\":\"12:00\",\"end\":\"14:00\"},{\"start\":\"17:00\",\"end\":\"21:00\"}]}}`\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PropertyUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated property with `warnings`, or the pending change request.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/PropertyDetail"
                        },
                        "warnings": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/PropertyWarning"
                          }
                        }
                      }
                    },
                    {
                      "type": "object",
                      "properties": {
                        "changed": {
                          "type": "boolean",
                          "enum": [
                            false
                          ]
                        },
                        "approval_pending": {
                          "type": "boolean",
                          "enum": [
                            true
                          ]
                        },
                        "batch_id": {
                          "type": "string"
                        },
                        "entity_type": {
                          "type": "string",
                          "enum": [
                            "property_settings"
                          ]
                        },
                        "label": {
                          "type": "string"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`RESPONSIBLE_NOT_ASSIGNABLE`, or a rule id of the wrong type / not assignable to properties."
          },
          "403": {
            "description": "The key's account cannot access this property."
          },
          "404": {
            "description": "Property (other tenant), customer, category or rule not found."
          },
          "409": {
            "description": "`REQUEST_PENDING` — a change request for these settings is still awaiting approval."
          },
          "422": {
            "description": "Validation, empty patch, `CHANGE_REASON_REQUIRED` (`errors[0].fields` names the gated fields), `MAIL_UNKNOWN` (`errors: [{code, email}]`)."
          }
        }
      }
    },
    "/v1/properties/{id}/worktime-chip": {
      "post": {
        "summary": "Bind an NFC chip to the property's work-time tag (without a scan)",
        "description": "Requires scope `properties:write` and the role right to update\nproperties. Target is the property's active work-time tag (the tag\npeople scan to clock in/out; it is not reachable via\n`/control-points`). The chip source is EITHER `chip_id` OR\n`from_tag_id` — see `POST /v1/control-points/{id}/chip`: the UID is\ntaken from the source tag's current binding or, after archiving,\nfrom the most recent UID in the configuration audit. Same path as\n\"NFC verbinden\" in the portal: the chip is released from any other\ntag or account of the tenant (audited). Without `overwrite` a chip\nheld by a third tag or account answers 409 `CHIP_IN_USE`; a chip\nstill held by the source tag itself moves without `overwrite`.\n\nNo active work-time tag → 404 `WORKTIME_TAG_MISSING`. Several active\nwork-time tags → the most recently created one is used and the\nresponse carries `multiple: true` together with `target_tag_id`.\nUnknown, foreign and hidden properties answer alike (404).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChipSource"
              },
              "examples": {
                "from_tag": {
                  "summary": "Move the chip of tag 4575 to the property's work-time tag",
                  "value": {
                    "from_tag_id": 4575
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { property_id, target_tag_id, chip_connected: true, multiple? } }`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "property_id": {
                          "type": "integer"
                        },
                        "target_tag_id": {
                          "type": "integer",
                          "description": "The work-time tag that now holds the chip."
                        },
                        "chip_connected": {
                          "type": "boolean",
                          "enum": [
                            true
                          ]
                        },
                        "multiple": {
                          "type": "boolean",
                          "description": "Only present (true) when the property has several active work-time tags; the newest was used."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Property not visible, source tag unknown/foreign, `SOURCE_CHIP_UNKNOWN`, or `WORKTIME_TAG_MISSING`."
          },
          "409": {
            "description": "`CHIP_IN_USE` — chip bound to a third tag/account (without overwrite)."
          },
          "422": {
            "description": "Neither or both of `chip_id` / `from_tag_id` given."
          }
        }
      }
    },
    "/v1/properties/{id}/copy": {
      "post": {
        "summary": "Copy a property (master data and settings; optionally control points, routes, recurring tasks, assignments)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "The property to copy."
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyUuid"
          }
        ],
        "description": "Requires scopes `properties:read` and `properties:write` (the answer carries\nthe values of the source, so the key must be allowed to read it) and\nthe role right to create\nproperties — copying needs the same rights as creating. The source is\nonly read and never changed. Unknown, foreign and hidden source\nproperties answer alike (404).\n\nALWAYS copied: master data (name with ` (Kopie)` appended, address,\ncustomer, category, notes, responsible persons, coordinates and area)\nand every setting (as `settings_from_property_id` does on create).\nAny field of the body wins against the source — pass `customer_id` to\ncopy to another customer, `name` for your own name.\n\nON REQUEST (`include`, default: nothing):\n- `control_points` — control points and task points with their areas\n  (name, notes, type, position, coordinates, GPS radius, image).\n- `routes` — route definitions with their control points, order, time\n  windows and rhythm. Needs `control_points` and `start_date`. Of a\n  route with several versions only the latest is copied. A single\n  appointment keeps its own day and only comes along when that day\n  does not lie before `start_date`.\n- `recurring_tasks` — open tasks of the property that have an active\n  series OR are linked to a control point or route: title,\n  description, priority, labels, assignees, proof switches, signature\n  requirement, form, checklist, rhythm and the links to copied\n  control points and routes. A task that lives only from links whose\n  targets were not copied is skipped. Archived or inactive assignees\n  are dropped (reported). Needs `start_date`.\n- `account_assignments` — accounts assigned to the source also get\n  the copy. Exactly one assignment row per account is added; the\n  account's other assignments and favourites are not touched.\n\nNEVER copied: NFC chips and QR codes (a copied control point has no\nchip and a new `uuid`, which is its QR code), history, patrol runs,\ntask completions, time entries, incidents, customer portal accesses,\narchived accounts.\n\nEach included part needs the right to create that part, checked\nBEFORE anything is written (403 `COPY_PART_NOT_PERMITTED`, the\nmessage names what is missing): `control_points` → scope\n`control_points:write` + create control points; `routes` →\n`routes:write` + create routes; `recurring_tasks` → `tasks:write` +\ncreate tasks; `account_assignments` → `accounts:write` + update\npersons.\n\nThe property itself is created in ONE transaction, exactly like\nPOST /v1/properties. Each control point, route, task and assignment\nis then created through its own create path — the same validation,\naudit row, change approval and notifications as creating it by hand.\nOne record that cannot be copied does not stop the others: `copy`\ncounts per part what was copied, skipped and failed, and\n`copy.issues[]` names every such record with a `code` and a message.\nWhen the tenant requires approval for routes, a copied route becomes\na change request instead (`copy.routes.approval_pending`); send the\nreason as `change_reason` or header `X-Change-Reason`. Where the\ntenant requires a change reason, `routes` and `account_assignments`\nneed it: without one the call answers 422 `CHANGE_REASON_REQUIRED`\nbefore anything is written.\n\n`start_date` is the day from which copied routes and task series\nrun; it must not lie in the past (time zone of the source property).\nA series end of the source is not copied for routes; routes and task\nseries that end before `start_date` are skipped.\n\nIdempotency: pass `Idempotency-Key` (or `uuid`). The same key with\nthe same body answers 200 with `duplicate: true` and the copy created\nfirst — no second property, no second control point. The key is\nlooked up before every other check, so a repeat gets this answer\neven when `start_date` has meanwhile passed. The same key with a\ndifferent body ⇒ 422 `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`. Use a key\nwhenever parts are included: a call repeated WITHOUT a key creates a\nsecond copy.\n\nThe property and its parts are NOT one transaction. If the first\ncall was cut off after the property was created, the repeat does not\ncopy the missing parts: it answers `duplicate: true` with\n`copy: null` and the warning `copy_not_repeated`. Compare the copy\nwith the source in that case. A large property takes time — every\ncontrol point, route and task is created on its own; allow a long\nclient timeout.\n",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PropertyCopy"
              },
              "examples": {
                "settings_only": {
                  "summary": "Master data and settings only",
                  "value": {}
                },
                "everything": {
                  "summary": "With control points, routes, recurring tasks and assignments",
                  "value": {
                    "name": "Filiale Süd",
                    "include": {
                      "control_points": true,
                      "routes": true,
                      "recurring_tasks": true,
                      "account_assignments": true
                    },
                    "start_date": "2026-12-07"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The key was used before with the same body: the copy created first, `duplicate: true`. Nothing written and no part copied again (`copy: null`, warning `copy_not_repeated`).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PropertyDetail"
                    },
                    "duplicate": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "copy": {
                      "type": "null"
                    },
                    "warnings": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PropertyWarning"
                      }
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Copy created. `copy` tells per part what came along.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PropertyDetail"
                    },
                    "created": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "holidays_created": {
                      "type": "integer"
                    },
                    "warnings": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PropertyWarning"
                      }
                    },
                    "copy": {
                      "$ref": "#/components/schemas/PropertyCopyResult"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`RESPONSIBLE_NOT_ASSIGNABLE` — a responsible person of the body is foreign, archived or a customer account."
          },
          "403": {
            "description": "Missing scope or role right to create properties; `COPY_PART_NOT_PERMITTED` — an included part needs a scope or role right the key does not have. Nothing written."
          },
          "404": {
            "description": "Source property unknown, of another tenant or not visible to the key; `CUSTOMER_NOT_FOUND`, `CATEGORY_NOT_FOUND` for fields of the body."
          },
          "409": {
            "description": "`PROPERTY_KEY_TAKEN` — the key names a property the key cannot see."
          },
          "422": {
            "description": "Validation; `COPY_ROUTES_NEED_CONTROL_POINTS` (`include.routes` without `include.control_points`), `COPY_START_DATE_REQUIRED`, `COPY_START_DATE_IN_PAST` (today counts in the time zone of the source property), `start_date` is no calendar day, `CHANGE_REASON_REQUIRED`, `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`. Nothing written."
          }
        }
      }
    },
    "/v1/tasks/{id}/copy": {
      "post": {
        "summary": "Copy a task (title, description, checklist, repetition, assignment)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The task to copy (its `uuid`)."
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyUuid"
          }
        ],
        "description": "Requires scopes `tasks:read` and `tasks:write` (the answer carries\nthe values of the source, so the key must be allowed to read it) and\nthe role right to create tasks —\ncopying needs the same rights as creating. The source is only read\nand never changed. Unknown, foreign and hidden source tasks answer\nalike (404).\n\nCOPIED: title (with ` (Kopie)` appended unless `title` is given),\ndescription, priority, labels, assignees and assigned roles, the\nproof switches (photo, scan, checklist required), signature\nrequirement, form, checklist, the repetition and the links to control\npoints and routes that still exist. The copy stays in the property of\nthe source and records where it came from (`source_task_uuid`).\n\nNEVER copied: completions, history, comments, times, incidents and\nthe due date of a one-off task. Archived or inactive assignees are\ndropped and named in `copy.issues[]`.\n\nA copied series runs from `start_date` (default: today in the time\nzone of the property); it must not lie in the past. A series end of\nthe source that lies before `start_date` is not taken over. A series\nthat has no date on or after `start_date` ⇒ 422\n`COPY_SERIES_HAS_NO_DATE`.\n\nThe copy is created through the same path as POST /v1/tasks: the\nsame validation, licence limits, audit row and notifications. Like\ncreating, copying never needs a change reason.\n\nIdempotency: pass `Idempotency-Key` (or `uuid`); it becomes the\n`uuid` of the copy. The same key again answers 200 with\n`duplicate: true` and the copy created first — no second task. A key\nthat already belongs to a task which is not a copy of this source ⇒\n422 `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`. The same key with a different\n`title` or `start_date` is another request and answers the same 422.\nA repeat carries the same `copy.issues[]` as the first answer.\n",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "uuid": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Idempotency key (alternatively header `Idempotency-Key`); becomes the `uuid` of the copy."
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500,
                    "description": "Default: title of the source + ` (Kopie)`, shortened to fit 500 characters."
                  },
                  "start_date": {
                    "type": "string",
                    "format": "date",
                    "description": "Day from which a copied series runs (YYYY-MM-DD, not in the past). Default: today in the time zone of the property."
                  }
                }
              },
              "examples": {
                "defaults": {
                  "summary": "Copy with defaults",
                  "value": {}
                },
                "series": {
                  "summary": "Series starts next Monday",
                  "value": {
                    "title": "Treppenhaus reinigen Haus B",
                    "start_date": "2026-12-07"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The key was used before for the same request: the copy created first, `duplicate: true` and the same `copy.issues[]`. Nothing written."
          },
          "201": {
            "description": "Copy created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/Task"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "source_task_uuid": {
                              "type": "string",
                              "format": "uuid",
                              "description": "The task this one was copied from."
                            }
                          }
                        }
                      ]
                    },
                    "created": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "copy": {
                      "type": "object",
                      "properties": {
                        "issues": {
                          "type": "array",
                          "description": "What did not come along (for example an archived assignee), each with a `code` and a message.",
                          "items": {
                            "type": "object",
                            "properties": {
                              "code": {
                                "type": "string"
                              },
                              "message": {
                                "type": "string"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope `tasks:write` or role right to create tasks."
          },
          "404": {
            "description": "Source task unknown, of another tenant or not visible to the key."
          },
          "409": {
            "description": "The key is already in use and cannot be used for this copy."
          },
          "422": {
            "description": "`COPY_START_DATE_IN_PAST`, `COPY_SERIES_HAS_NO_DATE`, `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`, or a validation error of the body."
          }
        }
      }
    },
    "/v1/routes/{id}/copy": {
      "post": {
        "summary": "Copy a patrol route (control points, order, time windows, rhythm)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "The route to copy (`route_id`)."
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyUuid"
          }
        ],
        "description": "Requires scopes `patrols:read` and `routes:write` (the answer carries\nthe values of the source, so the key must be allowed to read it) and\nthe role right to create routes —\ncopying needs the same rights as creating. The source is only read\nand never changed. Unknown, foreign and hidden routes answer alike\n(404). Only the route's own time windows are copied; a route that a\ntour stop uses stays usable by that tour. A route without a time\nwindow of its own answers 422 `ROUTE_WITHOUT_TIME_WINDOW`.\n\nCOPIED into the same property: name (with ` (Kopie)` appended,\nshortened to 50 characters, unless `name` is given), notes, the\ncontrol points with order and duty flag, every time window, the\nrhythm (weekdays, days of the month, interval, public-holiday rule)\nand the reaction rule. The control points are the SAME points — no\npoint and no NFC chip or QR code is created.\n\nNEVER copied: runs, scans, history and the task linked to the\nsource. Every time window starts on `start_date` (default: tomorrow\nin the time zone of the property; not in the past). A series end of\nthe source is not taken over.\n\nThe copy is created through the same path as POST /v1/routes: the\nsame validation, audit row and change approval. Where the tenant\nrequires approval for routes, the call files a change request and\nanswers `ApprovalPending` with HTTP 200 instead of creating the\nroute; send the reason as `change_reason` or header\n`X-Change-Reason`. Where the tenant requires a change reason, a call\nwithout one answers 422 `CHANGE_REASON_REQUIRED` and writes nothing.\n\nIdempotency: pass `Idempotency-Key` (or `uuid`). The same key with\nthe same body answers 200 with `duplicate: true` and the route (or\nthe change request) created first. The same key with a different\nbody ⇒ 422 `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`; a second call while\nthe first is still running ⇒ 409 `IDEMPOTENCY_KEY_IN_PROGRESS`. A\ncall that failed releases its key, so the corrected call may reuse\nit.\n",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "uuid": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Idempotency key (alternatively header `Idempotency-Key`)."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Default: name of the source + ` (Kopie)`, shortened to fit 50 characters."
                  },
                  "start_date": {
                    "type": "string",
                    "format": "date",
                    "description": "Day on which every copied time window starts (YYYY-MM-DD, not in the past). Default: tomorrow in the time zone of the property."
                  },
                  "change_reason": {
                    "type": "string",
                    "description": "Reason for the audit trail and the change approval (alternatively header `X-Change-Reason`)."
                  }
                }
              },
              "examples": {
                "defaults": {
                  "summary": "Copy with defaults",
                  "value": {}
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Either the key was used before with the same body (`{ data, duplicate: true }`, nothing written), or the tenant requires approval: `ApprovalPending` (`entity_type: route_config`), no route created yet."
          },
          "201": {
            "description": "Copy created: `{ data: <route as GET /v1/routes/{id}> + source_route_id, created: true }`."
          },
          "403": {
            "description": "Missing scope `routes:write` or role right to create routes."
          },
          "404": {
            "description": "Source route unknown, of another tenant or not visible to the key."
          },
          "409": {
            "description": "`IDEMPOTENCY_KEY_IN_PROGRESS` — the first call with this key has not finished."
          },
          "422": {
            "description": "`ROUTE_WITHOUT_TIME_WINDOW`, `COPY_START_DATE_IN_PAST`, `CHANGE_REASON_REQUIRED`, `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`, or a validation error of the body."
          }
        }
      }
    },
    "/v1/tasks": {
      "get": {
        "summary": "List tasks",
        "description": "Requires scope `tasks:read`. Without `due`/`assignee_id`/`priority`\nthe list is ordered newest first. With one of them the list follows\nthe board order of the portal (manual order, else newest first) and\nuses the portal's single definition of \"overdue\" (due date or due\ntime passed, not done, no open \"not feasible\" report; a task with an\nactive schedule counts as `overdue` only while TODAY's planned\noccurrence is open and its deadline — `end_time`, else `start_time`,\nin the property's time zone — has passed; its `due_date` is just the\ndisplayed start, past missed days surface per occurrence);\n`today`/`week` resolve recurring tasks in the tenant's\ntime zone. On that path tasks\nWITHOUT a property are not returned to property-restricted keys.\n`due` together with `state_id` → 422.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "state_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "due",
            "in": "query",
            "description": "overdue, today, week — or one day YYYY-MM-DD: tasks due (due_date) or planned as a series occurrence on exactly that day (versions and exceptions of the series included).",
            "schema": {
              "type": "string",
              "pattern": "^(overdue|today|week|\\d{4}-\\d{2}-\\d{2})$"
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Part of the title (case-insensitive), e.g. \"Treppenhaus\".",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            }
          },
          {
            "name": "assignee_id",
            "in": "query",
            "description": "Only tasks assigned to this account (any of the assignees).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "priority",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "HIGH",
                "MEDIUM",
                "LOW"
              ]
            }
          },
          {
            "name": "include_archived",
            "in": "query",
            "description": "Include archived task definitions (soft archive, PR U). Default false — lists return active tasks only.",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged task list `{ data: [Task + {priority, assignee_ids,\nassignee_role_ids}], total, page, pageSize }`. `priority`\n(HIGH|MEDIUM|LOW|null), `assignee_ids` (all assigned account ids,\nin assignment order) and `assignee_role_ids` (roles responsible,\nsee the Task schema) are additive list fields.\n"
          },
          "422": {
            "description": "Invalid filter, or `due` combined with `state_id`."
          }
        }
      },
      "post": {
        "summary": "Create a task (\"guest checked out → cleaning task\")",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKeyUuid"
          }
        ],
        "description": "Requires scope `tasks:write`. Pass a client-generated `uuid` to make\nretries idempotent (a redelivered webhook creates no duplicate).\nWithout `state_id` the task lands in the tenant's first board column.\n`assignee_id` must be an account of the tenant (400 otherwise);\n`assignee_role_ids` must be roles of the tenant (400 otherwise;\nids from GET /v1/roles) — people and roles may be combined, a task\nwith roles only has no `assignee_id`; `state_id` must be a board\ncolumn of the tenant (404 otherwise).\nA `uuid` that is already taken by a task the key account cannot see\nanswers 409 (`errorCode: CONFLICT`) — checked first, nothing is\ncreated or changed, no field of that task is returned. A `uuid` of\nan own, visible task reused with a DIFFERENT body answers 422\n`IDEMPOTENCY_KEY_PAYLOAD_MISMATCH` (since 22.10.2026; the body\nfingerprint is stored on create, tasks created before replay as\nbefore) — right after the uuid check, nothing written.\n\n**One call per control point.** `checklist`, `bindings` and\n`schedule` let you create a complete task per point in one request:\nthe points of the checklist (up to 50), the control points or patrol\nroutes the task hangs on, and the recurrence rule. The order of\nchecks is part of the contract: uuid → property access (403) →\n`form_template_id` (400) → every binding target (400 outside the\ntenant, 403 outside the key's properties) → create →\nsettings → checklist → bindings → schedule. A `uuid` replay returns\nthe task created first and writes NOTHING again — 200 with\n`duplicate: true` (same `data` shape; the counters mirror what\nexists). `form_template_id` together with a\nchecklist point that requires a photo is a schema error (422, issue\non `checklist`). A `schedule` that yields no date from today on is\nrejected with 422 `SCHEDULE_EMPTY` — the task, its checklist and\nbindings then already exist (the services commit separately); set\nthe schedule again with PUT /v1/tasks/{id}/schedule. A `schedule`\nwith a holiday rule (`type_freedays` other than `none` or\n`nonworking_rule` other than `skip`) first refreshes the property's\npublic holidays; if the property has no `country: DE` or no `region`,\nthe call answers 422 `PROPERTY_WITHOUT_REGION` (also in `reason`)\ninstead of `SCHEDULE_EMPTY` — set them and retry. With a\n`schedule` and no `due_date`, the task takes the rule's FIRST planned\ndate from today on (holidays and workdays of the property included;\n`start_date` itself need not be a planned day) and `start_time` as\nits due date — the portal shows it as \"starts on\" for a series. If\nthe rule yields no date, `due_date` stays empty. `PUT …/schedule`\nmoves it to the first date of the new rule. For a series `due_date`\nis display only; the series is returned under `due=overdue` only while\ntoday's occurrence is open and past its deadline (`end_time`, else\n`start_time`).\n\nChecklist points live on the task itself (no background template).\nOne switch decides what they mean: checklist_required = all items are required (required checklist): every point ticked or marked not applicable with a reason, every photo point has a photo; off = points may stay open, open points show in the report. Task-level photo_required is waived while the required checklist has photo points.\nA point with `photo_required: true` asks for a photo at that point;\nit blocks completion only when all items are required. `photo_required` on the\ntask itself asks for ONE photo per completion — the lean choice for\n\"one proof per room\".\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title"
                ],
                "additionalProperties": false,
                "properties": {
                  "uuid": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "title": {
                    "type": "string"
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "priority": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "HIGH",
                      "MEDIUM",
                      "LOW",
                      null
                    ]
                  },
                  "labels": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "due_date": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date"
                  },
                  "due_time": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
                    "description": "HH:mm; requires due_date (400 otherwise)."
                  },
                  "due_end_time": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
                    "description": "HH:mm; end of the due window. Requires due_time and must lie after it (400 otherwise); null = no end. With a `schedule` the rule carries `end_time` and this stays null."
                  },
                  "property_id": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "assignee_id": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "assignee_role_ids": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "maxItems": 20,
                    "items": {
                      "type": "integer",
                      "minimum": 1
                    },
                    "description": "Roles responsible for the task (GET /v1/roles; tenant roles only, 400 otherwise). Omitted, `[]` or `null` = no role. May be combined with `assignee_id`."
                  },
                  "state_id": {
                    "type": "integer"
                  },
                  "form_template_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid",
                    "description": "Own, ACTIVE form template (400 otherwise) that must be filled in on completion. Not together with a checklist point that requires a photo (422, validation issue on `checklist`)."
                  },
                  "require_scan": {
                    "type": "boolean"
                  },
                  "photo_required": {
                    "type": "boolean",
                    "description": "One photo per completion of the whole task. Waived while the required checklist has photo points."
                  },
                  "checklist_required": {
                    "type": "boolean",
                    "default": false,
                    "description": "checklist_required = all items are required (required checklist): every point ticked or marked not applicable with a reason, every photo point has a photo; off = points may stay open, open points show in the report. Task-level photo_required is waived while the required checklist has photo points."
                  },
                  "checklist": {
                    "type": "array",
                    "maxItems": 50,
                    "description": "Points of the checklist, in order. Omitted or `[]` = no checklist.",
                    "items": {
                      "type": "object",
                      "required": [
                        "title"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "title": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 300
                        },
                        "photo_required": {
                          "type": "boolean",
                          "description": "This point needs a photo (enforced only with `checklist_required`; otherwise a missing photo shows in the report)."
                        }
                      }
                    }
                  },
                  "bindings": {
                    "type": "array",
                    "maxItems": 200,
                    "description": "Same items as PUT /v1/tasks/{id}/bindings (`CHECKPOINT` + `tag_id`, `ROUTE` + `route_id`, optional `role_ids`). Replaces nothing — the task is new.",
                    "items": {
                      "type": "object",
                      "required": [
                        "binding_type"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "binding_type": {
                          "type": "string",
                          "enum": [
                            "CHECKPOINT",
                            "ROUTE"
                          ]
                        },
                        "tag_id": {
                          "type": "integer"
                        },
                        "route_id": {
                          "type": "integer"
                        },
                        "role_ids": {
                          "type": [
                            "array",
                            "null"
                          ],
                          "maxItems": 50,
                          "items": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "description": "Roles (GET /v1/roles) that see the task at this point. Missing, empty or null = the assignee of the task decides (no assignee = every role)."
                        }
                      }
                    }
                  },
                  "schedule": {
                    "type": "object",
                    "description": "Same body as PUT /v1/tasks/{id}/schedule without `effective_from` (`repeat_type`, `weekdays`, `monthdays`, `frequency`, `start_date`, `end_date`, `occurrence_count`, `start_time`, `type_freedays`, `anchor_mode`, `window_mode`, `tolerance_days`, `nonworking_rule`, `active`). No change approval on create — there is no series to change yet."
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Optional. Creating needs no reason (initial creation), even when the tenant requires reasons for changes; when given, it is stored with the task's created row (alternatively header X-Change-Reason)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created (or idempotently returned) task: `{ data: { task_id, uuid,\ntitle, state_id, checklist_count, form_template_id,\nbindings_count, schedule } }` — `form_template_id` is the\nbackground checklist template when a point requires a photo,\n`schedule` is `true` when a plan was written. On a `uuid` replay\nthe counters mirror the existing task (nothing written).\n"
          },
          "400": {
            "description": "A binding target (control point or patrol route) outside the tenant, or a `form_template_id` that is not an own, active template."
          },
          "403": {
            "description": "Property (of the task or of a binding target) outside the key account's restriction."
          },
          "409": {
            "description": "The `uuid` is already in use by a task outside the key account's visibility."
          },
          "422": {
            "description": "`errorCode: IDEMPOTENCY_KEY_PAYLOAD_MISMATCH` — the `uuid` was already used with a different request body (nothing written). Schema error (also `form_template_id` together with a checklist point that requires a photo — issue on `checklist`), or `errorCode: SCHEDULE_EMPTY` — the plan yields no date from today on; task, checklist and bindings exist already. `errorCode: PROPERTY_WITHOUT_REGION` — the plan uses a holiday rule but the property has no country DE or no region; set them and retry."
          }
        }
      }
    },
    "/v1/tasks/{id}": {
      "get": {
        "summary": "Get a task",
        "description": "Requires scope `tasks:read`. `id` is the task uuid (as returned by\nlist/create). Property-restricted key accounts only see tasks on\naccessible properties (tenant-wide tasks without a property stay\nvisible); anything else answers 404.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Task detail: the list row shape (incl. `priority`, `assignee_ids` and `assignee_role_ids` — the same additive fields as GET /v1/tasks) plus `checklist` (TaskChecklistItem[]) and `checklist_source` (`items` | `template` | null)."
          }
        }
      },
      "patch": {
        "summary": "Edit task fields (title, priority, due date, assignment, …)",
        "description": "Requires scope `tasks:write`. Partial patch over the same internal\nsettings path as the portal editor — assignee/property tenant guards,\nedit log and `task.assigned` workflow event apply identically. Omitted\nfields stay untouched, `null` clears a field. `assignee_ids` (full\nassignment set) wins over the legacy single `assignee_id`; `[]` or\n`null` unassigns. `assignee_role_ids` is the full set of roles\nresponsible (tenant roles, 400 otherwise): `[]` or `null` removes all\nroles, omitted leaves them unchanged; it is independent of\n`assignee_ids` (clearing people keeps the roles and vice versa).\nThe board state is deliberately NOT patchable here —\nuse POST /v1/tasks/{id}/state. Moving the task to a property outside\nthe key account's restriction answers 403 (`permission_denied`) —\na task uuid the key cannot see answers 404. Moving a task that is\nbound to control points or patrol routes of its current property\nanswers 409 (`errorCode: TASK_BOUND_TO_PROPERTY`, body `bindings:\n{ control_points, routes }`): detach the bindings first\n(PUT /v1/tasks/{id}/bindings), then patch again. Nothing is changed.\n`checklist` replaces the whole checklist (same rules as PUT\n/v1/tasks/{id}/checklist) BEFORE the other fields are written, so\n`checklist: null` together with `form_template_id` binds the form\non a clean task. Binding a regular form template drops any plain\nchecklist rows (a task carries a checklist OR a form). Points\ntogether with `form_template_id` in one patch answer 400\n`CHECKLIST_WITH_FORM`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "minProperties": 1,
                "additionalProperties": false,
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "priority": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "HIGH",
                      "MEDIUM",
                      "LOW",
                      null
                    ]
                  },
                  "labels": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "string"
                    }
                  },
                  "due_date": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date"
                  },
                  "due_time": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
                    "description": "HH:mm; `null` clears the time. Clearing due_date clears due_time as well; a time without a date is rejected (400)."
                  },
                  "due_end_time": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
                    "description": "HH:mm; end of the due window, `null` clears it. Requires a due_time (400 when the task has none or the end is not after it). Clearing due_date or due_time clears the end as well; a due_time moved onto or past the end clears the end silently."
                  },
                  "property_id": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "assignee_id": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "assignee_ids": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "integer"
                    }
                  },
                  "assignee_role_ids": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "maxItems": 20,
                    "items": {
                      "type": "integer",
                      "minimum": 1
                    },
                    "description": "Full set of roles responsible (GET /v1/roles); `[]` or `null` removes all roles, omitted = unchanged. Independent of `assignee_ids`."
                  },
                  "photo_required": {
                    "type": "boolean",
                    "description": "One photo per completion of the whole task. Waived while the required checklist has photo points."
                  },
                  "require_scan": {
                    "type": "boolean"
                  },
                  "checklist_required": {
                    "type": "boolean",
                    "description": "checklist_required = all items are required (required checklist): every point ticked or marked not applicable with a reason, every photo point has a photo; off = points may stay open, open points show in the report. Task-level photo_required is waived while the required checklist has photo points."
                  },
                  "form_template_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid",
                    "description": "Own, ACTIVE form template (400 otherwise); `null` detaches the form."
                  },
                  "checklist": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "maxItems": 50,
                    "description": "Complete new checklist (full replace); `null` or `[]` removes it. `field_id` is tolerated for older clients and ignored.",
                    "items": {
                      "type": "object",
                      "required": [
                        "title"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "title": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 300
                        },
                        "photo_required": {
                          "type": "boolean"
                        },
                        "field_id": {
                          "type": "string",
                          "maxLength": 64
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated task detail (same shape as GET)."
          },
          "404": {
            "description": "Task (or target property) not visible for this key."
          },
          "409": {
            "description": "`errorCode: TASK_BOUND_TO_PROPERTY` — the task is bound to control points / patrol routes of another property than the target; `bindings.control_points` and `bindings.routes` carry the counts. With `checklist` points: `CHECKLIST_TEMPLATE_SHARED` or `TASK_HAS_FORM` (see PUT /v1/tasks/{id}/checklist); `checklist: null` never conflicts."
          }
        }
      }
    },
    "/v1/tasks/{id}/checklist": {
      "get": {
        "summary": "Read the checklist of a task",
        "description": "Requires scope `tasks:read`. Same visibility rule as GET /v1/tasks/{id}\n(404 when the key cannot see the task). `source` says where the points\nlive (`items` = plain rows, `template` = background template of kind\n`checklist`, `null` = none — also when the task is bound to a regular\nform; its fields are not a checklist).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: TaskChecklistState }`."
          },
          "404": {
            "description": "Task not visible for this key."
          }
        }
      },
      "put": {
        "summary": "Replace the checklist of a task",
        "description": "Requires scope `tasks:write`. Full replace — the body is the complete\nnew list in order (`items: []` removes the checklist — always\nallowed, also while a regular form template is bound: only the plain\nrows are dropped, the form stays). Same rules as the portal's task\ndrawer:\n\n- no point requires a photo and no checklist template is bound →\n  plain rows are replaced;\n- at least one point requires a photo and no template is bound →\n  LiteLog creates and publishes a background form template\n  (`template_kind: checklist`, scope `tag`, no assignment, one\n  `task` field per point, named \"<title> – Checkliste\"), binds it via\n  `form_template_id` and drops the plain rows. The form-template\n  approval gate does not apply (the template belongs to this task\n  and never appears in the app's form hub);\n- a checklist template is bound and only this task uses it → its\n  schema is rewritten; points with `field_id` keep their field,\n  points without get a new one. When no point requires a photo any\n  more, the template is archived and the points become plain rows\n  again;\n- a checklist template is bound and other tasks use it too → 409\n  `CHECKLIST_TEMPLATE_SHARED` (change the points in the portal or\n  detach the template first);\n- the bound template is a regular form (not a checklist any more) →\n  409 `TASK_HAS_FORM`.\n\nChanges to the background template are written to the configuration\naudit; the mobile app picks the new list up on its next pull.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "items"
                ],
                "additionalProperties": false,
                "properties": {
                  "items": {
                    "type": "array",
                    "maxItems": 50,
                    "items": {
                      "type": "object",
                      "required": [
                        "title"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "title": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 300
                        },
                        "photo_required": {
                          "type": "boolean"
                        },
                        "field_id": {
                          "type": "string",
                          "maxLength": 64,
                          "description": "Keep this field of the background template (from GET)."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: TaskChecklistState }` — the new list, with fresh `item_id`/`field_id` values."
          },
          "404": {
            "description": "Task not visible for this key."
          },
          "409": {
            "description": "`errorCode: CHECKLIST_TEMPLATE_SHARED` (the bound checklist template is used by other tasks) or `TASK_HAS_FORM` (the bound template is a regular form)."
          }
        }
      }
    },
    "/v1/tasks/{id}/state": {
      "post": {
        "summary": "Move a task to another board state (e.g. complete it)",
        "description": "Requires scope `tasks:write`. Same internal path as the portal board:\nmoving into the completed column fires the `task.completed` workflow\nevent, notifies a raising customer and pushes live updates. Pick the\n`state_id` from GET /v1/task-states. `completed_at` is honoured only\nfor terminal states (completed/cancelled); omitted, the server stamps\n\"now\". Non-terminal states reset `completed_at` to null.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "state_id"
                ],
                "additionalProperties": false,
                "properties": {
                  "state_id": {
                    "type": "integer"
                  },
                  "completed_at": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { task_id, uuid, state_id, completed_at } }`."
          },
          "404": {
            "description": "Task not visible for this key, or state not in tenant."
          }
        }
      }
    },
    "/v1/tasks/{id}/archive": {
      "post": {
        "summary": "Archive a task (soft archive — tasks are never deleted)",
        "description": "Requires scope `tasks:write` and the archive permission (`DELETE_TASKS`,\nlabelled \"archive tasks\"). Sets `archived_at`; the definition is then\nfrozen (PATCH / state changes answer 409 `task_archived`), future\noccurrences disappear from lists, the app and rules, while completions,\nincidents, comments and the audit trail are kept. Writes the audit-trail\nrow `archived` with the change reason (`change_reason` in the body or\nheader `X-Change-Reason`; required when the tenant enforces reasons).\nIdempotent: an already archived task answers `changed: false`.\n\nA task with a live repetition (active plan, series not ended) ends\nthat series when archived — this is a change of the repetition. When\nthe tenant requires approval for task schedules, the call files a\nchange request instead (send `change_reason`) and answers\n`ApprovalPending` with HTTP 200; the task is archived once approved.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "change_reason": {
                    "type": "string",
                    "description": "`[code] text`, e.g. `[other] pilot ended`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { task_id, uuid, archived_at, changed } }`, or `ApprovalPending` (`entity_type: task_schedule`) for a task with a live repetition under change approval."
          },
          "404": {
            "description": "Task not visible for this key."
          },
          "422": {
            "description": "Change reason required."
          }
        }
      }
    },
    "/v1/tasks/{id}/restore": {
      "post": {
        "summary": "Restore an archived task",
        "description": "Requires scope `tasks:write` and the archive permission. Clears\n`archived_at` and writes the audit-trail row `restored`; the task\nreturns to lists exactly as it was. Idempotent for active tasks.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "change_reason": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { task_id, uuid, archived_at: null, changed } }`."
          },
          "404": {
            "description": "Task not visible for this key."
          }
        }
      }
    },
    "/v1/tasks/{id}/comments": {
      "get": {
        "summary": "List the comments of a task",
        "description": "Requires scope `tasks:read`. The latest `limit` comments in\nchronological order, internal team notes included (`internal: true`).\nNo attachments, no avatars. Visibility as GET /v1/tasks/{id}: unknown,\nother tenant and outside the key's property restriction answer the\nsame 404.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 25
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{comment_id, body, author_account_id, author_name,\nauthor_is_customer, internal, created_at}], has_more }`\n"
          },
          "404": {
            "description": "Task not visible for this key."
          }
        }
      },
      "post": {
        "summary": "Add an internal comment to a task",
        "description": "Requires scope `tasks:write`. The comment is ALWAYS internal (team\nonly): the customer does not see it and no customer e-mail is sent.\nThere is deliberately no field to make it customer-visible — replies\nto customers are written in the portal. Unknown fields → 422.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "body"
                ],
                "additionalProperties": false,
                "properties": {
                  "body": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 10000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ data: {comment_id, task_uuid, internal: true, created_at} }`"
          },
          "404": {
            "description": "Task not visible for this key."
          }
        }
      }
    },
    "/v1/tasks/{id}/history": {
      "get": {
        "summary": "Task history (activity log)",
        "description": "Requires scope `tasks:read`. Newest entries first. Page with\n`starting_after` = `task_log_id` of the last entry of the previous\npage.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 25
            }
          },
          {
            "name": "starting_after",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{task_log_id, log_type, msg, timestamp,\nactor_account_id, actor_name}], has_more }`\n"
          },
          "404": {
            "description": "Task not visible for this key."
          }
        }
      }
    },
    "/v1/tasks/{id}/completions": {
      "get": {
        "summary": "Completions of a task",
        "description": "Requires scope `tasks:read`. Newest first, cancelled completions\nincluded (`cancelled: true`) — a cancelled completion explains why an\noccurrence is open again. Page with `starting_after` = `completion_id`\nof the last entry of the previous page. Photos, notes and the free\ntext of a cancel reason are not part of the list.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 25
            }
          },
          {
            "name": "starting_after",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "occurrence_date",
            "in": "query",
            "description": "Only the completions of this occurrence of the series.",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{completion_id, occurrence_date, completed_at,\naccount_id, completed_without_scan, form_response_id, cancelled,\ncancelled_at, cancelled_by_account_id, cancel_reason_code}],\nhas_more }`\n"
          },
          "404": {
            "description": "Task not visible for this key."
          }
        }
      }
    },
    "/v1/tasks/{id}/completions/{completionId}/cancel": {
      "post": {
        "summary": "Cancel a completion",
        "description": "Requires scope `tasks:write` and the permission `DELETE_TASKS`, like\nthe portal. The proof stays in the history but no longer counts; the\noccurrence is open again and the webhook `task.completion.cancelled`\nis sent. This is the way out of `409 ACTIVE_COMPLETION` on\n`POST /v1/tasks/{id}/state`.\n\nThe reason is mandatory and coded: `reason_code` plus `reason_text`\n(required for `other`).\n\nA task that requires a digital signature cannot be cancelled with an\nAPI key (422 `Esignature required`) — cancel it in the portal. When\nthe tenant requires approval for cancellations, the call files a\nchange request and answers `ApprovalPending` with HTTP 200; the\ncompletion stays valid until the request is approved.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "completionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reason_code"
                ],
                "additionalProperties": false,
                "properties": {
                  "reason_code": {
                    "type": "string",
                    "enum": [
                      "correction",
                      "new_requirement",
                      "customer_request",
                      "error_fix",
                      "periodic_review",
                      "other"
                    ]
                  },
                  "reason_text": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Required for `other`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { completion_id, task_uuid, occurrence_date, cancelled, cancelled_at, cancel_reason_code, task_reopened } }`, or `ApprovalPending` (`entity_type: task_completion`)."
          },
          "404": {
            "description": "Task not visible for this key, or the completion does not belong to this task."
          },
          "409": {
            "description": "`errorCode: COMPLETION_ALREADY_CANCELLED`."
          },
          "422": {
            "description": "Invalid body, or `{ error: \"Esignature required\", reason, allowed_methods }` when the task requires a signature."
          }
        }
      }
    },
    "/v1/tasks/{id}/completions/{completionId}/reassign-target": {
      "get": {
        "summary": "Where may this completion be moved to?",
        "description": "Requires scope `tasks:read` and the permission `DELETE_TASKS`. Read\nonly. A completion can be moved to exactly one occurrence: the one\nwhose completion window (occurrence ± tolerance) contains the day of\nthe completion — and only when that day is NOT inside the window of\nits current occurrence. `target` is that occurrence; `blocker` names\nwhy the correction is not possible (see the 409 codes of\n`POST …/reassign`).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "completionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { completion_id, task_uuid, completed_day, current,\ntarget, blocker } }` — `current` and `target` are\n`{ occurrence_date, due, window_from, window_to }` or null;\n`blocker` is a code or null.\n"
          },
          "404": {
            "description": "Task not visible for this key, or the completion does not belong to this task."
          }
        }
      }
    },
    "/v1/tasks/{id}/completions/{completionId}/reassign": {
      "post": {
        "summary": "Move a completion to the occurrence it belongs to",
        "description": "Requires scope `tasks:write` and the permission `DELETE_TASKS`. The\ncompletion stays as it is (time, account, proof); only its occurrence\nchanges. The former occurrence is open again and may be reported as\noverdue. Typical case: someone ticked the task in last week's calendar\nwhile this week's window was already open.\n\n`occurrence_date` must be the `target` of `GET …/reassign-target`; the\nserver computes it again. The reason is mandatory and coded\n(`reason_code`, `reason_text` required for `other`). Writes two\nhistory entries (`COMPLETION_REASSIGNED`), an audit-trail row with old\nand new occurrence, and sends the webhook `task.completion.reassigned`.\n`task.completed` is not sent again.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "completionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "occurrence_date",
                  "reason_code"
                ],
                "additionalProperties": false,
                "properties": {
                  "occurrence_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "reason_code": {
                    "type": "string",
                    "enum": [
                      "correction",
                      "new_requirement",
                      "customer_request",
                      "error_fix",
                      "periodic_review",
                      "other"
                    ]
                  },
                  "reason_text": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Required for `other`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { completion_id, task_uuid, occurrence_date, previous_occurrence_date } }`."
          },
          "404": {
            "description": "Task not visible for this key, or the completion does not belong to this task."
          },
          "409": {
            "description": "`errorCode` (also in `errors[0].code`):\n`COMPLETION_ALREADY_CANCELLED`, `REASSIGN_NO_OCCURRENCE_DATE`\n(completion without occurrence), `REASSIGN_NO_COVERING_OCCURRENCE`\n(no series, or no occurrence covers the day),\n`REASSIGN_ALREADY_VALID`, `REASSIGN_SIGNED` (verified signature\ncovers the occurrence), `REASSIGN_APPROVAL_REQUIRED` (tenant uses\napproval for cancellations), `REASSIGN_REQUEST_PENDING`,\n`REASSIGN_TARGET_OCCUPIED`, `REASSIGN_TARGET_NOT_FEASIBLE`,\n`REASSIGN_TARGET_MISMATCH` (`errors[0].target` carries the\ncomputed target).\n"
          },
          "422": {
            "description": "Invalid body."
          }
        }
      }
    },
    "/v1/tasks/{id}/notes": {
      "post": {
        "summary": "Add a note to the task history",
        "description": "Requires scope `tasks:write`. Writes a history entry of type `ADD_NOTE`.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "note"
                ],
                "additionalProperties": false,
                "properties": {
                  "note": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 10000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ data: {task_uuid, task_log_id, created_at} }`"
          },
          "404": {
            "description": "Task not visible for this key."
          }
        }
      }
    },
    "/v1/tasks/{id}/bindings": {
      "get": {
        "summary": "List the checkpoint/route links of a task",
        "description": "Requires scope `tasks:read`. Same visibility rule as GET /v1/tasks/{id}\n(404 when the key cannot see the task).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: TaskBinding[] }`."
          }
        }
      },
      "put": {
        "summary": "Replace the checkpoint/route links of a task",
        "description": "Requires scope `tasks:write`. Replace-set semantics — the body is the\ncomplete new set (`[]` unlinks everything); same internal path as the\nportal's \"Verknüpfungen bearbeiten\". Each entry names exactly one\ntarget: `tag_id` for `CHECKPOINT`, `route_id` for `ROUTE`. Optional\n`role_ids` per entry restricts who sees the task at that point (the\nportal's \"Am Punkt sichtbar für\"); missing, empty or `null` = every\nrole. Targets or roles outside the tenant answer 400, a target\nproperty outside the key account's restriction 403. A ROUTE binding deactivates the task's own\nschedule (the route's rhythm takes over). Linked checkpoints are\nstamped for the mobile sync, so devices pick up the task at the point\non their next pull.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "bindings"
                ],
                "additionalProperties": false,
                "properties": {
                  "bindings": {
                    "type": "array",
                    "maxItems": 200,
                    "items": {
                      "type": "object",
                      "required": [
                        "binding_type"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "binding_type": {
                          "type": "string",
                          "enum": [
                            "CHECKPOINT",
                            "ROUTE"
                          ]
                        },
                        "tag_id": {
                          "type": "integer"
                        },
                        "route_id": {
                          "type": "integer"
                        },
                        "role_ids": {
                          "type": [
                            "array",
                            "null"
                          ],
                          "maxItems": 50,
                          "items": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "description": "Roles (GET /v1/roles) that see the task at this point. Missing, empty or null = the assignee of the task decides (no assignee = every role)."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: TaskBinding[] }` — the new set."
          },
          "400": {
            "description": "A tag_id/route_id/role_id is not in the tenant."
          },
          "404": {
            "description": "Task not visible for this key."
          }
        }
      }
    },
    "/v1/tasks/{id}/schedule": {
      "get": {
        "summary": "Read the task's schedule (recurrence)",
        "description": "Requires scope `tasks:read`. `{ data: TaskSchedule[] }` — a task carries\nat most one primary plan; an empty list means the task is a one-off.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: TaskSchedule[] }`."
          },
          "404": {
            "description": "Task not visible for this key."
          }
        }
      },
      "put": {
        "summary": "Set the task's schedule (make it recurring, or change it from a date)",
        "description": "Requires scope `tasks:write`. The same path as the portal editor (audit\ntrail, live update, and the tenant's four-eyes change approval when\nenabled: send `change_reason` and expect `ApprovalPending` with HTTP\n200 instead of the plan — nothing is written until approved).\n\nWithout `effective_from`: full replace of the task's single plan; the\nrule versions are reconciled to ONE base version (a planned change is\ndropped, its exceptions removed — see `removed_exceptions`).\n\nWith `effective_from` (YYYY-MM-DD, at least tomorrow in the property's\ntimezone and after `start_date`): \"change the series from that day\" —\na new rule version is appended, occurrences before the day stay as\nthey were, the response reports the planned version in\n`upcoming_change`. Exceptions and completions on days the new rule no\nlonger produces are counted in `removed_exceptions` /\n`orphaned_completions`. Undo with DELETE …/schedule/versions/{versionId}.\n\nA CHECKPOINT-bound task keeps its bindings and becomes due per plan,\ncompleted by scan at the point; a ROUTE-bound task cannot carry an\nactive plan (400). `start_date` is the first due day; `start_time` the\ndue time (HH:mm, property wall clock). `type_freedays`: `none`\n(holidays count as normal days), `disable` (skip holidays), `enabled`\n(holidays only). A holiday rule (`type_freedays` other than `none` or\n`nonworking_rule` other than `skip`) first refreshes the property's\npublic holidays; it needs a property with `country: DE` and a\n`region`, else 422 `PROPERTY_WITHOUT_REGION`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "repeat_type",
                  "start_date"
                ],
                "properties": {
                  "repeat_type": {
                    "type": "string",
                    "enum": [
                      "none",
                      "daily",
                      "weekly",
                      "monthly"
                    ]
                  },
                  "weekdays": {
                    "type": "array",
                    "items": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 6
                    },
                    "description": "0 = Sunday … 6 = Saturday (weekly only). Duplikate werden entfernt, Liste sortiert."
                  },
                  "monthdays": {
                    "type": "array",
                    "items": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 31
                    },
                    "description": "Duplikate werden entfernt, Liste sortiert."
                  },
                  "frequency": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 365,
                    "default": 1,
                    "description": "Every n days/weeks/months."
                  },
                  "start_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "end_date": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date",
                    "description": "Exclusive with occurrence_count."
                  },
                  "occurrence_count": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 1,
                    "maximum": 1000
                  },
                  "start_time": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "end_time": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^\\d{2}:\\d{2}$",
                    "description": "Optional end of the execution window; needs start_time and must be after it (400 otherwise). Omitted = null (full replace)."
                  },
                  "type_freedays": {
                    "type": "string",
                    "enum": [
                      "none",
                      "disable",
                      "enabled"
                    ],
                    "default": "none"
                  },
                  "anchor_mode": {
                    "type": "string",
                    "enum": [
                      "fixed",
                      "completion"
                    ],
                    "default": "fixed"
                  },
                  "window_mode": {
                    "type": "string",
                    "enum": [
                      "none",
                      "days",
                      "month"
                    ],
                    "default": "none"
                  },
                  "tolerance_days": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "maximum": 180
                  },
                  "nonworking_rule": {
                    "type": "string",
                    "enum": [
                      "skip",
                      "prev",
                      "next"
                    ],
                    "default": "skip"
                  },
                  "active": {
                    "type": "boolean",
                    "default": true
                  },
                  "effective_from": {
                    "type": "string",
                    "format": "date",
                    "description": "Change the series from this day (≥ tomorrow in the property's timezone, > start_date). Omit for a full replace."
                  },
                  "change_reason": {
                    "type": "string",
                    "description": "Required when the tenant's change approval covers task schedules."
                  }
                }
              },
              "examples": {
                "fullReplace": {
                  "summary": "Weekly on Wednesdays, whole series",
                  "value": {
                    "repeat_type": "weekly",
                    "weekdays": [
                      3
                    ],
                    "frequency": 1,
                    "start_date": "2026-09-02",
                    "start_time": "08:00",
                    "end_time": "12:00"
                  }
                },
                "fromDate": {
                  "summary": "Fridays from 7 October, Wednesdays stay before",
                  "value": {
                    "repeat_type": "weekly",
                    "weekdays": [
                      5
                    ],
                    "frequency": 1,
                    "start_date": "2026-09-02",
                    "effective_from": "2026-10-07",
                    "change_reason": "Neuer Liefertag"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: TaskSchedule }` incl. `orphaned_completions`,\n`removed_exceptions` and — after a change from a date —\n`upcoming_change`; or `ApprovalPending` when the four-eyes rule\nis active.\n",
            "content": {
              "application/json": {
                "examples": {
                  "fromDate": {
                    "value": {
                      "data": {
                        "schedule_id": 41,
                        "repeat_type": "weekly",
                        "weekdays": [
                          5
                        ],
                        "monthdays": [],
                        "frequency": 1,
                        "start_date": "2026-09-02",
                        "end_date": null,
                        "occurrence_count": null,
                        "start_time": "08:00",
                        "type_freedays": "none",
                        "anchor_mode": "fixed",
                        "window_mode": "none",
                        "tolerance_days": null,
                        "nonworking_rule": "skip",
                        "active": true,
                        "effective_from": "2026-09-02",
                        "upcoming_change": {
                          "version_id": 12,
                          "effective_from": "2026-10-07",
                          "repeat_type": "weekly",
                          "weekdays": [
                            5
                          ],
                          "monthdays": [],
                          "frequency": 1,
                          "start_time": "08:00",
                          "type_freedays": "none",
                          "anchor_mode": "fixed",
                          "window_mode": "none",
                          "tolerance_days": null,
                          "nonworking_rule": "skip"
                        },
                        "orphaned_completions": 0,
                        "removed_exceptions": 1
                      }
                    }
                  },
                  "approvalPending": {
                    "value": {
                      "changed": false,
                      "approval_pending": true,
                      "batch_id": "6f1c…",
                      "entity_type": "task_schedule",
                      "label": "Aufgaben-Rhythmus"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Task is bound to a patrol route (its rhythm wins) or invalid combination."
          },
          "404": {
            "description": "Task not visible for this key."
          },
          "422": {
            "description": "`errorCode: SCHEDULE_EMPTY` — the active plan yields no due date\nfrom today on (e.g. `end_date` in the past, or a yearly 25.12.\nwith `type_freedays: disable`). Nothing is saved.\n`errorCode: PROPERTY_WITHOUT_REGION` — the plan uses a holiday\nrule but the property has no country DE or no region; set them\nand retry. Nothing is saved.\n`errorCode: EFFECTIVE_FROM_TOO_EARLY` — `effective_from` is today\nor earlier (property timezone). `errorCode: CHANGE_REASON_REQUIRED`\n(as `error`) — approval active, no reason given. Other 422s are\nfield validation (`errorCode: UNPROCESSABLE_ENTITY`, e.g.\n`frequency` above 365, `effective_from` not after `start_date`).\n"
          }
        }
      }
    },
    "/v1/tasks/{id}/schedule/versions": {
      "get": {
        "summary": "List the rule versions of the task's series",
        "description": "Requires scope `tasks:read`. All rule versions ascending by\n`effective_from` — the first is the base version. An empty list means\nthe task has no series (or one written before versioning; the next\nPUT creates the base version).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: ScheduleVersion[] }`.",
            "content": {
              "application/json": {
                "example": {
                  "data": [
                    {
                      "version_id": 11,
                      "effective_from": "2026-09-02",
                      "repeat_type": "weekly",
                      "weekdays": [
                        3
                      ],
                      "monthdays": [],
                      "frequency": 1,
                      "start_time": "08:00",
                      "type_freedays": "none",
                      "anchor_mode": "fixed",
                      "window_mode": "none",
                      "tolerance_days": null,
                      "nonworking_rule": "skip"
                    },
                    {
                      "version_id": 12,
                      "effective_from": "2026-10-07",
                      "repeat_type": "weekly",
                      "weekdays": [
                        5
                      ],
                      "monthdays": [],
                      "frequency": 1,
                      "start_time": "08:00",
                      "type_freedays": "none",
                      "anchor_mode": "fixed",
                      "window_mode": "none",
                      "tolerance_days": null,
                      "nonworking_rule": "skip"
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Task not visible for this key."
          }
        }
      }
    },
    "/v1/tasks/{id}/schedule/versions/{versionId}": {
      "delete": {
        "summary": "Discard a planned rule change (undo \"change from a date\")",
        "description": "Requires scope `tasks:write`. Only a version whose `effective_from` is\nstill in the future can be discarded; the base version and versions\nalready in force stay. Exceptions that the version had orphaned are\nrestored (`restored_exceptions`); exceptions that only existed under\nthe discarded rule are removed (`removed_exceptions`). Subject to the\nfour-eyes change approval like PUT schedule (`change_reason` in the\nbody or `X-Change-Reason` header → `ApprovalPending`).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "versionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "change_reason": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { version_id, effective_from, removed_exceptions, restored_exceptions, upcoming_change: ScheduleVersion | null } }`, or `ApprovalPending`.",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "version_id": 12,
                    "effective_from": "2026-10-07",
                    "removed_exceptions": 0,
                    "restored_exceptions": 1,
                    "upcoming_change": null
                  }
                }
              }
            }
          },
          "404": {
            "description": "Task not visible for this key, or `errorCode: VERSION_NOT_FOUND`."
          },
          "422": {
            "description": "`errorCode: VERSION_IS_BASE` (the first version) or `VERSION_NOT_FUTURE` (already in force)."
          }
        }
      }
    },
    "/v1/tasks/{id}/occurrences/exceptions": {
      "get": {
        "summary": "List the live per-occurrence exceptions of the task's series",
        "description": "Requires scope `tasks:read`. Every exception that is currently in\neffect (skipped or moved occurrences), ascending by `original_date`.\nUndone exceptions are not listed.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: OccurrenceException[] }`.",
            "content": {
              "application/json": {
                "example": {
                  "data": [
                    {
                      "original_date": "2026-09-30",
                      "action": "move",
                      "new_date": "2026-10-02",
                      "new_time": "09:30",
                      "reason": "Lieferung",
                      "created_at": "2026-09-26T10:12:00.000Z"
                    },
                    {
                      "original_date": "2026-10-14",
                      "action": "skip",
                      "new_date": null,
                      "new_time": null,
                      "reason": null,
                      "created_at": "2026-09-26T10:13:00.000Z"
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Task not visible for this key."
          }
        }
      }
    },
    "/v1/tasks/{id}/occurrences/{date}/exception": {
      "post": {
        "summary": "Skip or move ONE occurrence of the series",
        "description": "Requires scope `tasks:write`. `{date}` is the occurrence key = the due\nday the rule produces (YYYY-MM-DD) — not the day a moved occurrence is\ncurrently shown on. `skip` drops the occurrence, `move` shows it on\n`new_date` (optional `new_time` HH:mm). Only occurrences from today on\n(property timezone) can be changed; a completed or reported occurrence\ncannot; the target day must not already carry an occurrence of the\nsame series. Posting again for the same key replaces the exception\n(a moved occurrence may move on, also back to its original day). The\ntask history and the config audit trail get an entry. Subject to the\nfour-eyes change approval like PUT schedule (`change_reason` →\n`ApprovalPending`; impossible requests are rejected BEFORE an approval\nrequest is filed).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "date",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "action"
                ],
                "properties": {
                  "action": {
                    "type": "string",
                    "enum": [
                      "skip",
                      "move"
                    ]
                  },
                  "new_date": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date",
                    "description": "Required for `move`, forbidden for `skip`."
                  },
                  "new_time": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^\\d{2}:\\d{2}$",
                    "description": "Optional for `move`."
                  },
                  "reason": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 500
                  },
                  "change_reason": {
                    "type": "string",
                    "description": "Required when the tenant's change approval covers task schedules."
                  }
                }
              },
              "examples": {
                "move": {
                  "value": {
                    "action": "move",
                    "new_date": "2026-10-02",
                    "new_time": "09:30",
                    "reason": "Lieferung"
                  }
                },
                "skip": {
                  "value": {
                    "action": "skip",
                    "reason": "Feiertag im Haus"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { original_date, action, new_date, new_time } }`, or `ApprovalPending`.",
            "content": {
              "application/json": {
                "example": {
                  "data": {
                    "original_date": "2026-09-30",
                    "action": "move",
                    "new_date": "2026-10-02",
                    "new_time": "09:30"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Task not visible for this key."
          },
          "409": {
            "description": "`errorCode: OCCURRENCE_TARGET_TAKEN` (`new_date` already carries an occurrence of this series) or `OCCURRENCE_DONE` (the occurrence is completed or reported)."
          },
          "422": {
            "description": "`errorCode: NO_SERIES` (task has no active series),\n`OCCURRENCE_IN_PAST` (`{date}` before today), `MOVE_TARGET_IN_PAST`\n(`new_date` before today), `MOVE_TIME_AFTER_END` (`new_time` is not\nbefore the series' `end_time` on that day), `NOT_AN_OCCURRENCE`\n(`{date}` is not a due day of the series). Field validation: `UNPROCESSABLE_ENTITY`.\n"
          }
        }
      },
      "delete": {
        "summary": "Undo the exception of ONE occurrence",
        "description": "Requires scope `tasks:write`. Removes the live exception for the\noccurrence key `{date}` — a moved occurrence returns to its original\nday, a skipped one is due again. Subject to the four-eyes change\napproval like PUT schedule (`change_reason` in the body or\n`X-Change-Reason` header → `ApprovalPending`).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "date",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "change_reason": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { original_date, removed: true } }`, or `ApprovalPending`."
          },
          "404": {
            "description": "Task not visible for this key, or `errorCode: EXCEPTION_NOT_FOUND` (no live exception for that key)."
          }
        }
      }
    },
    "/v1/task-states": {
      "get": {
        "summary": "List the tenant's board states (columns)",
        "description": "Requires scope `tasks:read`. The `state_id` catalogue for\nPOST /v1/tasks/{id}/state, in board order (`index`). `title` carries\nthe completion semantics the server matches on.\n",
        "responses": {
          "200": {
            "description": "`{ data: [{state_id, title, index}] }`."
          }
        }
      }
    },
    "/v1/incidents": {
      "get": {
        "summary": "List incidents (defect reports)",
        "description": "Requires scope `incidents:read`. The read counterpart to the\ncreate-only POST — lets an integrator poll the reports it (or staff)\nraised. `from`/`to` filter on the event `timestamp`. AI\nclassification internals and photo/audio attachments are not\nexposed; `severity`/`category_id` are included once classified.\nProperty-restricted keys only see incidents on accessible properties.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "category_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "severity",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "low",
                "medium",
                "high",
                "critical"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "open = neither acknowledged nor closed; acknowledged = acknowledged, not closed; closed = closed.",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "acknowledged",
                "closed"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [Incident], total, page, pageSize }`, newest first.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Incident"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "pageSize": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create an incident (defect report)",
        "description": "Requires scope `incidents:write`. Incidents created here carry\n`source: \"api\"` (app-created incidents carry `\"device\"`), so the\nprovenance stays distinguishable in reads and exports. `timestamp`\nsets the event time (imports of past reports); omitted = now. A\ntimestamp in the future answers 422.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "property_id",
                  "text"
                ],
                "additionalProperties": false,
                "properties": {
                  "property_id": {
                    "type": "integer"
                  },
                  "text": {
                    "type": "string"
                  },
                  "lat": {
                    "type": "number"
                  },
                  "lng": {
                    "type": "number"
                  },
                  "timestamp": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Event time (ISO 8601). Omitted = time of the call. Must not lie in the future."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created incident id."
          }
        }
      }
    },
    "/v1/incidents/{id}": {
      "get": {
        "summary": "Get an incident",
        "description": "Requires scope `incidents:read`. `id` is the numeric `incident_id`\nreturned by POST /v1/incidents. Same property scoping as the list.\n`linked_task_uuid` is the task created from this incident — only\nwhen the key may see that task, else null.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: Incident + {linked_task_uuid} }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/Incident"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "linked_task_uuid": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "format": "uuid"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Incident not visible for this key (unknown, other tenant, outside the property restriction — indistinguishable)."
          }
        }
      }
    },
    "/v1/incidents/{id}/acknowledge": {
      "post": {
        "summary": "Acknowledge an incident",
        "description": "Requires scope `incidents:write`. Empty body. Stops escalations.\nAlready acknowledged → `changed: false`, nothing written. Archived\nincident → 409 `reason: RECORD_ARCHIVED`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: IncidentStatusChange }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/IncidentStatusChange"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Incident not visible for this key."
          },
          "409": {
            "description": "`reason: RECORD_ARCHIVED`"
          }
        }
      }
    },
    "/v1/incidents/{id}/close": {
      "post": {
        "summary": "Close an incident",
        "description": "Requires scope `incidents:write`. Empty body. Acknowledges as well\nwhen that is still missing. Already closed → `changed: false`.\nArchived → 409 `reason: RECORD_ARCHIVED`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: IncidentStatusChange }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/IncidentStatusChange"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Incident not visible for this key."
          },
          "409": {
            "description": "`reason: RECORD_ARCHIVED`"
          }
        }
      }
    },
    "/v1/incidents/{id}/reopen": {
      "post": {
        "summary": "Reopen a closed incident",
        "description": "Requires scope `incidents:write`. Empty body. Lifts ONLY the closing —\nthe acknowledgement stays, the incident is `acknowledged` afterwards.\nNot closed → `changed: false`. Archived → 409 `reason: RECORD_ARCHIVED`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: IncidentStatusChange }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/IncidentStatusChange"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Incident not visible for this key."
          },
          "409": {
            "description": "`reason: RECORD_ARCHIVED`"
          }
        }
      }
    },
    "/v1/incidents/{id}/classification": {
      "patch": {
        "summary": "Set category and/or severity of an incident",
        "description": "Requires scope `incidents:write`. At least one of `category_id`\n(null clears; ids from GET /v1/incident-categories, archived or\nforeign category → 404) and `severity`. Only fields that really\nchange are written; values already set are listed in `unchanged`.\nRe-classifying a HUMAN classification needs a `change_reason`\n(body field or `X-Change-Reason` header) — otherwise 422\n`reason: REASON_REQUIRED`. When the tenant requires approval for\nincident corrections, the re-classification becomes an approval\nrequest instead (ApprovalPending, nothing written); a second request\nwhile one is open → 409 `reason: REQUEST_PENDING`. Archived → 409\n`reason: RECORD_ARCHIVED`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "category_id": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "severity": {
                    "type": "string",
                    "enum": [
                      "low",
                      "medium",
                      "high",
                      "critical"
                    ]
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Applied: `{ changed, changes: [{field, before, after,\nbefore_name?, after_name?}], unchanged: [field], data: Incident }`.\nOr ApprovalPending (`entity_type: incident_log`).\n",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "changed": {
                          "type": "boolean"
                        },
                        "changes": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        },
                        "unchanged": {
                          "type": "array",
                          "items": {
                            "type": "string",
                            "enum": [
                              "category_id",
                              "severity"
                            ]
                          }
                        },
                        "data": {
                          "$ref": "#/components/schemas/Incident"
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/ApprovalPending"
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Incident or category not visible for this key."
          },
          "409": {
            "description": "`reason: RECORD_ARCHIVED` or `REQUEST_PENDING`"
          },
          "422": {
            "description": "Validation error, or `reason: REASON_REQUIRED`"
          }
        }
      }
    },
    "/v1/incidents/{id}/task": {
      "post": {
        "summary": "Create the task for an incident",
        "description": "Requires scope `tasks:write` and the role rights Create Task + Read\nIncident. One task per incident: a repeated call returns the\nexisting task with `created: false` (HTTP 200). Title and description\ndefault to the incident. `assignee_id` must be an active account of\nthe tenant (400). Archived incident → 409 `reason: RECORD_ARCHIVED`.\nCreating needs no change reason (initial creation), even when the\ntenant requires reasons for changes; a `change_reason` given anyway\n(body or `X-Change-Reason` header) is stored with the task's\n`created` row in the configuration audit trail.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 500
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 10000
                  },
                  "priority": {
                    "type": "string",
                    "enum": [
                      "HIGH",
                      "MEDIUM",
                      "LOW"
                    ]
                  },
                  "assignee_id": {
                    "type": "integer"
                  },
                  "due_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "due_time": {
                    "type": "string",
                    "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
                    "description": "HH:mm; requires due_date."
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Optional. Creating needs no reason; when given, it is stored with the created row (alternatively header X-Change-Reason)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The incident already had a task — `created: false`, same shape."
          },
          "201": {
            "description": "`{ data: {task_uuid, task_id, created: true, title, property_id, incident_id} }`"
          },
          "404": {
            "description": "Incident not visible for this key."
          },
          "409": {
            "description": "`reason: RECORD_ARCHIVED`"
          },
          "422": {
            "$ref": "#/components/responses/ChangeReasonRequired"
          }
        }
      }
    },
    "/v1/incident-categories": {
      "get": {
        "summary": "List the tenant's incident categories",
        "description": "Requires scope `incidents:read`. Read-only: a tenant that never\nopened the category list in the portal may have none yet (empty list).\n",
        "parameters": [
          {
            "name": "include_archived",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{category_id, name, description, is_system, archived}] }`"
          }
        }
      }
    },
    "/v1/form-responses": {
      "get": {
        "summary": "List form responses (\"cleaning checklist submitted\" polling)",
        "description": "Requires scope `form_responses:read`. Poll with `status=submitted` and\na `property_id` to detect finished checklists.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "template_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "submitted"
              ]
            }
          },
          {
            "name": "has_defect",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged summaries.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/FormResponseSummary"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/form-responses/open-defects": {
      "get": {
        "summary": "Open defects reported in submitted forms",
        "description": "Requires scope `form_responses:read`. Every defect signal\n(`ok_defect` = defect, or a configured workflow signal of type\n`defect`) of submitted, not archived or superseded responses that has\nnot been carried over yet, newest first. The service caps at 500\nresponses; the page is cut from that set. Property-restricted keys\nonly see their properties; `property_id` outside the restriction →\n403. No field ids, paths or photos — the field label, its value and\nthe response id (`GET /v1/form-responses/{id}` for the rest).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "within_days",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 365,
              "default": 90
            }
          },
          {
            "name": "template_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{source_response_id, template_id, template_name,\nproperty_id, captured_at, label, value, signal_type}], total,\npage, pageSize }`\n"
          }
        }
      }
    },
    "/v1/form-responses/compare": {
      "get": {
        "summary": "Compare two submitted form responses (e.g. move-in vs. move-out)",
        "description": "Requires scope `form_responses:read`. Both responses must be\nsubmitted and not cancelled/archived/superseded; the older one is\nalways `left`. Fields are matched by id, then by equal label and\ntype; the rest lands in `unmatched`. Verdicts per row: `new`,\n`preexisting`, `fixed` (ok/defect fields), `changed`, `unchanged`,\n`not_rated`; `delta` for numbers. No media, signatures or\ncoordinates. Person fields and the filler's name appear only for keys\nwith `VIEW_TIME_TRACKING_OTHERS` (or the Update right on time\ntracking). Unknown, foreign, hidden (property restriction) and not\ncomparable responses all answer 404; `a` = `b` → 422.\n",
        "parameters": [
          {
            "name": "a",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "b",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { left: {id, template_id, template_name,\ntemplate_version, property_id, property_name, submitted_at,\nhas_defect, account_name}, right: {…}, same_template,\ndifferences: [{field_id, label, type, left: {value, note}, right:\n{value, note}, verdict, delta}], unmatched: [{side, field_id,\nlabel, type, value, note}], summary: {new, preexisting, fixed,\nunchanged, changed, notRated} } }`\n"
          },
          "404": {
            "description": "Not found or not comparable."
          }
        }
      }
    },
    "/v1/form-responses/{id}": {
      "get": {
        "summary": "Form response detail (answers + presigned media URLs)",
        "description": "Requires scope `form_responses:read`. `signature` is the submitter's\nelectronic signature (latest manifest with meaning `completion` or\n`submission`), `null` when the response carries none. Its `status` is\nthe derived state the portal shows: `signed`, `signed_v1`,\n`signed_no_hash`, `rejected`, `missing`, `modified`, `cancelled`,\n`superseded`. A `rejected` signature means the response is not a\nvalid proof; `failure_reason` carries the code (e.g. `grant_invalid`,\n`pin_mismatch`). `signed_at` is the time on the device, `received_at`\nthe time the server received it. `task_completions` lists the task\ncompletions this response booked (cancelled ones included, flag\n`cancelled`); it is only present for keys that also hold\n`tasks:read`. `linked_task` is unrelated to completions: it is a\nfollow-up task CREATED from the response. `checkpoint_name` is the\nname of the control point the form was filled in at (`tag_id`), `null`\nwithout one. `completed_without_scan` on a completion is `true` when\na task that requires the control point scan was completed without it.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Full response including answers and media links, plus\n`signature: { status, signer_name, signer_username, signer_role,\nmeaning, signed_at, received_at, method, hash, hash_version,\nfailure_reason } | null` and (with `tasks:read`)\n`task_completions: [{ completion_id, task_uuid, task_title,\noccurrence_date, completed_at, completed_without_scan,\ncancelled }]`, and `checkpoint_name`, plus the proof status\n`proof_invalid: boolean` and `proof_reason: 'signature_rejected' |\n'signature_missing' | 'completion_cancelled' | null`: the same rule the portal uses to lock\napproval and customer sending (no verified signature of the submitter,\nbut a rejected one, or a required one is missing; or every task\ncompletion recorded with the response has been cancelled). Also\n`bridge_outcome` (how the response was booked as a task completion:\n`completed`, `no_candidate`, `already_completed`, `target_not_found`,\n`target_wrong_template`, `target_closed`, `target_already_completed`,\n`scan_required`, `failed`; `null` for responses submitted before this\nfield existed) and `completion_missing` (`target_not_found` |\n`target_wrong_template` | `target_closed` | `scan_required` | `failed` |\n`null`): a completion was expected but none exists. Informational\nonly, it does not block approval or sending. Capture time:\n`client_created_at` (time on the device when the response was last\nsaved there; `null` when no device time is on record) and\n`device_time_status` (`missing`: the response came from a device\nwithout a device time; `unreadable`: the device sent a time that\ncould not be read; `null`: a device time is present, the response\ndid not come from a device, or it was submitted before this field\nexisted). With `missing` or `unreadable` only the server time of\nreceipt (`received_at`) applies.\n"
          }
        }
      }
    },
    "/v1/material/items": {
      "get": {
        "summary": "List material items (master data)",
        "description": "Requires scope `material:read`. All `/v1/material/*` endpoints\nadditionally require the tenant's material module to be enabled\n(company setting `material_enabled`); when the module is off they\nrespond `403 Forbidden`. Note: material endpoints also return\ndata for properties whose app UI has the material module hidden —\n`show_material` is a pure display flag, not an access gate.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "consumable",
                "equipment",
                "serialized"
              ]
            }
          },
          {
            "name": "barcode",
            "in": "query",
            "description": "Exact manufacturer barcode (the value a scanner reads). Returns\nthe one item that carries it, or an empty list. Combine with\n`status=archived` to look among archived items.\n",
            "schema": {
              "type": "string",
              "maxLength": 80
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "archived"
              ],
              "default": "active"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged item list."
          }
        }
      },
      "post": {
        "summary": "Create a material item (ERP master-data sync)",
        "description": "Requires scope `material:write`. Slim public field set (name, unit,\ncategory, size, kind, unit_price_cents, barcodes) — photos/custom\nfields stay portal-only. Duplicate names answer 409.\n\n`barcodes` is the full list of the item's manufacturer barcodes.\nA barcode that already belongs to another active item answers 409\nwith `reason: material_barcode_taken` and that item (`item_id`,\n`item_name`); a barcode of an archived item moves to the new item.\n",
        "responses": {
          "201": {
            "description": "Created item."
          },
          "409": {
            "description": "An item with this name already exists, or a barcode belongs to\nanother active item (`reason: material_barcode_taken`).\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MaterialItem"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/material/items/{id}": {
      "get": {
        "summary": "Material item detail",
        "description": "Requires scope `material:read`.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The item."
          }
        }
      },
      "patch": {
        "summary": "Update a material item",
        "description": "Requires scope `material:write`. Same slim field set as create\n(minus `kind` — an item's kind is immutable via the public API).\n`barcodes` replaces the item's list (`[]` removes all); when the\nfield is omitted the barcodes stay as they are. A barcode of another\nactive item answers 409 (`reason: material_barcode_taken`).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated item."
          }
        }
      }
    },
    "/v1/material/items/{id}/archive": {
      "post": {
        "summary": "Archive an item (soft — stock/history stay readable)",
        "description": "Requires scope `material:write`.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { archived: true } }`."
          }
        }
      }
    },
    "/v1/material/items/{id}/unarchive": {
      "post": {
        "summary": "Restore an archived item",
        "description": "Requires scope `material:write`.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { archived: false } }`."
          },
          "404": {
            "description": "Item not found."
          },
          "409": {
            "description": "An active item with the same name and size already exists. Rename or archive it first."
          }
        }
      }
    },
    "/v1/material/stock": {
      "get": {
        "summary": "Stock levels of one property",
        "description": "Requires scope `material:read`. `property_id` is mandatory.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "property_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged stock rows.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MaterialStockRow"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/material/warehouse/stock": {
      "get": {
        "summary": "Stock levels of a central warehouse",
        "description": "Requires scope `material:read` AND a key account with tenant-wide\nvisibility (relation \"global\") — the warehouse has no property\ncontext. Without `warehouse_id` the tenant's default warehouse is\nused; an unknown/foreign id yields 404.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "warehouse_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "archived"
              ],
              "default": "active"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged stock rows."
          }
        }
      }
    },
    "/v1/material/movements": {
      "get": {
        "summary": "List stock movements of one property (journal polling)",
        "description": "Requires scope `material:read`. `property_id` is mandatory.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "property_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "item_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged movements, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MaterialMovement"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Book stock movements (adjustments, deliveries, consumption)",
        "description": "Requires scope `material:write`. Batch of up to 200 rows. Pass a\nclient-generated `uuid` per row to make retries idempotent\n(`ON CONFLICT DO NOTHING` — redelivery creates no duplicate booking;\nduplicates are reported in `duplicate_uuids`). The unit price is\nALWAYS stamped server-side from the item master — a client-supplied\n`unit_price_cents` is rejected (422). Bookings are recorded with\nsource \"portal\". Below-minimum alerts (automations) fire exactly like\nfor portal/app bookings.\n\nSign rules (enforced, 422 validation error on violation): stock\nDECREASES (`consume`, `issue`, `loss`) require a NEGATIVE `qty`;\nstock INCREASES (`refill`, `delivery`, `return`) require a POSITIVE\n`qty`; `correction` accepts both directions (stock-count\ndifferences). Serialized items (per-unit tracked, e.g. keys) cannot\nbe booked as quantity movements — such rows answer 400 with the\noffending item ids. In both cases nothing of the batch is booked.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "movements"
                ],
                "additionalProperties": false,
                "properties": {
                  "movements": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 200,
                    "items": {
                      "type": "object",
                      "required": [
                        "item_id",
                        "property_id",
                        "qty",
                        "reason",
                        "occurred_at"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "uuid": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "item_id": {
                          "type": "integer"
                        },
                        "property_id": {
                          "type": "integer"
                        },
                        "qty": {
                          "type": "number",
                          "description": "≠ 0; sign must match reason (refill/delivery/return > 0, consume/loss/issue < 0, correction ±); max 3 decimals"
                        },
                        "reason": {
                          "type": "string",
                          "enum": [
                            "refill",
                            "consume",
                            "delivery",
                            "correction",
                            "issue",
                            "return",
                            "loss"
                          ]
                        },
                        "occurred_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "note": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Inserted + duplicate uuids.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "inserted_uuids": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "duplicate_uuids": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Serialized item booked as quantity movement (item ids in the message)."
          },
          "422": {
            "description": "Qty sign not matching the reason, or unknown material item id(s)."
          }
        }
      }
    },
    "/v1/material/requests": {
      "get": {
        "summary": "List material requests (status polling for ERP/purchasing)",
        "description": "Requires scope `material:read`. The read counterpart to the\ncreate-only POST — status lifecycle: `pending` →\n`approved`/`rejected` (decision) → `fulfilled` (books refill to the\nproperty plus consume in the source warehouse), or `cancelled`\n(requester withdrawal). `from`/`to` filter on creation date with day\nedges in the account timezone. Property-restricted keys only see\nrequests of accessible properties.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "approved",
                "rejected",
                "cancelled",
                "fulfilled"
              ]
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "item_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{uuid, property_id, status, note,\nrequested_by_account_id, requester_name, decided_by, decided_at,\nreject_reason, fulfilled_by, fulfilled_at, source_warehouse_id,\ncreated_at, items: [{item_id, name, unit, qty}]}], total }`\n"
          }
        }
      },
      "post": {
        "summary": "Create a material request for a property",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKeyUuid"
          }
        ],
        "description": "Requires scope `material:write`. `uuid` is MANDATORY (idempotency\nanchor): the first call answers 201, a retry with the same uuid\nanswers 200 with `duplicate: true`. The request enters the tenant's\napproval inbox and fires the `material.request_created` automation\ntrigger.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "uuid",
                  "property_id",
                  "items"
                ],
                "additionalProperties": false,
                "properties": {
                  "uuid": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "property_id": {
                    "type": "integer"
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 100,
                    "items": {
                      "type": "object",
                      "required": [
                        "item_id",
                        "qty"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "item_id": {
                          "type": "integer"
                        },
                        "qty": {
                          "type": "number",
                          "description": "> 0; max 3 decimals"
                        }
                      }
                    }
                  },
                  "note": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Idempotent replay of an already-known uuid (`duplicate: true`)."
          },
          "201": {
            "description": "Created request (uuid, status, property_id, created_at)."
          },
          "422": {
            "description": "Unknown material item id(s), or a serialized item in the request (unit-tracked items are handed over via transfers, not requests)."
          }
        }
      }
    },
    "/v1/material/requests/{id}": {
      "get": {
        "summary": "Get a material request",
        "description": "Requires scope `material:read`. `id` is the request uuid (as sent to\nor returned by POST). Same property scoping as the list (404 outside\nthe key's property scope).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Request detail (same shape as the list rows)."
          }
        }
      }
    },
    "/v1/material/requests/{id}/approve": {
      "post": {
        "summary": "Approve a pending material request",
        "description": "Requires scope `material:write` plus a role with the material\napproval gate (mirrors the portal approval inbox). Optional\n`warehouse_id` pre-selects the fulfilment source warehouse\n(multi-warehouse) — an unknown warehouse answers 404, one not\nvisible for the key's account 403. Only `pending` requests:\nanything else answers 409 with the current status.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: request }` (status approved)."
          },
          "409": {
            "description": "Not pending (stale list)."
          }
        }
      }
    },
    "/v1/material/requests/{id}/reject": {
      "post": {
        "summary": "Reject a pending material request",
        "description": "Requires scope `material:write` plus the approval gate. Optional\n`reason` (max 500 chars) is stored as reject_reason. Only `pending`\nrequests; otherwise 409.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: request }` (status rejected)."
          },
          "409": {
            "description": "Not pending."
          }
        }
      }
    },
    "/v1/material/requests/{id}/fulfill": {
      "post": {
        "summary": "Fulfil an approved request (books both stock sides)",
        "description": "Requires scope `material:write` plus the approval gate. Atomically\nflips `approved` → `fulfilled` and books per position a refill\nmovement to the property AND a consume movement in the source\nwarehouse (cascade: explicit `warehouse_id` > approval disposition >\nproperty default > tenant main warehouse), anchored via\n`ref_type='material_request'`. An unknown explicit warehouse answers\n404, one not visible for the key's account 403. Idempotent — a second\nfulfil answers 409 and never double-books. `occurred_at` optional\n(default now).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: request }` (status fulfilled)."
          },
          "409": {
            "description": "Not approved (or already fulfilled)."
          },
          "422": {
            "description": "Explicitly chosen warehouse unknown, or the request contains a serialized item (created before the guard) and cannot be fulfilled as a quantity booking."
          }
        }
      }
    },
    "/v1/material/requests/{id}/cancel": {
      "post": {
        "summary": "Withdraw an own pending request",
        "description": "Requires scope `material:write`. Only the creator (the key account)\ncan withdraw, and only while `pending` — otherwise 409. POST, not\nDELETE: the withdrawal is a status transition (audit row remains).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: request }` (status cancelled)."
          },
          "409": {
            "description": "Not pending or not the creator."
          }
        }
      }
    },
    "/v1/material/stock-targets": {
      "get": {
        "summary": "Read min/target stock per property",
        "description": "Requires scope `material:read`.",
        "parameters": [
          {
            "name": "property_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{item_id, min_qty, target_qty}] }`."
          }
        }
      },
      "put": {
        "summary": "Set min/target stock per property (full replace)",
        "description": "Requires scope `material:write`. Full-replace contract (mirror of the\nportal): items not listed lose their entry. Feeds the stock traffic\nlight (`low`/`empty`). Unknown item_ids answer 422.\n",
        "responses": {
          "200": {
            "description": "Stored targets."
          }
        }
      }
    },
    "/v1/material/counts": {
      "post": {
        "summary": "Record a stock count (inventory anchor)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKeyUuid"
          }
        ],
        "description": "Requires scope `material:write`. Sets the property's count anchor —\nstock = counted_qty plus movements after `counted_at`. Idempotent\nvia client `uuid` (replay answers 200 instead of 201). A count can\nalso trip the below-minimum alarm.\n",
        "responses": {
          "200": {
            "description": "Replay of a known uuid (`inserted: false`)."
          },
          "201": {
            "description": "`{ data: { inserted: true } }`."
          }
        }
      }
    },
    "/v1/material/warehouses": {
      "get": {
        "summary": "List warehouses (central stock)",
        "description": "Requires scope `material:read` and a key account with GLOBAL\nrelation. Respects per-account warehouse visibility.\n",
        "parameters": [
          {
            "name": "include_archived",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{warehouse_id, name, is_default, archived, note}] }`."
          }
        }
      },
      "post": {
        "summary": "Create a warehouse",
        "description": "Requires scope `material:write` + GLOBAL relation. Duplicate names\nanswer 409.\n",
        "responses": {
          "201": {
            "description": "Created warehouse."
          },
          "409": {
            "description": "Name already exists."
          }
        }
      }
    },
    "/v1/material/warehouse/movements": {
      "post": {
        "summary": "Book central-stock movements (goods receipt, withdrawal)",
        "description": "Requires scope `material:write` + GLOBAL relation. Reasons:\n`delivery` (+), `consume` (−), `correction` (±) — the qty sign is\nENFORCED per reason. `warehouse_id` optional (default warehouse).\nIdempotent via client uuid per row.\n",
        "responses": {
          "201": {
            "description": "`{ data: { inserted_uuids, duplicate_uuids } }`."
          }
        }
      }
    },
    "/v1/material/units": {
      "get": {
        "summary": "List units (serialized items — keys, devices)",
        "description": "Requires scope `material:read`. Answers \"who holds which key\":\n`holder_type`/`holder_id`/`holder_name` is the current holder,\n`status` is derived (available/issued/lost/retired). Filters:\nitem_id, account_id (units held by a person), search\n(serial/item name), status active|archived.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "item_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "archived"
              ],
              "default": "active"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{unit_id, uuid, item_id, item_name, serial_no,\nchip_id, holder_type, holder_id, holder_name, status, note,\ncreated_at}], total }`\n"
          }
        }
      },
      "post": {
        "summary": "Create a unit (key/device instance)",
        "description": "Requires scope `material:write`. The item must be `serialized`\n(422 otherwise); duplicate serial_no per item or chip_id per tenant\nanswers 409.\n",
        "responses": {
          "201": {
            "description": "Created unit."
          }
        }
      }
    },
    "/v1/material/units/{id}": {
      "get": {
        "summary": "Unit detail incl. hand-over history",
        "description": "Requires scope `material:read`. Same fields as the list row plus\n`history`: the unit's movement trail (newest first, capped at 200) —\neach entry with qty/reason, occurred_at, the holder it was booked\nto/from (person or property, with name), the acting user and the\n`transfer_uuid`/`receipt_id` references of the documented hand-over.\nRetired units stay resolvable.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { …unit…, history: [...] } }`."
          },
          "404": {
            "description": "Unit not found in this tenant."
          }
        }
      }
    },
    "/v1/material/units/bulk": {
      "post": {
        "summary": "Create a series of units (e.g. keys SCHL-001…020)",
        "description": "Requires scope `material:write`. Partial success is the contract —\nduplicates come back as a conflicts list in the 201 response.\n",
        "responses": {
          "201": {
            "description": "`{ data: { created: [{unit_id, serial_no}], conflicts } }`."
          }
        }
      }
    },
    "/v1/material/receipts": {
      "get": {
        "summary": "List hand-over receipts (issue/return documents)",
        "description": "Requires scope `material:read`. The signed hand-over documents\ncreated by the app/portal issue-return flow. `signed` is the\nsignature STATUS (with `signer_name`/`signed_at`); the signature\nimage itself stays internal. `line_count` is the number of item\npositions. Filter: `account_id` (receiving person).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{receipt_id, uuid, account_id, account_name,\nissued_by_account_id, issued_by_name, kind, signed,\nsigner_name, signed_at, note, line_count, created_at}],\ntotal }`\n"
          }
        }
      }
    },
    "/v1/material/receipts/{id}": {
      "get": {
        "summary": "Receipt detail incl. item positions",
        "description": "Requires scope `material:read`. `{id}` is the receipt `uuid` (as\nreturned by the list and referenced from unit histories via\n`receipt_id`). `lines` are the receiver-side positions — for\n`return` receipts the outgoing lines of the account: item, unit\nof measure, qty, serial_no (serialized items), unit_price_cents.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { …receipt…, lines: [...] } }`."
          },
          "404": {
            "description": "Receipt not found in this tenant."
          }
        }
      }
    },
    "/v1/material/transfers": {
      "post": {
        "summary": "Issue/return/report loss to persons (key handover)",
        "description": "Requires scope `material:write`. The documented handover trail of\nthe industry: `issue` (to an account), `return` (from an account),\n`loss` (from an account, no target). qty is ALWAYS positive — the\nserver writes the signed journal lines (source −q, target +q,\natomic). Serialized items require `unit_uuid` (qty 1); the unit\nprojection then answers \"who holds which key\". Stale source holders\nare still booked but flagged in `conflicts` (append-only journal).\nClient `uuid` per transfer makes retries idempotent. Account\nreferences outside the tenant answer 404, property references\noutside the key's scope 403. Booking OUT of a foreign account\n(source account ≠ the key's own) additionally requires a role with\nmaterial update rights (`UPDATE_MATERIALS`) — 403 otherwise.\nUnknown unit uuids/warehouses answer 404, invalid transfers\n(serialized item without unit, unit-item mismatch, retired unit) 422.\n",
        "responses": {
          "201": {
            "description": "`{ data: { inserted_uuids, duplicate_uuids, conflicts } }`."
          }
        }
      }
    },
    "/v1/roles": {
      "get": {
        "summary": "List roles (id, name, type, hierarchy, person_scope)",
        "description": "Requires scope `roles:read`. `person_scope` is `below_level` (sees\npersons below its own level) or `own_only` (subcontractor: sees only\naccounts it owns).\n",
        "responses": {
          "200": {
            "description": "Full role list of the tenant."
          }
        }
      },
      "post": {
        "summary": "Create a custom role",
        "description": "Requires scope `roles:write`. `permissions` is a list of permission\ncodes (same catalog as the portal role editor). `hierarchy` (1–99)\nmust be strictly below the level of the key's bound account.\n`person_scope` (default `below_level`) sets person visibility;\n`own_only` marks a subcontractor role. A key bound to an `own_only`\naccount can only create `own_only` roles.\nSubject to the tenant's four-eyes change approval (entity type\n`role`): send `change_reason` (body or `X-Change-Reason` header, else\n422 `CHANGE_REASON_REQUIRED`) and expect `ApprovalPending` with HTTP\n200 — the role is created once the request is approved in the portal.\nA role that carries the approval permission (`ARCHIVE_APPROVE`) is\nALWAYS subject to approval, even when the tenant has not enabled it\nfor roles.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "permissions"
                ],
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "permissions": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "hierarchy": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 99
                  },
                  "person_scope": {
                    "type": "string",
                    "enum": [
                      "below_level",
                      "own_only"
                    ]
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Reason for the change approval (alternatively header `X-Change-Reason`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`ApprovalPending` — nothing written yet, an approval request was filed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApprovalPending"
                },
                "examples": {
                  "approvalPending": {
                    "value": {
                      "changed": false,
                      "approval_pending": true,
                      "batch_id": "6f1c…",
                      "entity_type": "role",
                      "label": "Rolle"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Created role (role_id, name, hierarchy, person_scope)."
          },
          "409": {
            "description": "Role name already exists, or an approval request for a role of this name is still open (`REQUEST_PENDING`)."
          },
          "422": {
            "description": "Validation failed, or `CHANGE_REASON_REQUIRED` (change approval active, no reason given)."
          }
        }
      }
    },
    "/v1/accounts": {
      "get": {
        "summary": "List employee accounts",
        "description": "Requires scope `accounts:read`. The list follows the key account's\nperson scope: a key of a subcontractor account (role `own_only`)\nonly sees itself and its own employees — the same rule as\n`GET /v1/accounts/{id}`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "role_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "archived",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "custom_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact personnel-number match — maps payroll/PMS employee ids to account_ids."
          }
        ],
        "responses": {
          "200": {
            "description": "Paged account list (account_id, name, username, custom_id, role)."
          }
        }
      },
      "post": {
        "summary": "Create an employee account",
        "description": "Requires scope `accounts:write`. Counts against the tenant's seat cap\n(403 SEAT_LIMIT_EXCEEDED beyond it). The new account's role must be\nstrictly below the key account's own hierarchy level. Without\n`username`/`password` random credentials are generated — follow up\nwith `POST /v1/accounts/{id}/invite-link` so the employee sets their\nown password. Empty `property_ids` = tenant-wide visibility (global).\nCreating needs no change reason (initial creation); a `change_reason`\ngiven anyway is stored with the account's `created` row.\n`custom_fields` sets values of the tenant's custom account fields by\n`key` in the same call (see `GET /v1/account-custom-fields`); an\nunknown key or an empty required field answers 422.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "role_id"
                ],
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "username": {
                    "type": "string",
                    "description": "login, usually the e-mail (min 6 chars)"
                  },
                  "password": {
                    "type": "string",
                    "description": "min 8 chars"
                  },
                  "role_id": {
                    "type": "integer"
                  },
                  "language": {
                    "type": "string",
                    "description": "ISO code, e.g. de, en"
                  },
                  "timezone": {
                    "type": "string",
                    "description": "IANA timezone"
                  },
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "property_ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    }
                  },
                  "custom_fields": {
                    "$ref": "#/components/schemas/CustomFieldValues"
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Optional. Creating needs no reason; when given, it is stored with the created row (alternatively header X-Change-Reason)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created account (account_id, uuid, username)."
          },
          "409": {
            "description": "Username already taken."
          },
          "422": {
            "description": "Validation failed, unknown custom-field key or empty required custom field."
          }
        }
      }
    },
    "/v1/accounts/{id}": {
      "get": {
        "summary": "Employee account detail",
        "description": "Requires scope `accounts:read`. The list fields plus\n`owner_account_id` (\"belongs to\": root account of the subcontractor,\nnull = own staff), the assigned `qualifications` and the values of the\nactive custom fields by `key`. Follows the person scope of the key's\naccount: a subcontractor key reaches only its own people; any other\naccount, a customer account or an unknown id answers 404.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Account detail.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountDetail"
                }
              }
            }
          },
          "404": {
            "description": "Account not found in this tenant or outside the key's person scope."
          }
        }
      },
      "patch": {
        "summary": "Set custom-field values of an employee account",
        "description": "Requires scope `accounts:write` and the right to edit people.\nPartial update by `key`: only the keys sent are touched, `null`\nclears a value. Unknown keys and an empty required field answer 422.\nSame person scope as GET (outside = 404). A `change_reason` is\nstored in the account history when given, and required when the\ntenant policy demands one.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "custom_fields"
                ],
                "additionalProperties": false,
                "properties": {
                  "custom_fields": {
                    "$ref": "#/components/schemas/CustomFieldValues"
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Alternative to the X-Change-Reason header (same rules)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated account detail.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountDetail"
                }
              }
            }
          },
          "404": {
            "description": "Account not found in this tenant or outside the key's person scope."
          },
          "422": {
            "description": "Unknown custom-field key, empty required field, or missing change reason."
          }
        }
      }
    },
    "/v1/account-custom-fields": {
      "get": {
        "summary": "Definitions of the tenant's custom account fields",
        "description": "Requires scope `accounts:read`. The active custom fields of the\nemployee record as configured in the portal, sorted by `sort_order`.\nValues are read and written by `key` (not by label) through\n`GET`/`PATCH /v1/accounts/{id}` and `POST /v1/accounts`. A security-\nguard register number (§ 11b GewO) is not a system field: the tenant\ncreates a text field for it (e.g. key `bewacherregister_nr`).\n",
        "responses": {
          "200": {
            "description": "`{ data: CustomFieldDefinition[] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CustomFieldDefinition"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/accounts/archive": {
      "post": {
        "summary": "Archive or restore employee accounts in a batch",
        "description": "Requires scope `accounts:write`. Accounts have no delete path —\narchiving is the end state. Archiving frees the seat, soft-deletes the\naccount's still-open work-time rows and blocks the mobile app; the\nportal login itself keeps working (it checks the enabled flag, not the\narchive flag).\n\nPartial success is the contract: ids that must not be touched come back\nunder `skipped` with a reason instead of failing the whole run.\nReasons are `not_found`, `customer_account`, `role_not_archivable`\n(e.g. the tenant owner), `insufficient_hierarchy` (at or above the key\naccount's own level), `self` (the account the key authenticates as) and\n`last_admin` (would leave the tenant without an administrator).\n\nRestoring re-occupies seats and is all-or-nothing against the seat cap.\nAn account already in the requested state counts as applied.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "account_ids",
                  "archived"
                ],
                "additionalProperties": false,
                "properties": {
                  "account_ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "minItems": 1,
                    "maxItems": 100
                  },
                  "archived": {
                    "type": "boolean",
                    "description": "true = archive, false = restore"
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Alternative to the X-Change-Reason header (same rules)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ applied: [account_id], skipped: [{ account_id, reason }] }`"
          },
          "422": {
            "$ref": "#/components/responses/ChangeReasonRequired"
          }
        }
      }
    },
    "/v1/accounts/{id}/archive": {
      "post": {
        "summary": "Archive a single employee account",
        "description": "Requires scope `accounts:write`. Same guards as the batch route, but a\nrefusal is an error here. Accounts out of the key's hierarchy reach\nanswer 404 like non-existent ones, so the surface reveals no ids.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "responses": {
          "200": {
            "description": "`{ archived: true }`"
          },
          "403": {
            "description": "Role cannot be archived, or it is the key's own account."
          },
          "404": {
            "description": "Unknown account, or above the key account's level."
          },
          "409": {
            "description": "Would leave the tenant without an administrator."
          },
          "422": {
            "$ref": "#/components/responses/ChangeReasonRequired"
          }
        }
      }
    },
    "/v1/accounts/{id}/unarchive": {
      "post": {
        "summary": "Restore a single employee account",
        "description": "Requires scope `accounts:write`. Re-occupies a seat — answers 403\nSEAT_LIMIT_EXCEEDED when the tenant's cap is already reached.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "responses": {
          "200": {
            "description": "`{ archived: false }`"
          },
          "422": {
            "$ref": "#/components/responses/ChangeReasonRequired"
          }
        }
      }
    },
    "/v1/accounts/{id}/invite-link": {
      "post": {
        "summary": "Mint a copyable password-setup link (no mail is sent)",
        "description": "Requires scope `accounts:write`. Same hierarchy guard as the portal:\nno setup links for accounts at or above the key account's level.\nEvery new link revokes the previous one (one-time, valid 14 days);\na link created within 60 s after an invite e-mail was sent from the\nportal answers 429. Archived or locked accounts answer 409. The link\nis recorded in the account history as `invite_link_created`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "`{ setup_url, expires_at }`"
          }
        }
      }
    },
    "/v1/accounts/{id}/copy": {
      "post": {
        "summary": "Copy an employee account (role, properties, qualifications, custom fields)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "The employee account to copy (`account_id`)."
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyUuid"
          }
        ],
        "description": "Creates a NEW employee equipped like an existing one. Requires scopes `accounts:read` and `accounts:write` (the answer carries\nthe values of the source, so the key must be allowed to read it) and\nthe role right to create persons — copying needs\nthe same rights as creating. The source is only read and never\nchanged. Accounts outside the person scope of the key (staff of\nanother subcontractor), customer portal logins, foreign and unknown\naccounts answer alike (404).\n\nCOPIED: role, property assignment (all properties or the list),\nqualifications, custom fields, language and, for staff of a\nsubcontractor, the owner (`owner_account_id`).\n\nNEVER copied: name (`name` in the body names the new employee and is\nrequired), login name and e-mail, phone, password, PIN, the person's\nNFC chip, personnel number (drawn anew from the number series), note,\nbirthday, address, devices, time entries and history. The\nvalid-until date of a qualification belongs to the person's\ncertificate: the copy gets the qualification without a date, and\n`copy.issues[]` names it (`QUALIFICATION_VALIDITY_NOT_COPIED`).\n\nThe account is created through the same path as POST /v1/accounts:\nthe role must rank below the role of the key's account (403), the\nlicence must have a free seat (403 `seat_limit_exceeded`), and a\nsubcontractor key only creates its own staff. As with creating, no\nchange reason is needed; one given is stored with the audit trail.\nWithout `username` the server generates a login name; the employee\nthen gets access through an invite, as with POST /v1/accounts.\n\nQualifications and custom fields are set after the account exists.\nIf one of them fails, the account still exists: `copy.issues[]`\nnames what is missing (`QUALIFICATIONS_NOT_COPIED`,\n`CUSTOM_FIELDS_NOT_COPIED`, `PROPERTIES_NOT_COPIED`).\n\nIdempotency: pass `Idempotency-Key` (or `uuid`). The same key with\nthe same body answers 200 with `duplicate: true` and the account\ncreated first — no second account, no second seat. The same key with\na different body ⇒ 422 `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`; a second\ncall while the first is still running ⇒ 409\n`IDEMPOTENCY_KEY_IN_PROGRESS`. A call that failed releases its key.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name"
                ],
                "properties": {
                  "uuid": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Idempotency key (alternatively header `Idempotency-Key`)."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Display name of the NEW employee. The name of the source is never copied."
                  },
                  "username": {
                    "type": "string",
                    "minLength": 6,
                    "maxLength": 50,
                    "description": "Login name (usually the e-mail). Omitted: the server generates one."
                  },
                  "change_reason": {
                    "type": "string",
                    "description": "Optional reason for the audit trail (alternatively header `X-Change-Reason`)."
                  }
                }
              },
              "examples": {
                "new_colleague": {
                  "summary": "New colleague with the equipment of an existing one",
                  "value": {
                    "name": "Ben Neu"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The key was used before with the same body: the account created first, `duplicate: true`. Nothing written."
          },
          "201": {
            "description": "Copy created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/AccountDetail"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "source_account_id": {
                              "type": "integer",
                              "description": "The account this one was copied from."
                            }
                          }
                        }
                      ]
                    },
                    "created": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "copy": {
                      "type": "object",
                      "properties": {
                        "all_properties": {
                          "type": "boolean"
                        },
                        "property_ids": {
                          "type": "array",
                          "items": {
                            "type": "integer"
                          }
                        },
                        "issues": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "code": {
                                "type": "string"
                              },
                              "message": {
                                "type": "string"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope `accounts:write` or role right to create persons; the role of the source ranks at or above the role of the key's account; `seat_limit_exceeded` — no free licence seat."
          },
          "404": {
            "description": "Source account unknown, of another tenant, a customer portal login or outside the person scope of the key."
          },
          "409": {
            "description": "`IDEMPOTENCY_KEY_IN_PROGRESS`, or the `username` is already taken."
          },
          "422": {
            "description": "`name` missing, `ACCOUNT_WITHOUT_ROLE`, `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`, or a validation error of the body."
          }
        }
      }
    },
    "/v1/accounts/{id}/properties": {
      "get": {
        "summary": "Properties an employee may access",
        "description": "Requires scope `accounts:read`. Answers either \"all properties\" or the\nfixed list of assigned properties (archived properties are left out).\nFollows the person scope of the key's account (a subcontractor key\nreaches only its own people); an account outside that scope, a\ncustomer login or an account of another tenant answers 404.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: AccountProperties }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/AccountProperties"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Account not found in this tenant or outside the key's person scope."
          }
        }
      },
      "put": {
        "summary": "Set the properties an employee may access",
        "description": "Requires scope `accounts:write` and the right to edit people (the same\nright as the \"Assignment\" card of the employee in the portal). Set\nsemantics: the call replaces the whole assignment. Pass exactly one of\n`property_ids` (1 to 500 ids) or `all_properties: true`; an empty list\nis refused, so nobody sets \"all\" or \"none\" by accident.\n\nRefused: an id that is not an active property of this tenant (422\n`UNKNOWN_PROPERTY_IDS`, the body lists them in `unknown_property_ids`);\nan account at or above the level of the key's account, a customer\nlogin or an account outside the key's person scope (404); the account\nthe key itself is bound to (403 `ACCOUNT_IS_KEY_ACCOUNT`); \"all\nproperties\" for a subcontractor account (422\n`SUBCONTRACTOR_RELATION_GLOBAL`); a subcontractor key handing out a\nproperty its own account cannot access (403\n`PROPERTY_OUTSIDE_ACTOR_SCOPE`).\n\nThe change is recorded in the account history; `change_reason` is\nrequired when the tenant policy demands one. The mobile app picks the\nnew assignment up with its next sync.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "description": "Exactly one of `property_ids` or `all_properties`.",
                "properties": {
                  "property_ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "minItems": 1,
                    "maxItems": 500
                  },
                  "all_properties": {
                    "type": "boolean",
                    "enum": [
                      true
                    ]
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Alternative to the X-Change-Reason header (same rules)."
                  }
                }
              },
              "examples": {
                "list": {
                  "summary": "Two fixed properties",
                  "value": {
                    "property_ids": [
                      12,
                      15
                    ]
                  }
                },
                "all": {
                  "summary": "All properties of the tenant",
                  "value": {
                    "all_properties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: AccountProperties }` — the assignment after the call.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/AccountProperties"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Standard error body with `reason: ACCOUNT_IS_KEY_ACCOUNT` or `PROPERTY_OUTSIDE_ACTOR_SCOPE` (also in `error`), or a missing scope or right."
          },
          "404": {
            "description": "Account not found in this tenant, not manageable by the key's account, or outside its person scope."
          },
          "422": {
            "description": "Standard error body with `reason: UNKNOWN_PROPERTY_IDS` (also in `error`, with `unknown_property_ids`), `SUBCONTRACTOR_RELATION_GLOBAL` or `CHANGE_REASON_REQUIRED`, or a schema error."
          }
        }
      }
    },
    "/v1/form-templates": {
      "get": {
        "summary": "List form templates (checklists)",
        "description": "Requires scope `form_templates:read`. Optional `?status=` filter. Paged like every other list (`page`/`pageSize`, default 50, max 100).",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "active",
                "archived"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged template summaries: `{ data: [{ id, name, status, scope, assignment }], total, page, pageSize }`."
          }
        }
      },
      "post": {
        "summary": "Create a form template",
        "description": "Requires scope `form_templates:write`. Same body as the portal editor\n(name, schema field array, scope, assignment.property_ids,\nrequires_signature, scoring…). Created as draft unless\n`status: active` is passed — activating counts against the\nform_templates quota. `template_kind` is `user` (default) or\n`checklist`; a checklist template (one `task` field per point) is\nwhat a task checklist with photo points becomes — usually you let\nPOST /v1/tasks or PUT /v1/tasks/{id}/checklist create it for you.\nCreating needs no change reason (initial creation); a `change_reason`\ngiven anyway (body or `X-Change-Reason` header) is stored with the\ntemplate's `created` row.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "schema"
                ],
                "description": "Portal editor body (not exhaustive — see the editor); the fields below are the ones the API adds or documents explicitly.",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "template_kind": {
                    "type": "string",
                    "enum": [
                      "user",
                      "checklist"
                    ],
                    "description": "Immutable after creation."
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "schema": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  },
                  "scope": {
                    "type": "string",
                    "enum": [
                      "standalone",
                      "property",
                      "tag",
                      "route"
                    ],
                    "description": "Omitted with a non-empty `assignment.property_ids` ⇒ the\ntemplate is saved with scope `property` (as the MCP tool\n`create_form_template`). `standalone` or `route` together\nwith `property_ids` is rejected with 400 `invalid_schema`\n(the ids would have no effect at runtime); `tag` may carry\n`property_ids` (they restrict the tag scan to those properties).\n"
                  },
                  "assignment": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "`{ property_ids?, route_ids?, tag_types?, worktime_events? }`.\n`property_ids` without `scope` sets the scope to `property`;\n`scope: standalone`/`route` together with `property_ids`\nanswers 400 `invalid_schema`. Every id must belong to the\ntenant (400 `invalid_schema` otherwise).\n"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "draft",
                      "active"
                    ],
                    "description": "Lifecycle state at creation; default `draft`. `active` counts against the form_templates quota (403 when exhausted)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created template."
          },
          "400": {
            "description": "`invalid_schema` with structural errors."
          }
        }
      }
    },
    "/v1/form-templates/{id}": {
      "get": {
        "summary": "Get a form template with all its fields",
        "description": "Requires scope `form_templates:read`. One template with its settings\nand the ordered `fields` array in the shape POST /v1/form-templates\ntakes (texts in their source language only, no storage keys of\nreference images) — a template can serve as a model for a new draft\nor be compared against an auditor's checklist. `property_ids` /\n`property_names` are the EFFECTIVE assignment: filled only for scope\n`property` and `tag` (where the ids restrict), empty for `standalone`\nand `route` (ids stored there have no effect at runtime; the list\nendpoint shows the stored `assignment` as is). They are cut down to\nthe properties the key account can see (property-restricted accounts\nnever see foreign properties).\nAn id of another tenant answers 404 (indistinguishable from unknown).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { id, form_template_id, name, description, status, template_kind, is_system, scope, property_ids, property_names, requires_signature, requires_review, esignature_mode, scoring_enabled, pass_threshold, default_priority, icon, accent_color, version, field_count, fields: FormFieldDefinition[], updated_at } }` — `id` as in the list, `form_template_id` as in the MCP tool (same value)."
          },
          "404": {
            "description": "Unknown id or template of another tenant."
          }
        }
      },
      "patch": {
        "summary": "Update a form template",
        "description": "Requires scope `form_templates:write`. Partial body of the create\nshape. Scope ↔ assignment is validated on the merged result: a patch\nwith `assignment.property_ids` and no `scope` moves a `standalone`/\n`route` template to scope `property` (a `tag` template stays `tag`);\n`scope: standalone`/`route` while `property_ids` remain non-empty\nanswers 400 `invalid_schema` — send `assignment.property_ids: []`\nalong to release the binding.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated template."
          }
        }
      }
    },
    "/v1/form-templates/{id}/status": {
      "post": {
        "summary": "Switch template status (draft / active / archived)",
        "description": "Requires scope `form_templates:write`. Entering `active` counts\nagainst the form_templates quota.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "status"
                ],
                "additionalProperties": false,
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "draft",
                      "active",
                      "archived"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated template."
          }
        }
      }
    },
    "/v1/form-templates/catalog/import": {
      "post": {
        "summary": "Import curated catalog templates (as drafts)",
        "description": "Requires scope `form_templates:write`. `keys` are catalog entry keys\n(e.g. the vacation-rental group: master data, cleaning checklist,\nhousekeeping inspection, move-in/move-out handover protocols).\nIdempotent per template name; imports always land as drafts.\nImporting needs no change reason (initial creation); a `change_reason`\ngiven anyway (body or `X-Change-Reason` header) is stored with each\nimported template's `created` row.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "keys"
                ],
                "additionalProperties": false,
                "properties": {
                  "keys": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Optional. Importing needs no reason; when given, it is stored with the created rows (alternatively header X-Change-Reason)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Import result per key."
          }
        }
      }
    },
    "/v1/report-templates": {
      "get": {
        "summary": "List report templates",
        "description": "Requires scope `report_templates:read` and the right to view reports.\nThe export templates behind the reports (Exports → Templates in the\nportal): the company's own templates plus the ones shared with the\nkey's account, and every stock template the company has not edited yet\n(virtual `default:<slug>` ids). Archived templates are left out.\nPaged (`page`/`pageSize`, default 50, max 100); `sortField` one of\n`updated_at` (default), `created_at`, `name`, `report_group`,\n`is_shared`; `sortOrder` `asc`/`desc` (default `desc`).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "sortField",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "updated_at",
                "created_at",
                "name",
                "report_group",
                "is_shared"
              ],
              "default": "updated_at"
            }
          },
          {
            "name": "sortOrder",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "desc"
            }
          },
          {
            "name": "locale",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "de",
                "en"
              ],
              "default": "de"
            },
            "description": "Language of the stock templates' names and descriptions."
          }
        ],
        "responses": {
          "200": {
            "description": "Paged templates.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ReportTemplate"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "pageSize": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a report template",
        "description": "Requires scope `report_templates:write`, the right to export reports and\nthe Custom report templates module (Standard package or higher;\n`403 ENTITLEMENT_MISSING` otherwise). Counts against the company's\ntemplate quota (Standard 10, Premium unlimited; 403 when exhausted).\nEvery `sections[].fields` key must exist in the catalog for its\n`source` (400 otherwise). No change reason is needed — report\ntemplates are outside change control and the configuration audit\ntrail, exactly like the portal editor.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/ReportTemplateWrite"
                  },
                  {
                    "required": [
                      "name"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created template.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ReportTemplate"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "A `fields` key the source does not offer (message names the unknown and the valid keys)."
          },
          "403": {
            "description": "Missing scope, right, module or quota."
          },
          "422": {
            "description": "Unknown or malformed field."
          }
        }
      }
    },
    "/v1/report-templates/catalog": {
      "get": {
        "summary": "Sources and columns a template can use",
        "description": "Requires scope `report_templates:read` and the Custom report templates\nmodule. The same list the portal editor builds its column picker from:\nevery data source (`worktime.history`, `incidents.list`, `tasks.list`,\n`routes.list`, …) with the column keys it offers. Use it to choose\n`sections[].fields` — e.g. everything but `property_name` to drop the\nobject column from a report.\n",
        "parameters": [
          {
            "name": "locale",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "de",
                "en"
              ],
              "default": "de"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sources with their columns and KPIs.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ReportTemplateCatalogSource"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/report-templates/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Row UUID or `default:<slug>` (an unedited stock template). Anything else answers 422."
        }
      ],
      "get": {
        "summary": "Get a report template",
        "description": "Requires scope `report_templates:read`. Another company's id, or one the key's account cannot see, answers 404. `?locale=de|en` as on the list.",
        "parameters": [
          {
            "name": "locale",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "de",
                "en"
              ],
              "default": "de"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The template.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ReportTemplate"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found."
          }
        }
      },
      "patch": {
        "summary": "Update a report template",
        "description": "Requires scope `report_templates:write`, the right to export reports and\nthe Custom report templates module. Partial: only the fields given\nchange; `sections` replaces the whole section list. On a `default:<slug>`\nid the company's own copy is created from the stock template on the\nfirst call (the answer carries its UUID; repeating the call edits that\ncopy, it never creates a second one). Shared templates may be edited by\nevery account with the export right. No change reason needed.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReportTemplateWrite"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated template.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ReportTemplate"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "A `fields` key the source does not offer."
          },
          "404": {
            "description": "Not found."
          },
          "422": {
            "description": "Unknown or malformed field."
          }
        }
      },
      "delete": {
        "summary": "Delete a report template",
        "description": "Requires scope `report_templates:write`, the right to export reports and\nthe Custom report templates module. Stock templates — virtual or the\ncompany's edited copy (`is_default: true`) — cannot be deleted (403);\nrestore a stock template's original columns with a PATCH instead.\n",
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "403": {
            "description": "Stock template."
          },
          "404": {
            "description": "Not found."
          }
        }
      }
    },
    "/v1/workflow-rules": {
      "get": {
        "summary": "List automation rules",
        "description": "Requires scope `workflows:read`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "inactive"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged rule list."
          }
        }
      },
      "post": {
        "summary": "Create an automation rule",
        "description": "Requires scope `workflows:write`. Same body as the portal builder\n(`name`, `enabled`, `graph` with trigger/action nodes). Creating with\n`enabled: true` counts against the workflow_rules_active quota; the\ngraph is subject to the package's action-type restrictions. Creating\nneeds no change reason (initial creation); a `change_reason` given\nanyway (body or `X-Change-Reason` header) is stored with the rule's\n`created` row.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "responses": {
          "201": {
            "description": "Created rule."
          }
        }
      }
    },
    "/v1/workflow-executions": {
      "get": {
        "summary": "Runs of the automation (history)",
        "description": "Requires scope `workflows:read`, the Read right on workflows and a\nkey account with relation `global` (automation is company-wide; a\nproperty-restricted account gets 403). Newest first, including runs\nof deleted rules. Without error texts, results or payloads.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "rule_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "running",
                "success",
                "failed",
                "skipped",
                "deduped",
                "scheduled"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{run_id, rule_id, rule_name, rule_source, trigger_type,\nstatus, attempts, created_at, fired_at}], total, page, pageSize }`\n"
          }
        }
      }
    },
    "/v1/workflow-executions/{id}/deliveries": {
      "get": {
        "summary": "One run with its deliveries (recipients masked)",
        "description": "Same gates as `/v1/workflow-executions`. E-mail and SMS/call\nrecipients are masked (`j***@firma.de`, `+49 *** ** 12`); push and\nin-app deliveries carry counts only. Never the plain recipient, never\nthe error text.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: {run_id, rule_id, rule_name, rule_source, trigger_type,\nstatus, attempts, created_at, fired_at, deliveries: [{channel,\nnode_id, recipient_masked, status, sent_at, accounts, devices}]} }`\n"
          },
          "404": {
            "description": "Run not found."
          }
        }
      }
    },
    "/v1/change-requests": {
      "get": {
        "summary": "Requests of the change approval (archive, restore, correction, configuration)",
        "description": "Requires scope `audit:read`. Approvers (`ARCHIVE_APPROVE`) see every\nrequest; everyone who may request (Delete FormResponse, Update\nIncident, Update TourPlan) sees only the own requests — `mine` is\nforced. Grouped by batch, newest first. Names the changed FIELDS\n(`changed_fields`), never the payload or old/new values. Deciding\nstays in the portal.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "approved",
                "rejected"
              ],
              "default": "pending"
            }
          },
          {
            "name": "mine",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "archive",
                "restore",
                "amend",
                "correct",
                "config"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{batch_id, kind, entity_type, status, count, reason,\nentity_label, changed_fields[], requested_by_name,\ndecided_by_name, decision_note, created_at, decided_at}], total,\npage, pageSize }`\n"
          }
        }
      }
    },
    "/v1/config-changes": {
      "get": {
        "summary": "Change history of the settings (who changed what, when)",
        "description": "Requires scope `audit:read` and the Read right on settings. The\ntenant-wide trail for global key accounts; property-restricted\naccounts must pass `property_id` (else `403`, `reason:\nPROPERTY_REQUIRED`) and get the trail of that property. Names the\nchanged FIELDS by default; old/new values, the change reason and the\nactor's username only with `include=values` (one entry per changed\nfield, nested objects flattened to `a.b.c`). Never meta, never the\nactor uuid. `property_id`/`property_name` name the property an entry\nbelongs to (resolved within the tenant); both are null for\ntenant-wide settings such as roles or company settings.\n`entity_name` names the changed record (template, role, task,\ncontrol point …): stamped at write time or resolved within the\ntenant at read time; null when no name source exists.\n`actor_role_name`/`actor_role_type` give the actor's role frozen at\nthe time of the change (always, no `include` needed): the tenant's\nrole name and its fixed type (admin, subadmin, customer,\npropertymanager, securityemployee, subcontractor) or `platform_admin`\nfor the platform operator (no name, no account). Both are null for\nrows written before 2026-10-10 and for system actors; renaming a role\ndoes not rewrite history. Note: for `event: role_change` the changed\nrole (target) is in `changes`, the actor's own role is in\n`actor_role_*`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "entity_type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "entity_id",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "description": "Only entries of this record (id within entity_type)."
          },
          {
            "name": "include",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "values"
              ]
            },
            "description": "`values`: add `changes[{field, old, new}]`, `change_reason`, `actor_username`, `initial_creation`."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{id, created_at, entity_type, entity_id, event,\nactor_name, actor_role_name, actor_role_type, property_id,\nproperty_name, entity_name, changed_fields[],\nchanges?: [{field, old, new}], change_reason?,\nactor_username?, initial_creation?}], total, page, pageSize }` —\nthe four optional fields only with `include=values`;\n`initial_creation` is true for the `created` row and for\nfollow-up rows written in the same creating request (bindings,\nchecklist, settings of a new task or property) — such rows need\nno `change_reason` (the portal shows \"Erstanlage\"); `property_id`/`property_name`\nare null for tenant-wide settings; `entity_name` is null without\na name source; `actor_role_name`/`actor_role_type` are null for\nrows before 2026-10-10 and for system actors (`platform_admin`\ncarries no name).\n"
          },
          "403": {
            "description": "`PROPERTY_REQUIRED` for property-restricted keys without `property_id`, or property outside the restriction."
          }
        }
      }
    },
    "/v1/devices": {
      "get": {
        "summary": "Registered devices of the tenant (support view)",
        "description": "Requires scope `devices:read` and the Read right on devices (same as\nthe portal's device list). Lists the phones and tablets that ever\nsigned in with the LiteLog app: manufacturer, model, OS name,\napp version, when it was last used, the account last active on it and\nthe properties it is assigned to. Sorted by last use (newest first).\nProperty-restricted key accounts only see devices assigned to one of\ntheir properties; devices without a property assignment are visible to\nglobal accounts only. `os` is the OS NAME (\"iOS\"/\"Android\") the app\nreports — historically stored in the `serial_number` slot, so it is not\na serial number. Never notes, GPS, push credentials or the raw meta\nrecord.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Substring match on unique_id, name, app_version, manufacturer, model, device_name and os."
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "Only devices whose last active account is this one."
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "Only devices assigned to this property (intersected with the key's property restriction)."
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "maintenance",
                "defective"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{device_id, unique_id, name, manufacturer, model, os,\ndevice_name, app_version, status, last_used_at, registered_at,\nlast_account_id, last_account_name, property_ids[], relation,\nlocked_at}], total, page, pageSize }` — `name` is the internal\ndevice name from the portal; `last_used_at`, `app_version` and\n`last_account_*` are null until the device reported once.\n"
          },
          "403": {
            "description": "Missing scope `devices:read` or no Read right on devices."
          }
        }
      }
    },
    "/v1/session-log": {
      "get": {
        "summary": "Sign-in log (logins, failures, device switches, locks)",
        "description": "Requires scope `audit:read` and the Read right on settings (like\n`/v1/config-changes`). The tenant's session log: every login, failed\nlogin, logout, property change, device registration and account\nswitch on a device, lock/unlock, MFA event, session refresh and\nrevocation, admin login and API-key authentication — with the device,\nits internal name, the user agent and the IP address. Unlike the\nportal history this includes rows without an account (admin logins,\nfailed logins with an unknown username). Only key accounts that see\nall properties (else `403`, `reason: GLOBAL_ACCOUNT_REQUIRED`) —\nsession rows belong to accounts, not properties. Range: `to` defaults\nto now, `from` to `to` − 7 days, at most 31 days (`422`, `reason:\nRANGE_TOO_LARGE`; `from` after `to` ⇒ `RANGE_INVALID`). Never the raw\nmeta record, never coordinates.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "device_id",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "A device_id from `GET /v1/devices`."
          },
          {
            "name": "event",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 400
            },
            "description": "Comma-separated list (max 10) of event names, e.g. `login,login_failed,device_registered`; unknown names ⇒ `422`."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{id, occurred_at, event, account_id, actor_name,\nactor_username, actor_role_type, login_method, failure_reason,\ndevice_id, device_unique_id, device_name, ip, user_agent,\nold_property_id, new_property_id, surface}], total, page,\npageSize, from, to }` — newest first; `id` is a string (bigint);\n`surface` is `app`, `portal` or `admin` where known; `from`/`to`\necho the resolved range.\n"
          },
          "403": {
            "description": "`GLOBAL_ACCOUNT_REQUIRED` for property-restricted keys; or missing scope `audit:read`."
          },
          "422": {
            "description": "`RANGE_TOO_LARGE` (more than 31 days) or `RANGE_INVALID` (`from` after `to`), unknown `event` name."
          }
        }
      }
    },
    "/v1/diagnostics/events": {
      "get": {
        "summary": "Diagnostic events reported by the app (NFC write results, read errors, unknown chips)",
        "description": "Requires scope `devices:read` and the Read right on devices. The\nLiteLog app reports what used to stay on the phone: the result of\nevery chip write (`kind: nfc_write` — `outcome` WRITE_OK, FORMAT_LOCK,\nBIND_SILENT, CONFIRM_DIALOG, ABORT_INCOMPLETE, ABORT_NO_TAG,\nABORT_FORMAT_THREW, ABORT_STATUS_THREW, ABORT_EXCEPTION or CANCELLED,\nwith `step` = the last step reached: tech_connect, get_tag, format,\nndef_status, write, verify, lock), iOS read errors\n(`nfc_read_error`: timeout, failed), scanned chips the tenant does\nnot know (`scan_unknown_chip`: not_found, lookup_timeout) and the\nserver-side chip binding after a write (`chip_bind`: success, taken,\nerror, overwrite_success, overwrite_error). Each row carries the\ndevice, platform, OS version, app version, chip id, duration and a\nsmall `meta` record (e.g. `matchedTech`, `ndefWritable`,\n`verifyFailed`). Rows arrive only from app versions that report them\n(4.1.21 and later) and are kept for 90 days. Only key accounts that\nsee all properties (else `403`, `reason: GLOBAL_ACCOUNT_REQUIRED`).\nRange like `/v1/session-log`: default 7 days, at most 31 (`422`,\n`reason: RANGE_TOO_LARGE`).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "nfc_write",
                "nfc_read_error",
                "scan_unknown_chip",
                "chip_bind"
              ]
            }
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "device_id",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "A device_id from `GET /v1/devices`."
          },
          {
            "name": "chip_id",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "description": "Chip UID as the app reports it (e.g. `041BFB7A531E91`)."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{id, received_at, client_ts, kind, outcome, step,\naccount_id, device_id, device_unique_id, platform, os_version,\napp_version, chip_id, target_type, target_id, error, duration_ms,\nmeta}], total, page, pageSize, from, to }` — newest first; `id` is\na string (bigint); `client_ts` is the phone's clock, `received_at`\nthe server's; `meta` is a flat object of at most 20 keys.\n"
          },
          "403": {
            "description": "`GLOBAL_ACCOUNT_REQUIRED` for property-restricted keys; or missing scope `devices:read`."
          },
          "422": {
            "description": "`RANGE_TOO_LARGE` or `RANGE_INVALID`."
          }
        }
      }
    },
    "/v1/scans": {
      "get": {
        "summary": "Scan trail of a chip, control point, account or property",
        "description": "Requires scope `patrols:read` and the Read right on control points —\nthe same data as `/v1/patrols/{id}/events`, but across runs: every\nread of a control point in a planned patrol or a free patrol\n(`kind: checkpoint`, `method` nfc | qr | beacon | photo | gps) plus\nevery chip or QR read the server rejected (`kind: rejected`, from\nthe verification log: `reason` no_property_access, token_not_found,\ntoken_revoked …), newest first. At least one anchor is required:\n`chip_id`, `tag_id`, `account_id` or `property_id` (else `422`);\n`device_unique_id`, `kind` and `method` only narrow further.\n`chip_id` is normalised (separators removed, upper case) and resolves\nto the control points that carry the chip now OR carried it before\n(rebinding/archiving history), so a moved chip keeps its trail; the\n`chip_id` field of a checkpoint row is the chip bound NOW, of a\nrejected row the UID that was read. Property-restricted key accounts\nsee only runs of their properties. Range: `to` defaults to now,\n`from` to `to` − 7 days, at most 31 days (`422`, `reason:\nRANGE_TOO_LARGE`). Not included: work-time stamps (no chip stored),\ntour stops (no chip), scans of free patrols that were archived in\nthe portal, and the app's own write/read diagnostics\n(`/v1/diagnostics/events`). Never photos, never coordinates.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "chip_id",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "description": "Chip UID as the app scans it; separators and case are normalised."
          },
          {
            "name": "tag_id",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "Control point id (from `GET /v1/control-points`)."
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "device_unique_id",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 128
            },
            "description": "Phone id as reported by the app (`unique_id` in `GET /v1/devices`)."
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "checkpoint",
                "rejected"
              ]
            }
          },
          {
            "name": "method",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "nfc",
                "qr",
                "beacon",
                "photo",
                "gps"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{id, scanned_at, received_at, kind, method, tag_id,\ntag_name, chip_id, property_id, account_id, account_name,\ndevice_unique_id, device_id, run_id, run_kind, location_status,\nimpossible_travel, mock_location, source, sync_source, reason}],\ntotal, page, pageSize, from, to }` — `id` is prefixed by its\nsource (`rlt:`, `crlt:`, `ve:`); `scanned_at` is the device\nclock, `received_at` the server's; `run_kind` is `route`\n(planned patrol) or `custom_route` (free patrol), null for\nrejected reads; `device_id` resolves the phone id within the\ntenant and is null for unknown phones; `reason` only on rejected\nrows.\n"
          },
          "403": {
            "description": "Missing scope `patrols:read` or no Read right on control points."
          },
          "422": {
            "description": "No anchor (`chip_id`, `tag_id`, `account_id`, `property_id`), `RANGE_TOO_LARGE`, `RANGE_INVALID` or an unknown `kind`/`method`."
          }
        }
      }
    },
    "/v1/sync-failures": {
      "get": {
        "summary": "Offline-sync rejections per device (parked, dropped, suspect, failed bookings)",
        "description": "Requires scope `devices:read` and the Read right on devices. Answers\n\"why does this phone's offline data not arrive\": every record the\nserver parked (`outcome: parked`, `reason` = error code such as\ninvalid_schema, unknown_entity, too_many_records), acknowledged\nwithout storing (`acked_dropped`: shift_deleted,\nshift_already_closed, duplicate_state), flagged as replay\n(`replay_suspect`: device clock far behind receipt) — from the sync\ningest log — plus bookings the server could not store at all\n(`outcome: error`, from the failed-sync store: `entity` = target\ntable, `action` INSERT/UPDATE, `status` PENDING/HOLD/DONE,\n`retry_count`). `detail` is a short redacted message (never the\npayload, never a stack trace). Only key accounts that see all\nproperties (else `403`, `reason: GLOBAL_ACCOUNT_REQUIRED`). Range:\n`to` defaults to now, `from` to `to` − 7 days, at most 31 days\n(`422`, `reason: RANGE_TOO_LARGE`). Retention: ingest rows 90 days;\nfailed bookings until resolved (DONE rows 180 days). Successful syncs\nare not logged.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "device_id",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "A device_id from `GET /v1/devices` (resolved to the phone id within the tenant)."
          },
          {
            "name": "device_unique_id",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 128
            },
            "description": "Phone id as reported by the app."
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "Ingest rows only (failed bookings carry no account)."
          },
          {
            "name": "outcome",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "parked",
                "acked_dropped",
                "replay_suspect",
                "error"
              ]
            }
          },
          {
            "name": "entity",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 40
            },
            "description": "Sync entity (e.g. work_time, routes_logs_tags) or target table of a failed booking."
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "PENDING",
                "HOLD",
                "DONE"
              ]
            },
            "description": "Failed bookings only."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{id, occurred_at, source, device_unique_id, device_id,\naccount_id, sync_path, entity, action, outcome, reason, detail,\nstatus, retry_count, done_at, client_uuid, client_ts}], total,\npage, pageSize, from, to }` — `id` is prefixed `ingest:` or\n`failed:`; `source` is `ingest` or `failed_sync`; `client_uuid`,\n`client_ts`, `sync_path`, `account_id` only on ingest rows;\n`action`, `status`, `retry_count`, `done_at` only on failed\nbookings; `device_id` null for phones the tenant no longer knows.\n"
          },
          "403": {
            "description": "`GLOBAL_ACCOUNT_REQUIRED` for property-restricted keys; or missing scope `devices:read`."
          },
          "422": {
            "description": "`RANGE_TOO_LARGE` or `RANGE_INVALID`, unknown `outcome`/`status`."
          }
        }
      }
    },
    "/v1/notifications": {
      "get": {
        "summary": "Delivery attempts of e-mail, SMS, calls, push and in-app messages",
        "description": "Requires scope `audit:read` and the Read right on settings (like the\nsign-in log). Answers \"why did the mail / SMS / push not arrive\":\nevery delivery attempt from the mail log (e-mail and push, provider\nstatus, fallback reason), the automation dispatch log (SMS, call,\npush, in-app), attendance alarms and reminders, and the lone-worker\ncheck-in pushes — newest first. Recipients are always masked\n(`j***@firma.de`, `+49 *** ** 12`); push tokens and in-app\nplaceholders are returned as `null`. `error_summary` is a redacted\none-line summary of the provider error (contact data removed, at most\n200 characters), never a stack trace. `status` is the provider's\nword (sent, failed, blocked, pending, fallback, dead_letter,\nunknown_state, no_device); a reservation without outcome reads\n`pending`. Only key accounts that see all properties (else `403`,\n`reason: GLOBAL_ACCOUNT_REQUIRED`). Range: `to` defaults to now,\n`from` to `to` − 7 days, at most 31 days (`422`, `reason:\nRANGE_TOO_LARGE`). Retention: the mail log keeps 21 days, the other\nsources longer. Push rows carry the tenant from this release on;\nolder push rows are not attributable and do not appear.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "channel",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "email",
                "sms",
                "call",
                "push",
                "in_app"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "sent",
                "failed",
                "blocked",
                "pending",
                "fallback",
                "dead_letter",
                "unknown_state",
                "no_device"
              ]
            }
          },
          {
            "name": "source",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "mail",
                "workflow",
                "attendance",
                "lone_worker"
              ]
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "Only sources that carry a property (attendance, lone_worker)."
          },
          {
            "name": "recipient",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 320
            },
            "description": "Exact e-mail address or phone number as stored; matched server-side, never echoed back."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{id, occurred_at, sent_at, channel, source,\nrecipient_masked, status, error_summary, fallback_reason,\nsubject, template, notification_type, dedup_key, node_id, stage,\naccount_id, property_id}], total, page, pageSize, from, to }` —\n`id` is prefixed by its source (`mail:`, `wf:`, `att:`, `lw:`);\n`subject`/`template`/`fallback_reason` only on mail rows,\n`dedup_key`/`node_id` on automation rows, `notification_type` on\nattendance rows, `stage`/`account_id` on lone-worker rows.\n"
          },
          "403": {
            "description": "`GLOBAL_ACCOUNT_REQUIRED` for property-restricted keys; or missing scope `audit:read`."
          },
          "422": {
            "description": "`RANGE_TOO_LARGE` or `RANGE_INVALID`, unknown `channel`/`status`/`source`."
          }
        }
      }
    },
    "/v1/shifts": {
      "get": {
        "summary": "List planned shifts (Dienstplan)",
        "description": "Requires scope `shifts:read`. Range-bounded (max 366 days), not paged.\nWithout `property_id` the key sees all its accessible properties.\n`account_id` filters to shifts whose planned staffing contains that\nemployee. Cancelled shifts only appear with `include_cancelled=true`.\nThe list follows the key account's person scope: a key of a\nsubcontractor account (role `own_only`) only sees shifts with itself\nand its own employees — the same rule as `GET /v1/accounts`.\n",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "include_cancelled",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Shift list for the range.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Shift"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a single shift",
        "description": "Requires scope `shifts:write`. Check-in/out window timestamps are\noptional — omitted, they default to the full shift span (check-in/out\nallowed any time during the shift). `series_id` attaches the instance\nto an existing series; without it a standalone shift is created.\n`assignee_account_ids` sets the planned staffing (accounts must be\nassigned to the property or have global relation).\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "property_id",
                  "start_ts",
                  "end_ts"
                ],
                "additionalProperties": false,
                "properties": {
                  "series_id": {
                    "type": "integer"
                  },
                  "property_id": {
                    "type": "integer"
                  },
                  "start_ts": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "end_ts": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "checkin_start_ts": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "checkin_end_ts": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "checkout_start_ts": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "checkout_end_ts": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "name": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "checkin_requirement_mode": {
                    "type": "string",
                    "enum": [
                      "optional",
                      "minimum",
                      "fixed"
                    ]
                  },
                  "checkout_requirement_mode": {
                    "type": "string",
                    "enum": [
                      "optional",
                      "minimum",
                      "fixed"
                    ]
                  },
                  "required_checkins": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "required_checkouts": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "required_headcount": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 1,
                    "maximum": 999,
                    "description": "Explicit staffing target (Soll-Besetzung); overrides the derived demand. null clears it."
                  },
                  "required_qualifications": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "maxItems": 20,
                    "description": "Qualification demand: `[{qualification_id, count}]`, at most\n20 entries, each qualification once. Needs\n`required_headcount` (else `422 QUALIFICATION_DEMAND_NEEDS_HEADCOUNT`);\nΣ count ≤ required_headcount (else\n`422 QUALIFICATION_DEMAND_EXCEEDS_HEADCOUNT`). null / [] = none.\n",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "qualification_id",
                        "count"
                      ],
                      "properties": {
                        "qualification_id": {
                          "type": "integer",
                          "minimum": 1
                        },
                        "count": {
                          "type": "integer",
                          "minimum": 1,
                          "maximum": 999
                        }
                      }
                    }
                  },
                  "assignee_account_ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created shift.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Shift"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/shifts/bulk": {
      "post": {
        "summary": "Create up to 100 shifts in one call",
        "description": "Requires scope `shifts:write`. `assignee_account_ids` (top level)\nstaffs ALL instances of the call — per-instance staffing is rejected.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "instances"
                ],
                "additionalProperties": false,
                "properties": {
                  "instances": {
                    "type": "array",
                    "maxItems": 100,
                    "items": {
                      "type": "object",
                      "description": "Same shape as POST /v1/shifts minus assignee_account_ids (incl. required_headcount + required_qualifications, checked per instance)."
                    }
                  },
                  "assignee_account_ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ created, uuids }`."
          }
        }
      }
    },
    "/v1/shifts/generate": {
      "post": {
        "summary": "Materialise planned instances of an existing series",
        "description": "Requires scope `shifts:write`. Generates the scheduled instances of\nseries `series_id` for the date range according to its recurrence\nrules. The timezone is ALWAYS resolved server-side from the property.\nAlready-existing instances are skipped (idempotent per day).\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "series_id",
                  "property_id",
                  "from",
                  "to"
                ],
                "additionalProperties": false,
                "properties": {
                  "series_id": {
                    "type": "integer"
                  },
                  "property_id": {
                    "type": "integer"
                  },
                  "from": {
                    "type": "string",
                    "format": "date"
                  },
                  "to": {
                    "type": "string",
                    "format": "date"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ created }` — number of new instances."
          }
        }
      }
    },
    "/v1/shift-series": {
      "post": {
        "summary": "Create a shift series (a shift with a repetition)",
        "description": "Requires scope `shifts:write`. Creates ONE series: a shift that\nrepeats daily or weekly, with its people, with or without end — the\nrecord the portal creates with \"Wiederholung\" in the shift form.\nLiteLog creates the shifts of the series up to 90 days ahead at once\n(`generated_until`) and adds the later days itself, day by day; a\nplan that repeats needs one series per rhythm, not one shift per day.\n\nThe fields follow the calendar pattern \"rhythm + period\": the rhythm\nis `repeat` with `interval_weeks` and `weekdays`, the period is\n`start_date` and `end_date` (absent or null = no end). Times are wall\nclock in the time zone of the property; an `end_time` at or before\n`start_time` ends on the next day. Check-in and check-out windows,\nmodes and automatic check-out are not set here: the series inherits\nthem from the property, as a new series in the portal does. Holidays\ndo not skip a day.\n\nIdempotency: `idempotency_key` (or the header `Idempotency-Key`, a\nUUID) becomes the id of the series. The same key again answers `200`\nwith the series created first (`created: false`) and writes nothing.\nA key that belongs to a series the key cannot see answers\n`409 SERIES_KEY_TAKEN`.\n\nA series plans the times of other people: the key's role needs\nVIEW_TIME_TRACKING_OTHERS or the Update right on time tracking, and\na key whose account sees only its own people (subcontractor) is\nrefused with `403`.\n\nA different body under a key used before answers\n`422 IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`.\n\nRefusals before anything is written: `403` the property is unknown or\noutside the key's property restriction, the key sees only its own\npeople, or the package limit on planned people would be exceeded\n(`reason: quota_exceeded`, every series counts, also one that starts\nlater than 90 days ahead); `409 ASSIGNEE_NO_PROPERTY_ACCESS` a person\nis unknown, of another company or without access to the property\n(`errors[0].account_ids` names them); `422 SERIES_START_IN_PAST` the\nfirst shift (start_date + start_time in the zone of the property)\nlies in the past (the first shift the rhythm gives, in the zone of\nthe property). If the series is written but a later step fails (its\nshifts, its line in the settings history), the call answers\n`500 SERIES_PARTIALLY_WRITTEN` with `errors[0].series_id`: repeat it\nwith the same key, the replay answers the series and completes its\nhistory line. A repeated key is compared by meaning: the order of\n`weekdays` and people, an explicit `end_date: null` or\n`interval_weeks: 1` do not make another request.\n\nThe planned people are notified as in the portal. Double bookings,\nabsences and working-time rules never block; check them beforehand\nwith GET /v1/shifts/conflicts.\n",
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Second spelling of `idempotency_key`; both must match when both are sent."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "property_id",
                  "name",
                  "start_date",
                  "start_time",
                  "end_time",
                  "repeat"
                ],
                "properties": {
                  "property_id": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255
                  },
                  "start_date": {
                    "type": "string",
                    "format": "date",
                    "description": "First day, in the time zone of the property. Today or later."
                  },
                  "start_time": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$",
                    "description": "HH:mm, wall clock of the property."
                  },
                  "end_time": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$",
                    "description": "HH:mm; at or before start_time = the next day. Must differ from start_time."
                  },
                  "repeat": {
                    "type": "string",
                    "enum": [
                      "daily",
                      "weekly"
                    ],
                    "description": "daily = every day; weekly = on `weekdays`."
                  },
                  "interval_weeks": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 52,
                    "description": "weekly only: every n-th week. Default 1."
                  },
                  "weekdays": {
                    "type": "array",
                    "maxItems": 7,
                    "uniqueItems": true,
                    "items": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 6
                    },
                    "description": "weekly only, required there: 0 = Sunday … 6 = Saturday (as everywhere in this API)."
                  },
                  "end_date": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date",
                    "description": "Last day (inclusive). Absent or null = no end."
                  },
                  "assignee_account_ids": {
                    "type": "array",
                    "maxItems": 100,
                    "uniqueItems": true,
                    "items": {
                      "type": "integer",
                      "minimum": 1
                    },
                    "description": "Planned people of every shift of the series."
                  },
                  "required_headcount": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 999,
                    "description": "How many people each shift needs."
                  },
                  "instructions": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000,
                    "description": "Note for the people (portal: Anweisungen), shown at every shift."
                  },
                  "idempotency_key": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              },
              "example": {
                "property_id": 12,
                "name": "Büro Nord",
                "start_date": "2027-01-01",
                "start_time": "06:00",
                "end_time": "08:00",
                "repeat": "weekly",
                "weekdays": [
                  1,
                  2,
                  3,
                  4,
                  5
                ],
                "assignee_account_ids": [
                  34
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The idempotency key was used before — the series created first, `created: false`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ShiftSeriesCreated"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Created series.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ShiftSeriesCreated"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Property unknown or outside the key's restriction, the key sees only its own people or lacks VIEW_TIME_TRACKING_OTHERS, or `quota_exceeded` (planned people of the package)."
          },
          "409": {
            "description": "`ASSIGNEE_NO_PROPERTY_ACCESS` or `SERIES_KEY_TAKEN`."
          },
          "422": {
            "description": "Validation failure (e.g. `end_date` not after `start_date`: a single day is one shift), `SERIES_START_IN_PAST`, `SERIES_NOT_VALID` or `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`."
          },
          "500": {
            "description": "`SERIES_PARTIALLY_WRITTEN`: the series exists (`errors[0].series_id`), a later step failed; repeat with the same key."
          }
        }
      }
    },
    "/v1/shift-series/{id}/people": {
      "post": {
        "summary": "Change the people of a shift series, for a period or for good",
        "description": "Requires scope `shifts:write` and the Update right on time tracking.\n`{id}` is the `series_id` of a shift (GET /v1/shifts); the id of a\nday that was changed separately leads to its series. The two ways of\nthe portal dialog \"Für wie lange gilt die Einplanung?\":\n\n- **Period** (`from` and `to`, both inclusive, days in the time zone\n  of the property; `from` today or later, else\n  `422 SERIES_PERIOD_IN_PAST`; a shift of the period that has already\n  begun answers `422 SERIES_SHIFT_BEGUN`): only the planned shifts of those days change,\n  each as a day of its own; the series itself keeps its people and\n  goes on with them after `to`. Shifts with recorded time are left\n  as they are (`shifts_skipped_with_checkins`). Only shifts that\n  exist are changed (LiteLog creates them 90 days ahead); at most\n  200 shifts per call (`422 SERIES_PERIOD_TOO_LARGE`).\n- **From a day on, for good** (`from` alone; neither = from today):\n  LiteLog splits the series, as \"edit from a date\" in the portal. The\n  old series ends the day before and keeps its people; a new series\n  (`new_series_id`, same settings) goes on with the new people. Its\n  shifts already planned move to the new series with their ids;\n  nothing is deleted. Days changed separately keep their own people\n  (`days_changed_separately`). Past shifts and shifts with recorded\n  time stay with the old series: without dates the new series starts\n  the day after the last shift that has begun; with `from` and a\n  begun shift on or after it → `422 SERIES_SHIFT_BEGUN`. A series\n  with no shift before that day is changed in place\n  (`new_series_id: null`). The answer's `from` is the first day of\n  the rhythm on or after the requested day. No shift ahead →\n  `422 SERIES_ENDED`; if the series goes on as a later version,\n  `errors[0]` names `next_series_id` and `next_first_day`. A series\n  with several time settings → `422 SERIES_SPLIT_NOT_SUPPORTED`\n  (change it in the portal).\n\n`last_shift_day` names the last day the series has a shift for, and\n`next_version` a later version of the series (its settings were\nchanged from a date on; that version has its own `series_id` and is\nnot changed by this call).\n\nThe people are notified as in the portal; `notify: false` switches\nthat off. Refusals, before anything is written: `403` property\nunknown or outside the key's restriction, the key sees only its own\npeople, or `quota_exceeded`; `404` the series does not belong to this\nproperty or company; `409 ASSIGNEE_NO_PROPERTY_ACCESS` a person to add\n(from a day on: any person of the new list) is unknown or has no\naccess to the property; `422 NOT_A_SERIES` the id is a single shift\n(use PATCH /v1/shifts/{id}).\n",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "`series_id` of a shift of the series."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "property_id"
                ],
                "properties": {
                  "property_id": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "Property of the series."
                  },
                  "add_account_ids": {
                    "type": "array",
                    "maxItems": 100,
                    "uniqueItems": true,
                    "items": {
                      "type": "integer",
                      "minimum": 1
                    }
                  },
                  "remove_account_ids": {
                    "type": "array",
                    "maxItems": 100,
                    "uniqueItems": true,
                    "items": {
                      "type": "integer",
                      "minimum": 1
                    }
                  },
                  "from": {
                    "type": "string",
                    "format": "date",
                    "description": "First day: with `to` the period; alone = from that day on, for good. Today or later."
                  },
                  "to": {
                    "type": "string",
                    "format": "date",
                    "description": "Last day of the period (inclusive); needs `from`."
                  },
                  "notify": {
                    "type": "boolean",
                    "description": "false = the people are not told. Default true."
                  }
                }
              },
              "example": {
                "property_id": 12,
                "add_account_ids": [
                  35
                ],
                "remove_account_ids": [
                  34
                ],
                "from": "2027-01-04",
                "to": "2027-01-15"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "What changed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ShiftSeriesPeopleChange"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Property unknown or outside the key's restriction, the key sees only its own people, or `quota_exceeded`."
          },
          "404": {
            "description": "Series not found for this property."
          },
          "409": {
            "description": "`ASSIGNEE_NO_PROPERTY_ACCESS`."
          },
          "422": {
            "description": "Validation failure (at least one person; `to` needs `from`), `NOT_A_SERIES`, `SERIES_PERIOD_TOO_LARGE`, `SERIES_PERIOD_IN_PAST`, `SERIES_SHIFT_BEGUN`, `SERIES_ENDED` or `SERIES_SPLIT_NOT_SUPPORTED`."
          }
        }
      }
    },
    "/v1/shifts/auto-assign": {
      "post": {
        "summary": "Propose a roster for open shifts (automatic planning)",
        "description": "Requires scope `shifts:read`, the package feature `planner_automation`\n(else `403 ENTITLEMENT_MISSING`) and the Update right on time tracking\n— the answer names colleagues and plans their times. Same solver as\n\"Auto-assign\" in the portal shift planner: open or understaffed\nshifts of the given properties in the window, respecting absences,\ndouble bookings, qualifications, rest periods and contract hours.\nSaves nothing. At most 20 properties and 31 days. Unknown properties,\nproperties of other tenants and properties outside the key's property\nrestriction answer alike with 404. `503 SOLVER_UNAVAILABLE` when the\nplanning service is not reachable.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "property_ids",
                  "from",
                  "to"
                ],
                "properties": {
                  "property_ids": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 20,
                    "items": {
                      "type": "integer",
                      "minimum": 1
                    }
                  },
                  "from": {
                    "type": "string",
                    "format": "date"
                  },
                  "to": {
                    "type": "string",
                    "format": "date",
                    "description": "At most 31 days after `from`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { window: {from, to}, proposals: [{shift_uuid,\nproperty_id, property_name, start_ts, end_ts, account_id,\naccount_name}], unassigned: [{shift_uuid, property_id,\nproperty_name, start_ts, end_ts, missing, reason,\nunfilled_qualifications: [{qualification_id, missing}]}],\naccounts_without_schedule: [{account_id, name}], stats: {status,\nsolve_ms, candidates}, solver_degraded } }`\n"
          },
          "400": {
            "description": "Invalid window."
          },
          "403": {
            "description": "Missing scope, feature or right."
          },
          "404": {
            "description": "Property not found."
          },
          "503": {
            "description": "SOLVER_UNAVAILABLE."
          }
        }
      }
    },
    "/v1/shifts/auto-assign/apply": {
      "post": {
        "summary": "Apply roster assignments",
        "description": "Requires scope `shifts:write`, the package feature\n`planner_automation` and the Update right on time tracking. Adds the\ngiven people to their shifts (never removes anyone), through the same\npath as the portal: every guard and assignment event applies. Shifts\noutside the key's property restriction, unknown shifts, shifts that\nare no longer scheduled or already have check-ins, people not\nassignable to the property and people already planned are skipped\nwith a reason. At most 200 assignments.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "assignments"
                ],
                "properties": {
                  "assignments": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 200,
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "shift_uuid",
                        "account_id"
                      ],
                      "properties": {
                        "shift_uuid": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "account_id": {
                          "type": "integer",
                          "minimum": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { applied: [{shift_uuid, property_id, property_name,\nstart_ts, end_ts, account_ids[]}], skipped: [{shift_uuid, reason}]\n} }` — reasons: `not_found`, `not_scheduled`, `has_checkins`,\n`account_not_assignable`, `already_assigned`.\n"
          },
          "403": {
            "description": "Missing scope, feature or right."
          }
        }
      }
    },
    "/v1/shifts/conflicts": {
      "get": {
        "summary": "Planning warnings (soft — never blocks)",
        "description": "Requires scope `shifts:read` AND a key role with\n`VIEW_TIME_TRACKING_OTHERS` (or TimeTracking update rights) — the\nanswer names conflicts of arbitrary employees, mirroring the internal\nplanner gate. Mirrors the portal's planning checks for\na hypothetical assignment window: `conflicts` = overlapping planned\nshifts and absences per employee, `arbzg` = German working-time-law\nwarnings (rest period < 11h, day total > 10h, ISO-week total > 48h;\nevaluated server-side across ALL planned shifts of the tenant),\n`weekly` (only with `property_ids`) = weekly visit count vs. the\nproperty's `wt_max_visits_per_week` limit. `checked_until` marks the\ngenerator horizon — beyond it an empty result is not proof of\nno conflict. At least one of `account_ids`/`property_ids` (CSV of\nids) is required.\n",
        "parameters": [
          {
            "name": "account_ids",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "CSV of employee account ids."
          },
          {
            "name": "property_ids",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "CSV of property ids — adds the `weekly` visit-limit counts."
          },
          {
            "name": "start_ts",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "end_ts",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "exclude_shift_uuid",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Excludes an existing shift (edit flows) from all checks."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { conflicts: [{account_id, property_name, start_ts,\nend_ts, kind: shift|absence, status?}], arbzg: [{account_id,\nrule: restPeriod|dailyHours|weeklyHours, detail}],\nchecked_until, weekly?: [{property_id, count, limit}] } }`\n"
          }
        }
      }
    },
    "/v1/shifts/target-actual": {
      "get": {
        "summary": "Target vs. actual hours per employee (payroll pre-check)",
        "description": "Requires scope `shifts:read` AND the time-tracking view/update gate\n(the rows name planned/actual/contract hours of arbitrary\ncolleagues). Mirrors the portal's Soll/Ist view: `planned_ms` = sum\nof assigned, non-cancelled shift instances (bucketed by shift START\nday in the property's timezone — night shifts count fully on their\nstart day), `actual_ms` = recorded work time (open entries count up\nto now, account timezone), `contract_ms` = contract target from the\nwork-schedule model, absence-adjusted (`null` = no model\nmaintained), `balance_ms` = cumulative time-account balance up to\n`to`. Rows are the UNION of both sides. Range max 366 days.\nCustomer accounts are blocked (403).\n",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "property_ids",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "CSV of property ids — restricts the planned side."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{account_id, name, planned_ms, planned_shifts,\nactual_ms, actual_entries, contract_ms, balance_ms}] }`\n"
          },
          "403": {
            "description": "Key account lacks the view/update gate."
          }
        }
      }
    },
    "/v1/shifts/work-days": {
      "get": {
        "summary": "Target, plan and actual per person and calendar day",
        "description": "Requires scope `shifts:read` AND the time-tracking view/update gate\n(the rows name hours and absences of arbitrary colleagues). The day\nrows behind the totals of `/v1/shifts/target-actual`: one row per\nperson and day with contract target, planned shift time and recorded\ntime — the query of the portal page \"Arbeitstage\". `from`/`to` are\ncalendar days (end day included), range max 62 days; `page`/`pageSize`\ncount rows. With `property_id` plan and actual are narrowed to the\nproperty and days that only carry a contract target or an absence are\ndropped (they belong to the person, not to the property); the same\nholds for a key restricted to properties. Scoped like the shifts:\nproperty restriction of the key and its person scope.\nCustomer accounts are blocked (403).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged day rows, newest day first, then by name.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WorkDay"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "pageSize": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Key account lacks the view/update gate, or no access to the property."
          },
          "404": {
            "description": "The person is not in the tenant or outside the person scope of the key."
          }
        }
      }
    },
    "/v1/shifts/attendance": {
      "get": {
        "summary": "Planned vs. actual attendance of every shift in a range",
        "description": "Requires scope `shifts:read`. The same data as `GET /v1/shifts` plus\none `GET /v1/shifts/{id}/attendance` per shift, in one paged read:\nper shift the planned people and everyone who clocked in, merged\n(`missing` = planned without a valid entry, `planned: false` = came\nunplanned). `from`/`to` are calendar days in the timezone of each\nproperty (end day included), range max 92 days. Paged by shift.\nSame guards as `GET /v1/shifts`: property restriction of the key and\nits person scope (a subcontractor key sees only its own people, on\nthe planned and on the actual side).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "Only shifts this employee is planned for."
          },
          {
            "name": "include_cancelled",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged list of shifts with their attendance.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ShiftAttendance"
                      }
                    },
                    "total": {
                      "type": "integer",
                      "description": "Number of shifts in the range."
                    },
                    "page": {
                      "type": "integer"
                    },
                    "pageSize": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/shifts/{id}": {
      "get": {
        "summary": "Get a shift",
        "description": "Requires scope `shifts:read`. Follows the key account's person\nscope: a key of a subcontractor account (role `own_only`) only sees\nshifts with itself and its own employees (404 otherwise) — the same\nrule as `GET /v1/accounts`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Shift detail."
          }
        }
      },
      "patch": {
        "summary": "Update a shift instance",
        "description": "Requires scope `shifts:write`. Same fields as create (minus\nseries_id/property_id); start/end must change together — the check-in/\nout windows are then re-anchored to the new span unless set explicitly.\nChanging config-level fields (requirement modes, staffing) detaches the\ninstance from its series automatically, so the change never leaks into\nother instances. Shifts with existing check-ins or status other than\n`scheduled` cannot be edited (400). `required_qualifications` replaces\nthe whole demand (null / [] clears it) and must fit the EFFECTIVE\nheadcount — a patch with only one of `required_headcount` /\n`required_qualifications` is checked against the stored shift\n(`422 QUALIFICATION_DEMAND_EXCEEDS_HEADCOUNT` /\n`QUALIFICATION_DEMAND_NEEDS_HEADCOUNT`).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated shift."
          },
          "422": {
            "description": "Qualification demand does not fit the staffing target (`error` names the reason)."
          }
        }
      },
      "delete": {
        "summary": "Cancel a shift (status → cancelled)",
        "description": "Requires scope `shifts:write`. Planned shifts are never hard-deleted —\nDELETE cancels. Shifts with existing check-ins answer 409.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ cancelled: true }`."
          },
          "409": {
            "description": "Shift already has check-ins."
          }
        }
      }
    },
    "/v1/shifts/{id}/replacements": {
      "get": {
        "summary": "Suggest replacements for one shift (who can step in)",
        "description": "Requires scope `shifts:read`, the package feature `planner_automation`\n(else `403 ENTITLEMENT_MISSING`) and `VIEW_TIME_TRACKING_OTHERS` (or\nthe Update right on time tracking) — the answer names colleagues.\nSame ranking as the planner: available people of the property (not on\nthe shift, not double-booked, not absent), ordered by fit — works at\nthe property, weekly load, time-account balance, required\nqualification — with working-time warnings (`restPeriod`,\n`dailyHours`, `weeklyHours`). Per candidate\n`missing_qualification_ids` lists the OPEN qualifications of the\nshift (its `required_qualifications` minus what the assigned people\nhold) the person does not hold; `has_required_qualification` is true\nwhen the person covers at least one open slot or none is open.\n`only_qualified=true` keeps only candidates who cover an open slot;\nthe others count in `excluded_counts.unqualified`. The answer NEVER\nsays why someone is unavailable; absences and double bookings only\ncount in `excluded_counts.unavailable`. Only scheduled shifts without\ncheck-ins (else 400). Unknown shifts and shifts of other tenants → 404,\na shift outside the key's property restriction → 403.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 20,
              "default": 10
            }
          },
          {
            "name": "only_qualified",
            "in": "query",
            "description": "`true` = only people who cover an open qualification slot of the shift (everyone when none is open).",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { shift: {uuid, property_id, start_ts, end_ts,\nrequired_headcount, assigned_count, open_count, past,\ninherent_warnings[]}, candidates: [{account_id, name,\nworks_at_property, planned_week_hours, time_balance_hours,\nhas_required_qualification, missing_qualification_ids[],\nwarnings[], prefers_shift_time}], excluded_counts:\n{pool, already_on_shift, unavailable, unqualified} } }`\n`prefers_shift_time` = the person entered this time as preferred;\nblocked times (availability) count in `unavailable`.\n"
          },
          "400": {
            "description": "Shift is not scheduled or already has check-ins."
          },
          "403": {
            "description": "Missing scope, feature, right or property access."
          },
          "404": {
            "description": "Shift not found."
          }
        }
      }
    },
    "/v1/shifts/{id}/attendance": {
      "get": {
        "summary": "Actual attendance on a shift",
        "description": "Requires scope `shifts:read`. Who checked in/out, with timing verdicts\n(SOLL/IST view — planned staffing lives on the shift's `assignees`).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Attendance rows.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ShiftAttendanceRow"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/shifts/{id}/checkins": {
      "post": {
        "summary": "Check employees into a shift (live or retro)",
        "description": "Requires scope `shifts:write`. Live (shift running): omit `end_ts` —\nemployees without an open work-time entry get one created. Retro\n(shift completed): `start_ts` AND `end_ts` are required and must lie\nwithin the shift's allowed window; closed entries are created.\nAccounts not assigned to the shift's property are rejected and\nreported in `rejected_account_ids`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "account_ids"
                ],
                "additionalProperties": false,
                "properties": {
                  "account_ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "maxItems": 100
                  },
                  "start_ts": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "end_ts": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ checked_in, rejected_account_ids }`."
          }
        }
      }
    },
    "/v1/time-entries": {
      "get": {
        "summary": "List work-time entries",
        "description": "Requires scope `time_entries:read`. `status=open` = running entries\n(end_ts null), `status=closed` = finished. `shift_uuid` scopes to one\nplanned shift and cannot be combined with from/to/property_id.\n`linked=false` = only entries on NO planned shift, `linked=true` =\nonly entries on a shift (not together with `shift_uuid`); why an\nentry stayed without a shift: `GET /v1/time-entries/link-events`.\n`from`/`to` filter on the entry START (half-open interval).\nThe list follows the key account's person scope: a key of a\nsubcontractor account (role `own_only`) only sees itself and its\nown employees — the same rule as `GET /v1/accounts`.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "closed"
              ]
            }
          },
          {
            "name": "shift_uuid",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "linked",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "description": "true = only entries linked to a shift, false = only entries without one."
          }
        ],
        "responses": {
          "200": {
            "description": "Paged entry list.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TimeEntry"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "pageSize": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a closed work-time entry (manual booking)",
        "description": "Requires scope `time_entries:write`. Durations are server-computed\nfrom start/end/pause; the property's minimum-pause rules are\nenforced. Overlapping entries answer `409 DUPLICATE_WORKTIME`\n(override with `allow_overlap: true` — audited). `shift_uuid` links\nthe entry to a planned shift of the same property.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "account_id",
                  "property_id",
                  "start_ts",
                  "end_ts"
                ],
                "additionalProperties": false,
                "properties": {
                  "account_id": {
                    "type": "integer"
                  },
                  "property_id": {
                    "type": "integer"
                  },
                  "start_ts": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "end_ts": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "pause_ms": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "shift_uuid": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "allow_overlap": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created entry."
          },
          "409": {
            "description": "DUPLICATE_WORKTIME — overlapping entry exists."
          }
        }
      }
    },
    "/v1/time-entries/link-events": {
      "get": {
        "summary": "Why a work-time entry was not linked to a shift",
        "description": "Requires scope `time_entries:read`. The Zuordnungs-Protokoll: every\nrejected or failed attempt to link an entry to a planned shift, and\nentries put on a cancelled shift — newest first. `from`/`to` are\ncalendar days in the timezone of the property (end day included),\nrange max 31 days. Scoped like the entries themselves: property\nrestriction of the key and its person scope. Linking rules: same\nproperty; the person is assigned to the property; the clock-in lies\nat most 4 hours from the shift start, not earlier than one shift\nlength (max 6 hours) before it — a later arrival still counts while\nat least 2 hours of the shift lie ahead; cancelled shifts do not count.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "event",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "threshold_rejected",
                "no_candidate_nearby",
                "live_link_failed",
                "linked_to_cancelled"
              ]
            }
          },
          {
            "name": "linked",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "description": "State of the entry TODAY. `false` = only rows whose entry is still\nwithout a shift (or was not found) — the rows worth a look.\n`true` = only rows whose entry hangs on a shift by now.\n"
          }
        ],
        "responses": {
          "200": {
            "description": "Paged event list.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/LinkEvent"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "pageSize": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/time-entries/link-rules": {
      "get": {
        "summary": "The linking rules as data",
        "description": "Requires scope `time_entries:read`. The distances and windows by which\nan entry is linked to a planned shift — the same constants the server\nlinks with, so a client does not have to guess border cases. No\nparameters, no tenant data.\n",
        "responses": {
          "200": {
            "description": "The rules.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/LinkRules"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/time-entries/edit-events": {
      "get": {
        "summary": "Who changed which work-time entry, when and why",
        "description": "Requires scope `time_entries:read` AND the time-tracking view/update\ngate (the rows name changes to entries of arbitrary colleagues). The\nÄnderungsverlauf: every edit, deletion, late booking and release of an\nentry with old and new values, the reason and who did it — newest\nfirst. Either a period (`from`/`to`, calendar days in the timezone of\nthe property, end day included, max 31 days) or ONE entry over its\nwhole life (`time_entry_uuid`, then `from`/`to` may be left out), or\nboth. Scoped like the entries themselves: property restriction of the\nkey and its person scope. A key restricted to properties or persons\nonly sees rows whose entry still exists.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Required unless `time_entry_uuid` is set. Only together with `to`."
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "time_entry_uuid",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "Person of the entry (not who made the change)."
          },
          {
            "name": "event",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "edited",
                "deleted",
                "bulk_deleted",
                "sublogs_cleared",
                "overlap_override",
                "confirmed",
                "unconfirmed",
                "confirm_dropped",
                "created"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged event list.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/EditEvent"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "pageSize": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Key account lacks the view/update gate, or no access to the property."
          },
          "404": {
            "description": "The person is outside the person scope of the key."
          }
        }
      }
    },
    "/v1/time-entries/clock-in": {
      "post": {
        "summary": "Clock in (start a running entry)",
        "description": "Requires scope `time_entries:write`. Deterministic — never a toggle:\nANY already-open entry of the account — regardless of property —\nanswers `409 ALREADY_CLOCKED_IN` (one presence at a time; switch\nproperties by clocking out first). `timestamp` defaults to now.\nA start outside the property's execution windows or inside a blocked\ntime window answers `409 RESTRICTED_TIME` with\n`errors[0].reason` (`outside_window` | `restricted_time`) and\n`errors[0].next_start` (`{ date, time }`, wall clock of the property).\nManual entries via POST /v1/time-entries are still accepted but\nflagged in the verification trail.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "account_id",
                  "property_id"
                ],
                "additionalProperties": false,
                "properties": {
                  "account_id": {
                    "type": "integer"
                  },
                  "property_id": {
                    "type": "integer"
                  },
                  "timestamp": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "lat": {
                    "type": "number"
                  },
                  "lng": {
                    "type": "number"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The running entry."
          },
          "409": {
            "description": "ALREADY_CLOCKED_IN, DUPLICATE_WORKTIME or RESTRICTED_TIME (outside execution windows / blocked time window; `errors[0].next_start`)."
          }
        }
      }
    },
    "/v1/time-entries/clock-out": {
      "post": {
        "summary": "Clock out (close the running entry)",
        "description": "Requires scope `time_entries:write`. No open entry answers\n`409 NOT_CLOCKED_IN`. Durations incl. enforced minimum pause are\ncomputed on close. Same body as clock-in.\n",
        "responses": {
          "200": {
            "description": "The closed entry."
          },
          "409": {
            "description": "NOT_CLOCKED_IN."
          }
        }
      }
    },
    "/v1/time-entries/{id}": {
      "get": {
        "summary": "Get a work-time entry incl. timeline",
        "description": "Requires scope `time_entries:read`. Follows the key account's person\nscope: a key of a subcontractor account (role `own_only`) only sees\nentries of itself and its own employees (404 otherwise) — the same\nrule as `GET /v1/accounts`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Entry detail.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/TimeEntryDetail"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Correct start/end/pause of an entry",
        "description": "Requires scope `time_entries:write`. Only start_ts/end_ts/pause_ms —\naccount/property reassignment is not supported (delete + recreate).\nDurations are recomputed, minimum pause enforced, overlaps answer 409,\nevery change lands in the work-time audit log. Optional `reason`\n(string, max 500) documents WHY the entry was corrected and is stored\nin the audit trail; without it the audit records `public_api`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated entry."
          }
        }
      },
      "delete": {
        "summary": "Delete an entry (soft delete)",
        "description": "Requires scope `time_entries:write`. Audited.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ deleted: true }`."
          }
        }
      }
    },
    "/v1/work-orders": {
      "get": {
        "summary": "List work orders (Kundenaufträge)",
        "description": "Requires scope `work_orders:read` and a key role with customer read\nrights (`VIEW_CUSTOMERS`) — work-order payloads always carry prices,\nmirroring the internal customer gate. Optional filters `status`\n(open|completed|billed), `customer_id`, `property_id` and `q`\n(case-insensitive title substring); paginated via\n`page`/`limit` (default 50, max 200). Rows include customer_name,\nproperty_name, the execution task (task_uuid, task_completed_at)\nand net_total_cents over the billing positions.\n",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "completed",
                "billed"
              ]
            }
          },
          {
            "name": "customer_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Case-insensitive substring match on the order title.",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: WorkOrder[], total }`."
          }
        }
      },
      "post": {
        "summary": "Create a work order",
        "description": "Requires scope `work_orders:write`. Body: customer_id (required),\nproperty_id?, title, description?, positions[] (billing positions:\nkind service|material|travel|custom, title, unit, unit_price_cents,\ntax_rate %, quantity — omit/null = \"by effort\", resolved from\nactuals on completion) and task? (creates the execution task:\ntitle?, description?, due_date?, assignee_account_ids[],\nmaterials[] {item_id, expected_qty}). Customer/property/material\nreferences are tenant-guarded.\n",
        "responses": {
          "201": {
            "description": "`{ uuid }` of the created order."
          },
          "404": {
            "description": "Unknown customer/property (tenant guard)."
          }
        }
      }
    },
    "/v1/work-orders/{id}": {
      "get": {
        "summary": "Get a work order incl. billing positions",
        "description": "Requires scope `work_orders:read`.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Work order with positions[]."
          },
          "404": {
            "description": "Not found (tenant guard)."
          }
        }
      },
      "patch": {
        "summary": "Update title/description/property/positions",
        "description": "Requires scope `work_orders:write`. Billed, approved and completed\norders are immutable (409; error codes `approved_locked` /\n`completed_locked`). `positions` replaces the whole set when present.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ success: true }`."
          },
          "409": {
            "description": "Billed/approved/completed orders are immutable (codes `approved_locked`, `completed_locked`)."
          }
        }
      },
      "delete": {
        "summary": "Delete a work order",
        "description": "Requires scope `work_orders:write`. Billed, approved and completed\norders answer 409 (codes `approved_locked` / `completed_locked`).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ success: true }`."
          },
          "409": {
            "description": "Billed/approved/completed orders are immutable (codes `approved_locked`, `completed_locked`)."
          }
        }
      }
    },
    "/v1/work-orders/{id}/actuals": {
      "get": {
        "summary": "Actuals collected via the execution task",
        "description": "Requires scope `work_orders:read`. Aggregates recorded service\npositions (minutes/quantity per service type, via the task's\ncompletions) and consumed material (material movements\nreason=consume with the latest unit_price_cents snapshot) plus the\ncompletions count — the basis for resolving \"by effort\" quantities.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ total_service_minutes, services[], materials[], completions }`."
          }
        }
      }
    },
    "/v1/work-orders/{id}/complete": {
      "post": {
        "summary": "Complete a work order (freeze final positions)",
        "description": "Requires scope `work_orders:write`. Body: positions[] with RESOLVED\nquantities (quantity required per position, at least one position).\nReplaces the position set as the final snapshot and sets status\ncompleted. Only open orders can be completed: already completed\norders answer 409 `already_completed`, approved orders 409\n`approved_locked`, an empty positions array 409 `empty_positions`,\nbilled orders 409. Invoice hand-over (e.g. Lexoffice) is prepared\nbut not part of this API: positions are stored net with unit, unit\nprice (cents) and tax rate.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ success: true }`."
          },
          "409": {
            "description": "Not completable (codes `already_completed`, `approved_locked`, `empty_positions`; billed orders are immutable)."
          }
        }
      }
    },
    "/v1/absences": {
      "get": {
        "summary": "List absences (vacation, sick leave etc.)",
        "description": "Requires scope `shifts:read` (absences are part of the workforce/\nroster domain — no separate scope). GDPR Art. 9: the absence `type`,\n`note`, `decision_note` and `created_by_account_id` are health-related\nand are only delivered when the key's role carries the update gate for\ntime tracking — read-only keys see `type: null` (\"absent\"). Without\nthe view-others permission the list is silently narrowed to the key's\nown account. A `type` filter without the update gate answers 403.\nCustomer-access keys answer 403 (internal staff surface).\n",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "approved",
                "rejected",
                "withdrawn"
              ]
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Absence type (vacation, sick, time_off_in_lieu, child_sick, maternity_leave, parental_leave, education_leave, special_leave, unpaid_leave, other) — requires the update gate (403 otherwise)."
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Overlap filter — absences overlapping [from, to]. An existing calendar day (YYYY-MM-DD); `2026-02-31` answers 422 (since 06.11.2026)."
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Existing calendar day, not before `from`."
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "name": "pageSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{absence_id, account_id, account_name, type,\nstart_date, end_date, status, note, created_by_account_id,\ndecided_by, decided_at, decision_note, extends_absence_id,\ncreated_at}], total }`\n"
          }
        }
      },
      "post": {
        "summary": "Report an absence for an employee",
        "description": "Requires scope `shifts:write` and the time-tracking update gate.\nStatus is ALWAYS `pending` — approval runs via\n`/v1/absences/{id}/decide`, also for manager-created entries.\n`extends_absence_id` chains an extension to an approved predecessor.\nThe response lists overlapping existing absences of the same person\nas a HINT (`overlaps`) — overlaps never block.\nSince 06.11.2026: `start_date`/`end_date` must be existing calendar\ndays (`2026-02-31` answers 422, no longer 500) and one absence spans\nat most 366 days (`start_date..end_date`, both inclusive). Record a\nlonger absence as a chain: a new absence with `extends_absence_id`\npointing at the approved predecessor. No per-type rule here — the\n31-day cap for sick leave applies only to the employee's self-report\nin the app.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "account_id",
                  "type",
                  "start_date",
                  "end_date"
                ],
                "additionalProperties": false,
                "properties": {
                  "account_id": {
                    "type": "integer"
                  },
                  "type": {
                    "type": "string",
                    "description": "vacation, sick, time_off_in_lieu, child_sick, maternity_leave, parental_leave, education_leave, special_leave, unpaid_leave, other"
                  },
                  "start_date": {
                    "type": "string",
                    "format": "date",
                    "description": "First day — an existing calendar day (YYYY-MM-DD)."
                  },
                  "end_date": {
                    "type": "string",
                    "format": "date",
                    "description": "Last day — an existing calendar day, not before start_date; span start_date..end_date at most 366 days (both inclusive)."
                  },
                  "note": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000
                  },
                  "extends_absence_id": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ data: absence, overlaps: [absence] }`."
          },
          "404": {
            "description": "Employee not in tenant or archived."
          },
          "422": {
            "description": "Validation (unknown field, unknown `type`); `start_date`/`end_date` is no existing calendar day (`errors[].path` names the field — a 500 until 06.11.2026); `end_date` before `start_date`; span over 366 days (`errors[].path = [end_date]`, the message names the limit). A wrong format yields exactly one issue per field."
          }
        }
      }
    },
    "/v1/absences/{id}": {
      "get": {
        "summary": "Get an absence",
        "description": "Requires scope `shifts:read`. Same Art. 9 gating AND the same\nself-scoping as the list: without `VIEW_TIME_TRACKING_OTHERS` (or\nTimeTracking update rights) only the key account's own absences\nresolve — foreign ids answer 404.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Absence detail."
          }
        }
      },
      "put": {
        "summary": "Correct a still-pending absence",
        "description": "Requires scope `shifts:write` and the time-tracking update gate.\nFull field set (type, start_date, end_date, note) — the person and\nthe extension link stay fixed; a report rewritten to someone else is\na different report. Only `pending` reports are editable: decided ones\nanswer 409 (\"revoke + recreate\" applies). The response lists\noverlapping absences of the same person as a HINT (`overlaps`,\nexcluding the edited row) — overlaps never block.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "type",
                  "start_date",
                  "end_date"
                ],
                "additionalProperties": false,
                "properties": {
                  "type": {
                    "type": "string"
                  },
                  "start_date": {
                    "type": "string",
                    "format": "date",
                    "description": "First day — an existing calendar day (YYYY-MM-DD); since 06.11.2026."
                  },
                  "end_date": {
                    "type": "string",
                    "format": "date",
                    "description": "Last day — an existing calendar day, not before start_date; span start_date..end_date at most 366 days (both inclusive); since 06.11.2026."
                  },
                  "note": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: absence, overlaps: [absence] }`."
          },
          "409": {
            "description": "Absence already decided."
          },
          "422": {
            "description": "Validation (unknown field, unknown `type`); `start_date`/`end_date` is no existing calendar day (`errors[].path` names the field — a 500 until 06.11.2026); `end_date` before `start_date`; span over 366 days (`errors[].path = [end_date]`, the message names the limit)."
          }
        }
      }
    },
    "/v1/absences/{id}/decide": {
      "post": {
        "summary": "Approve or reject an absence",
        "description": "Requires scope `shifts:write` and the time-tracking update gate.\nAllowed transitions: `pending → approved|rejected` and\n`approved → rejected` (revoke); anything else answers 409 (stale\nstate). Rejecting requires `decision_note` (min 5 characters).\n`unassign: true` on approval removes the person from the staffing of\naffected planned shifts (per-day overrides) from max(today,\nstart_date); the response reports `unassigned_days`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: absence, unassigned_days }`."
          },
          "409": {
            "description": "Transition not allowed from the current status."
          }
        }
      }
    },
    "/v1/patrols": {
      "get": {
        "summary": "List patrol runs (planned routes + free patrols + tour runs)",
        "description": "Requires scope `patrols:read`. Read-only logbook surface: `planned`\nrows are instances of configured routes (`start_ts`/`end_ts` = the\nscheduled window, `done`/`attempts_*` = the outcome), `free` rows are\nad-hoc patrols (effective start/end, `attempts_*` null), `tour` rows\nare runs of a cross-property tour (`TourRun`: `property_id` null,\nplus `uuid`, `tour_uuid`, `tour_name`, `status`, `stops_total`,\n`stops_done`). `from`/`to` filter on the run start. `done=false` on\nplanned runs includes runs whose window is still open.\nProperty-restricted key accounts only see runs on accessible\nproperties; a tour run is visible only when EVERY stop property is\naccessible. `property_id` on tour rows = at least one stop at that\nproperty. Free patrols that were archived in the portal are left out\nof this list; `GET /v1/patrols/free/{id}` still returns them.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "planned",
                "free",
                "tour"
              ]
            }
          },
          {
            "name": "done",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "outcome",
            "in": "query",
            "description": "Only planned runs with this outcome (combined with `kind=free` or `kind=tour` → 422).\n`missed` = window over, no round finished; `incomplete` = some but\nnot all rounds finished; `overdue` = window over and not done\n(includes `missed`).\n",
            "schema": {
              "type": "string",
              "enum": [
                "missed",
                "incomplete",
                "overdue"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged list: `{ data: [{kind, id, property_id, property_name, route_id, route_name, start_ts, end_ts, done, attempts_finished, attempts_total}], total, page, pageSize }`. A run is identified by the PAIR (kind, id). Rows with `kind: tour` additionally carry `uuid, tour_uuid, tour_name, status, stops_total, stops_done` (schema `TourRun`) and are addressed by `uuid` in GET /v1/patrols/tour/{uuid}.\n"
          },
          "422": {
            "description": "`outcome` combined with `kind=free` or `kind=tour`."
          }
        }
      }
    },
    "/v1/patrols/checkpoint-coverage": {
      "get": {
        "summary": "Checkpoint coverage per property and day",
        "description": "Requires scope `patrols:read`. Which control points were scanned on\nwhich day and which were missed, per property. `from`/`to` are days\n(YYYY-MM-DD) in the key account's time zone. A `to` after today is\ncut to today (so \"this week\" works on any weekday); after that at most\n14 days including `from`, not starting in the future — otherwise 422\nwith `reason: RANGE_TOO_LARGE` / `RANGE_INVALID`. Property-restricted keys\nonly see accessible properties; an explicit `property_id` outside the\nrestriction → 403. `last_scanned_by_name` is only filled when the key\naccount may see other people's times (else only for its own scans).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "only_missed",
            "in": "query",
            "description": "true (default) = `points` lists only the points below their target (`scan_count < target`); with the default target of 1 these are the points without a scan.",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{date, property_id, property_name, scanned_count,\nmissed_count, total_count, target, reached_count, points:\n[{tag_id, name, scan_count, reached, last_scan_at,\nlast_scanned_by_name}]}], total, page, pageSize,\nsummary: {scan_count, point_count, reached_count, property_day_count,\ndays: [{date, scan_count, point_count, reached_count, property_count}]} }`.\n`target` = scans each control point needs per day (set on the\nproperty, 1 by default); `reached_count` = control points that\nreached it — the figure the portal shows as \"x of y reached\".\nOne row = one property on one day; `summary` covers the completed\ndays of the range. The running day (today in the account's time\nzone) keeps its row and its entry in `summary.days`, but is not\ncounted in the totals of `summary`.\n"
          },
          "403": {
            "description": "Missing scope, or `property_id` outside the key's restriction."
          },
          "422": {
            "description": "`reason: RANGE_TOO_LARGE` or `RANGE_INVALID`"
          }
        }
      }
    },
    "/v1/patrols/{kind}/{id}": {
      "get": {
        "summary": "Patrol run detail incl. the device-reported event stream (or the stop timeline of a tour run)",
        "description": "Requires scope `patrols:read`. For `planned` and `free`: same fields\nas the list row plus `events`: the chronological event stream as\nreported by the device — lifecycle events (`STARTED`, `DONE`,\n`CANCELED`, `TIMEOVER`) and checkpoint scans\n(`TAG_SCAN_TAG|QR|BEACON|PHOTO|GPS`; `msg` carries the checkpoint\nlabel on planned-route scans). Each event has `timestamp`,\n`account_id`/`account_name`, `latitude`/`longitude` (device-reported,\nmay be null) and `source`.\n\nFor `tour` the `id` is the run's `uuid` (from the list row) and the\nanswer is the run head (`tour_uuid`, `tour_name`, `order_mode`,\n`status`, `start_ts`/`end_ts`, `started_at`/`finished_at`,\n`started_by_name`, `acknowledged_at`, `stops_total`, `stops_done`)\nplus `stops[]` — the stop timeline in stop order (`TourRunStop`:\narrival/departure, source, skipped reason, task counters, the\n`route_log_id` of a stop's patrol run). A run of a tour with a stop\nproperty outside the key's restriction answers 404.\n",
        "parameters": [
          {
            "name": "kind",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "planned",
                "free",
                "tour"
              ]
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Numeric run id for `planned`/`free`; the run `uuid` for `tour`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { …list row…, events: [...] } }` for planned/free; `{ data: { …TourRun head…, stops: TourRunStop[] } }` for tour."
          },
          "404": {
            "description": "Run not visible for this key."
          }
        }
      }
    },
    "/v1/bookings": {
      "get": {
        "summary": "List bookings (holiday properties)",
        "description": "Requires scope `bookings:read` and role right Read Property. Stays of\nthe connected booking calendars in a window of days: default today\n(Europe/Berlin) plus 60 days, at most 92 days — otherwise 422\n`reason: RANGE_TOO_LARGE`; `to` before `from` → `RANGE_INVALID`.\n`kind`: `arrivals` = check-in in the window, `departures` = check-out\nin the window, `all` (default) = every stay touching the window. No\nguest names, no booking-portal ids. `property_id` outside the key's\nrestriction → 403. Customer accounts → 403.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "cancelled",
                "all"
              ]
            }
          },
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "arrivals",
                "departures",
                "all"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{check_in, check_out, check_in_time, check_out_time,\nstatus, is_block, ambiguous, same_day_turnover, guests_adults,\nguests_children, channel, source, property_id, property_name,\ntask_uuid, task_completed_at}], total, page, pageSize, from, to }`.\n`task_uuid` = cleaning task of the departure, if any.\n"
          },
          "403": {
            "description": "Missing scope/right, customer account, or `property_id` outside the restriction."
          },
          "422": {
            "description": "`reason: RANGE_TOO_LARGE` or `RANGE_INVALID`"
          }
        }
      }
    },
    "/v1/occupancy": {
      "get": {
        "summary": "Current staffing per property",
        "description": "Requires scope `shifts:read` and `VIEW_TIME_TRACKING_OTHERS` (or the\nUpdate right on time tracking) — at a small property \"1 present\"\nstill identifies a person. Numbers only, never names. Every\nnon-archived property the key may see is listed, unstaffed ones\nincluded. `property_id` outside the restriction → 403.\n",
        "parameters": [
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "state",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "understaffed",
                "staffed",
                "no_shift"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{property_id, property_name, present_count,\nrunning_shifts, required_count, shift_present_count, state}] }`.\n`present_count` = open time entries at the property, without\narchived staff (same for `shift_present_count`);\n`required_count` = target of the shifts running now.\n"
          },
          "403": {
            "description": "Missing scope or right, customer account, or `property_id` outside the restriction."
          }
        }
      }
    },
    "/v1/reports/overview": {
      "get": {
        "summary": "Company-wide totals of the last 7, 30 or 90 days",
        "description": "Requires scope `reports:read` and the Read right on reports (like the\nportal start page). Customer accounts are blocked (403). Sums over\nevery property the key may see (property-restricted keys: their\nproperties); fields ending in `_prev` are the previous period of the\nsame length. No sparklines, no property list.\n",
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                7,
                30,
                90
              ],
              "default": 30
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { days, properties, totals: {shifts, hours,\nopen_attendances, punctuality_pct, reliability_pct, worked_shifts,\nmissed_shifts, incidents, walks, walks_target,\nunavailable_check_points, tasks_completed, form_responses,\n…_prev} } }`\n"
          }
        }
      }
    },
    "/v1/reports/property-performance": {
      "get": {
        "summary": "Performance per property with a traffic light",
        "description": "Requires scope `reports:read` and the Read right on reports. One row\nper active property the key may see: `health` (`green`, `yellow`,\n`red` — red = planned shifts or patrols were not delivered), shifts,\nhours, punctuality, incidents, patrols, missed shifts and patrols,\nlate check-ins, open shifts, unreachable control points — each with\nthe previous period (`_prev`). Without `favorite`, `rel_id` and the\nproperty uuid of the portal. `property_id` outside the restriction →\n403.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                7,
                30,
                90
              ],
              "default": 30
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "health",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "green",
                "yellow",
                "red"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{property_id, name, health, shifts, hours,\npunctuality_pct, punctuality_count, incidents, walks,\nmissed_shifts, worked_shifts, missed_walks, late_checkins,\nopen_shifts, unavailable_check_points, …_prev}], total, page,\npageSize, days }`\n"
          }
        }
      }
    },
    "/v1/reports/service-level": {
      "get": {
        "summary": "Service-level status per property (current period)",
        "description": "Requires scope `reports:read` and the Read right on reports. For every\nproperty with a governing contract (tenant default or its own): the\nverdict of the current period (`onTrack`, `atRisk`, `missed`, `na` =\nnothing measurable yet), the promise counters and every promise\n(`slis[]`) with target and measured value. Worst properties first.\nWithout contract id and contract scope.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "verdict",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "onTrack",
                "atRisk",
                "missed",
                "na"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{property_id, property_name, period_type, period:\n{start, end}, verdict, promises: {total, kept, atRisk, missed,\nunmeasured}, slis: [{sli, type, op, target, actual, verdict}]}],\ntotal, page, pageSize, generated_at }`\n"
          }
        }
      }
    },
    "/v1/customers": {
      "get": {
        "summary": "List customers (CRM master data)",
        "description": "Requires scope `customers:read`. Writing is available under\n`customers:write` (POST/PATCH); payment and tax maintenance stay in the\nportal. `archived` omitted lists BOTH states\n(an archived customer stays resolvable); `type` filters BUSINESS vs\nPERSONAL. `search` is the portal's fuzzy search. Internal notes,\npayment terms/tax references and portal credentials are deliberately\nNOT exposed. Customer-portal key accounts are blocked (403).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "archived",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "BUSINESS",
                "PERSONAL"
              ]
            }
          },
          {
            "name": "category_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged list: `{ data: [{customer_id, uuid, customer_number, type, name, first_name, last_name, gender, tax_id, vat_number, archived, category, locations, communication, property_count, contact_person}], total, page, pageSize }`.\n"
          }
        }
      },
      "post": {
        "summary": "Create a customer",
        "description": "Requires scope `customers:write`. Business/personal rules mirror the\nportal: BUSINESS needs `name` and rejects `first_name`/`last_name`/\n`gender`; PERSONAL needs `last_name` and rejects `name`.\n\n`category_id`, `payment_term_id` and `taxes_id` are OPTIONAL here — an\nintegration does not know the tenant's internal references. Omitted,\nthe tenant's first category and payment term are used and `taxes_id`\nfalls back to the column default. A tenant without any category or\npayment term answers `400` naming which one to create in the portal.\n`customer_number` omitted → the next number of the tenant's series\n(the same the portal proposes). `contact_person` creates the primary\ncontact as in the portal dialog (a PERSONAL customer linked to this\none) and is returned as `contact_person`.\n\nInternal notes, portal credentials and tax/payment maintenance stay\nportal-only, exactly as on the read path.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "type"
                ],
                "additionalProperties": false,
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "BUSINESS",
                      "PERSONAL"
                    ]
                  },
                  "customer_number": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "first_name": {
                    "type": "string"
                  },
                  "last_name": {
                    "type": "string"
                  },
                  "gender": {
                    "type": "string",
                    "description": "MEN, WOMEN or OTHER. The salutations Herr, Frau, Divers and Mr, Ms, Other are accepted and stored as these values; anything else answers 400."
                  },
                  "tax_id": {
                    "type": "string"
                  },
                  "vat_number": {
                    "type": "string"
                  },
                  "category_id": {
                    "type": "integer"
                  },
                  "payment_term_id": {
                    "type": "integer"
                  },
                  "taxes_id": {
                    "type": "integer"
                  },
                  "locations": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  },
                  "communication": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  },
                  "contact_person": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [
                      "last_name"
                    ],
                    "properties": {
                      "gender": {
                        "type": "string",
                        "description": "MEN, WOMEN or OTHER. The salutations Herr, Frau, Divers and Mr, Ms, Other are accepted and stored as these values; anything else answers 400."
                      },
                      "first_name": {
                        "type": "string"
                      },
                      "last_name": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created customer (same shape as GET /v1/customers/{id}, plus `contact_person` when one was created)."
          },
          "400": {
            "description": "Type rules violated, or the tenant has no category / payment term."
          }
        }
      }
    },
    "/v1/customers/{id}": {
      "get": {
        "summary": "Get one customer",
        "description": "Requires scope `customers:read`. Same fields as the list row minus\nthe list-only extras (`property_count`, `contact_person`).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Customer detail."
          },
          "404": {
            "description": "Customer not found in this tenant."
          }
        }
      },
      "patch": {
        "summary": "Update a customer",
        "description": "Requires scope `customers:write`. Partial update — send only the fields\nthat change; an empty body is rejected. Type rules are enforced against\nthe EFFECTIVE type (the body's `type` if sent, otherwise the stored\none), so a partial update cannot attach a last name to a business\ncustomer.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "minProperties": 1,
                "additionalProperties": false,
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "BUSINESS",
                      "PERSONAL"
                    ]
                  },
                  "customer_number": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "first_name": {
                    "type": "string"
                  },
                  "last_name": {
                    "type": "string"
                  },
                  "gender": {
                    "type": "string",
                    "description": "MEN, WOMEN or OTHER. The salutations Herr, Frau, Divers and Mr, Ms, Other are accepted and stored as these values; anything else answers 400."
                  },
                  "tax_id": {
                    "type": "string"
                  },
                  "vat_number": {
                    "type": "string"
                  },
                  "category_id": {
                    "type": "integer"
                  },
                  "payment_term_id": {
                    "type": "integer"
                  },
                  "taxes_id": {
                    "type": "integer"
                  },
                  "locations": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  },
                  "communication": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated customer."
          },
          "400": {
            "description": "Type rules violated or empty body."
          },
          "404": {
            "description": "Customer not found in this tenant."
          }
        }
      }
    },
    "/v1/customers/{id}/copy": {
      "post": {
        "summary": "Copy a customer (master data, addresses, contact persons)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "The customer to copy (`customer_id`)."
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyUuid"
          }
        ],
        "description": "Requires scopes `customers:read` and `customers:write` (the answer carries\nthe values of the source, so the key must be allowed to read it) and\nthe role right to create\ncustomers — copying needs the same rights as creating; customer\nportal accounts are refused as on every `/v1/customers` path. The\nsource is only read and never changed. Unknown and foreign customers\nanswer alike (404).\n\nCOPIED: type, name (with ` (Kopie)` appended unless `name` is given;\nfor a person the suffix goes to the last name), salutation, tax\nnumber, VAT id, category, payment term, tax setting, internal note,\naddresses (`locations`) and communication channels. The customer\nnumber is drawn anew from the number series.\n\nCONTACT PERSONS: a contact person is a customer of its own (a person)\nconnected to the business customer. The copy is connected to the SAME\npersons, with the same role and the same primary-contact flag; no\nperson is duplicated. Archived persons stay with the source. `copy`\ntells how many were connected and names any that could not be\n(`copy.issues[]`, code `CONTACT_PERSON_NOT_COPIED`). Connections to other\ncompanies and to archived persons stay with the source; their number\nis reported (`CONNECTIONS_NOT_COPIED`).\n\nNEVER copied: the customer's portal access, properties, orders,\ndocuments and history. The copy is active, also when the source is\narchived.\n\nThe copy is created through the same path as POST /v1/customers.\nCreating a customer needs no change reason.\n\nIdempotency: pass `Idempotency-Key` (or `uuid`). The same key with\nthe same body answers 200 with `duplicate: true` and the customer\ncreated first. The same key with a different body ⇒ 422\n`IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`; a second call while the first is\nstill running ⇒ 409 `IDEMPOTENCY_KEY_IN_PROGRESS`. A call that failed\nreleases its key.\n",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "uuid": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Idempotency key (alternatively header `Idempotency-Key`)."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200,
                    "description": "Company name of the copy; for a person the last name (at most 100 characters there). Default: name of the source + ` (Kopie)`."
                  }
                }
              },
              "examples": {
                "defaults": {
                  "summary": "Copy with defaults",
                  "value": {}
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The key was used before with the same body: the customer created first, `duplicate: true`. Nothing written."
          },
          "201": {
            "description": "Copy created: `{ data: <customer as GET /v1/customers/{id}> + source_customer_id, created: true, copy: { contact_persons, issues[] } }`."
          },
          "400": {
            "description": "The tenant has no customer category, payment term or number series set up."
          },
          "403": {
            "description": "Missing scope `customers:write` or role right to create customers; customer portal account."
          },
          "404": {
            "description": "Source customer unknown or of another tenant."
          },
          "409": {
            "description": "`IDEMPOTENCY_KEY_IN_PROGRESS` — the first call with this key has not finished."
          },
          "422": {
            "description": "`IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`, `COPY_NAME_TOO_LONG` (name of a person over 100 characters) or a validation error of the body."
          }
        }
      }
    },
    "/v1/app-dashboard-layout": {
      "get": {
        "summary": "Get the tenant-wide app dashboard layout",
        "description": "Requires scope `app_dashboard:read`. Returns the default layout of the\nLiteLog app's dashboard for this tenant — which widgets the app shows,\nin which order, and which tiles the **quick actions** widget contains.\nSame setting as the default view of `/v1/app-views` (Settings → Functions & devices → App view).\n\n`layout: null` means \"app default\": every widget and every quick-action\ntile, in catalogue order. `catalog` lists the valid keys for `widgets`,\n`quick_actions` and `workspace_scope` (`workspace_scopes`). A widget/tile\nthat the role has no permission for,\nor whose feature is switched off at the property, never appears — a\nlayout can only hide or reorder, never reveal. Employees may still\nadjust the widgets (not the tiles) for themselves in the app unless a\ndevice carries a binding layout (portal-only).\n",
        "responses": {
          "200": {
            "description": "`{ data: { layout: { version: 1, widgets: [{key, enabled}], quick_actions?: [{key, enabled}], workspace_scope?: 'all' | 'spontaneous' } | null, catalog: { widgets: string[], quick_actions: string[], workspace_scopes: string[] } } }`. `workspace_scope` (optional, default `all`): `spontaneous` restricts the app's **workspace** widget to spontaneous tasks only — tasks without an active schedule whose priority is HIGH or MEDIUM; routes and tours are hidden. Employees cannot override it in the app.\n"
          }
        }
      },
      "put": {
        "summary": "Replace the tenant-wide app dashboard layout",
        "description": "Requires scope `app_dashboard:write`. Sends the COMPLETE layout — array\norder is display order; a catalogue key missing from an array counts as\nenabled and is appended at its default position. Omit `quick_actions`\nto keep all tiles. Omit `workspace_scope` (or send `all`) to show every\ntask and route in the workspace widget; `spontaneous` shows only\nspontaneous tasks (no active schedule, priority HIGH or MEDIUM — routes\nand tours are hidden; the widget must be enabled for the scope to have\nan effect). Unknown keys and unknown fields are rejected (400).\nConnected devices refresh promptly (push + sync).\n\nExample — only the **Melden** (report) tile:\n`{ \"version\": 1, \"widgets\": [], \"quick_actions\": [\n  { \"key\": \"report\", \"enabled\": true }, { \"key\": \"route\", \"enabled\": false },\n  { \"key\": \"forms\", \"enabled\": false }, { \"key\": \"task\", \"enabled\": false },\n  { \"key\": \"material\", \"enabled\": false }, { \"key\": \"status\", \"enabled\": false },\n  { \"key\": \"sos\", \"enabled\": false } ] }`\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "version",
                  "widgets"
                ],
                "additionalProperties": false,
                "properties": {
                  "version": {
                    "type": "integer",
                    "enum": [
                      1
                    ]
                  },
                  "widgets": {
                    "type": "array",
                    "maxItems": 5,
                    "items": {
                      "type": "object",
                      "required": [
                        "key",
                        "enabled"
                      ],
                      "properties": {
                        "key": {
                          "type": "string",
                          "enum": [
                            "status-hero",
                            "my-shift-today",
                            "quick-actions",
                            "statusgeber",
                            "workspace"
                          ]
                        },
                        "enabled": {
                          "type": "boolean"
                        }
                      }
                    }
                  },
                  "quick_actions": {
                    "type": "array",
                    "maxItems": 6,
                    "items": {
                      "type": "object",
                      "required": [
                        "key",
                        "enabled"
                      ],
                      "properties": {
                        "key": {
                          "type": "string",
                          "enum": [
                            "route",
                            "forms",
                            "report",
                            "task",
                            "material",
                            "status",
                            "sos"
                          ]
                        },
                        "enabled": {
                          "type": "boolean"
                        }
                      }
                    }
                  },
                  "workspace_scope": {
                    "type": "string",
                    "enum": [
                      "all",
                      "spontaneous"
                    ],
                    "description": "Scope of the workspace widget. `all` (default when omitted) = every task and route; `spontaneous` = only tasks without an active schedule and priority HIGH or MEDIUM.\n"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved layout (same shape as GET)."
          },
          "400": {
            "description": "Unknown widget/tile key, unknown field or wrong version."
          }
        }
      },
      "delete": {
        "summary": "Reset the app dashboard layout to the app default",
        "description": "Requires scope `app_dashboard:write`. Removes the tenant-wide layout —\nthe app falls back to its default (all widgets and tiles). Binding\nper-device layouts set in the portal are not affected.\n",
        "responses": {
          "204": {
            "description": "Layout removed."
          }
        }
      }
    },
    "/v1/app-views": {
      "get": {
        "summary": "List app views",
        "description": "Requires scope `app_dashboard:read` and the right to read settings.\nAn **app view** is a named start screen of the LiteLog app (Settings →\nFunctions & devices → App view): which blocks show, in which order,\nand which quick action tiles. Views are assigned to roles, people and\ndevices; the first level set applies in the order device → person →\nrole, otherwise the default view (`is_default`). An assigned view is\nbinding in the app, the default view stays adjustable by employees.\nRole permissions always win: a view can only hide, never reveal.\n`usage` counts the assignments. `catalog` lists the valid keys.\nCustomer accounts ⇒ 403.\n",
        "responses": {
          "200": {
            "description": "`{ data: [{ app_view_id, name, is_default, sort_order, layout: { version: 1, widgets: [{key, enabled}], quick_actions?: [{key, enabled}], workspace_scope?: 'all' | 'spontaneous' }, usage: { roles, accounts, devices } }], total, catalog: { widgets, quick_actions, workspace_scopes } }`\n"
          }
        }
      },
      "post": {
        "summary": "Create an app view",
        "description": "Requires scope `app_dashboard:write` and the right to change settings.\nInitial creation: no `change_reason` needed even when the account\ndemands reasons. Name unique per tenant (case-insensitive) ⇒ 409\n`APP_VIEW_NAME_TAKEN`.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "layout"
                ],
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "layout": {
                    "$ref": "#/components/schemas/AppViewLayout"
                  },
                  "is_default": {
                    "type": "boolean"
                  },
                  "sort_order": {
                    "type": "integer"
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ data: AppView }`"
          },
          "409": {
            "description": "`APP_VIEW_NAME_TAKEN`"
          }
        }
      }
    },
    "/v1/app-views/assignments": {
      "get": {
        "summary": "List app view assignments",
        "description": "Requires scope `app_dashboard:read`. Roles (all, without customer\nroles) with their view, plus people and devices that carry an OWN view\n(deviations from their role/person). People are limited to the key\naccount's person scope.\n",
        "responses": {
          "200": {
            "description": "`{ data: { roles: [Row], accounts: [Row], devices: [Row], default_view: { app_view_id, name } | null } }` with Row = `{ target, id, name, app_view_id, app_view_name }`.\n"
          }
        }
      },
      "put": {
        "summary": "Assign an app view to roles, people or devices",
        "description": "Requires scope `app_dashboard:write`, the right to change settings AND\nthe right to change the target (roles, people or devices) ⇒ else 403.\n`app_view_id: null` = inherit (role → default view, person → role,\ndevice → person). People and roles only strictly below the key\naccount's own level, never its own role; invisible or foreign targets\n⇒ 404 `APP_VIEW_TARGET_NOT_FOUND`. A role change runs through change\napproval like `PATCH /roles/:id`: when approval is required, the role\nis listed in `approval_pending` and stays unchanged until an approver\ndecides; if nothing else changed the answer is `202`. Needs\n`change_reason` when the account demands reasons.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "target",
                  "ids",
                  "app_view_id"
                ],
                "additionalProperties": false,
                "properties": {
                  "target": {
                    "type": "string",
                    "enum": [
                      "role",
                      "account",
                      "device"
                    ]
                  },
                  "ids": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 50,
                    "items": {
                      "type": "integer",
                      "minimum": 1
                    }
                  },
                  "app_view_id": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 1
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { target, app_view_id, app_view_name, changed: [Row], unchanged, approval_pending?: [{ role_id, batch_id }] } }`\n"
          },
          "202": {
            "description": "Only approval requests were filed; nothing changed yet."
          },
          "403": {
            "description": "Missing right for the target, or a role/person at or above your level."
          },
          "404": {
            "description": "`APP_VIEW_NOT_FOUND` or `APP_VIEW_TARGET_NOT_FOUND`."
          }
        }
      }
    },
    "/v1/app-views/effective": {
      "get": {
        "summary": "Effective app view of a person or device",
        "description": "Requires scope `app_dashboard:read`. Exactly what the app shows: the\nassigned view and its `source` (`device`, `account`, `role`) with\n`binding: true`, or the default view with `source: default` and\n`binding: false`. A device without `account_id` uses the person last\nsigned in on it.\n",
        "parameters": [
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "device_id",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { app_view_id, name, source, binding, layout } }`"
          },
          "404": {
            "description": "`APP_VIEW_TARGET_NOT_FOUND`"
          },
          "422": {
            "description": "Neither account_id nor device_id given."
          }
        }
      }
    },
    "/v1/app-views/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer",
            "minimum": 1
          }
        }
      ],
      "get": {
        "summary": "Get an app view",
        "description": "Requires scope `app_dashboard:read`.",
        "responses": {
          "200": {
            "description": "`{ data: AppView, catalog }`"
          },
          "404": {
            "description": "`APP_VIEW_NOT_FOUND`"
          }
        }
      },
      "patch": {
        "summary": "Change an app view",
        "description": "Requires scope `app_dashboard:write`. At least one of `name`, `layout`,\n`sort_order`; `layout` is replaced as a whole. Applies at once to every\nrole, person and device the view is assigned to (devices refresh via\npush). Needs `change_reason` when the account demands reasons.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "layout": {
                    "$ref": "#/components/schemas/AppViewLayout"
                  },
                  "sort_order": {
                    "type": "integer"
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: AppView }`"
          },
          "409": {
            "description": "`APP_VIEW_NAME_TAKEN`"
          }
        }
      },
      "delete": {
        "summary": "Delete an app view",
        "description": "Requires scope `app_dashboard:write`. Refused while the view is the\ndefault (409 `APP_VIEW_IS_DEFAULT`) or still assigned (409\n`APP_VIEW_IN_USE` with `usage`). Needs `change_reason` when the\naccount demands reasons.\n",
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "409": {
            "description": "`APP_VIEW_IS_DEFAULT` or `APP_VIEW_IN_USE`"
          }
        }
      }
    },
    "/v1/app-views/{id}/default": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer",
            "minimum": 1
          }
        }
      ],
      "put": {
        "summary": "Make an app view the default view",
        "description": "Requires scope `app_dashboard:write`. The default view applies to\neveryone without an own assignment and is the same setting as\n`/v1/app-dashboard-layout`. Body `{}` or `{ change_reason }`.\n",
        "responses": {
          "200": {
            "description": "`{ data: AppView }`"
          }
        }
      }
    },
    "/v1/nav-layout": {
      "get": {
        "summary": "Get the company main menu of the portal",
        "description": "Requires scope `nav_layout:read` and the Read right on settings;\ncustomer accounts get 403. Returns the company default of the portal\nmain menu (rail order, hidden main items, sections and views per\npanel, own names/icons/colors) — the same setting as \"Customize menu →\nSave as company default\" in the portal. `layout: null` = LiteLog\ndefault. `catalog` lists every accepted value plus the LiteLog default\nas a template (`default_layout`). Personal menus of single people are\nnot part of the API.\n",
        "responses": {
          "200": {
            "description": "Layout and catalogue.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "layout": {
                          "oneOf": [
                            {
                              "$ref": "#/components/schemas/NavLayout"
                            },
                            {
                              "type": "null"
                            }
                          ]
                        },
                        "preset": {
                          "type": "string",
                          "description": "Template in effect while `layout` is null (`catalog.presets[preset]`)."
                        },
                        "preset_choice": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Saved template choice; null = automatic by industry (security → security, cleaning and caretaker → tasks, else standard)."
                        },
                        "catalog": {
                          "$ref": "#/components/schemas/NavLayoutCatalog"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Scope or right missing, or customer account."
          }
        }
      },
      "put": {
        "summary": "Replace the company main menu of the portal",
        "description": "Requires scope `nav_layout:write` and the Update right on settings.\nSends the COMPLETE layout; panels left out keep the LiteLog default.\nStrict: unknown keys, icons, colors, rail ids or fields, a hidden\n`dashboard`, duplicate section ids or exceeded limits answer 422.\nPresentation only — no change reason and no change approval; every\nsaving change writes a configuration audit row (`nav_layout`) with the\nkey's account as actor. The same layout again writes nothing.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NavLayout"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved layout (with `company_updated_at`) and catalogue, same shape as GET."
          },
          "403": {
            "description": "Scope or right missing, or customer account."
          },
          "422": {
            "description": "Unknown value or field, hidden dashboard, duplicate section or limit exceeded."
          }
        }
      },
      "delete": {
        "summary": "Reset the company main menu to the LiteLog default",
        "description": "Requires scope `nav_layout:write` and the Update right on settings.\nDrops the company default; personal menus stay. Nothing saved ⇒\nnothing written.\n",
        "responses": {
          "200": {
            "description": "`{ data: { layout: null, catalog } }`."
          },
          "403": {
            "description": "Scope or right missing, or customer account."
          }
        }
      }
    },
    "/v1/nav-layout/preset": {
      "put": {
        "summary": "Choose the main menu template of the company",
        "description": "Requires scope `nav_layout:write` and the Update right on settings;\ncustomer accounts get 403. Stores only the choice (`null` = automatic\nby industry); the templates themselves are listed in\n`catalog.presets`. A saved company menu still wins — reset it with\nDELETE /v1/nav-layout to see the template. Presentation only, no\nchange reason; a changed choice writes a configuration audit row\n(`nav_layout`, field `nav_preset`). The same choice again writes nothing.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "preset"
                ],
                "additionalProperties": false,
                "properties": {
                  "preset": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "standard",
                      "attendance",
                      "time",
                      "tasks",
                      "security",
                      null
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: { preset, preset_choice } }`."
          },
          "403": {
            "description": "Scope or right missing, or customer account."
          },
          "422": {
            "description": "Unknown template or extra field."
          }
        }
      }
    },
    "/v1/routes": {
      "get": {
        "summary": "List patrol route configurations (catalogue)",
        "description": "Requires scope `patrols:read`. The master-data catalogue behind\n/v1/patrols — resolve a run's `route_id` to name, property and\ncheckpoint count. `name` is the newest schedule series' name.\n`archived` omitted lists ALL routes (runs may reference archived\nversions); pass `archived=false` for the active set. `parent_id`\nlinks to the predecessor version of an edited route.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "archived",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{route_id, name, property_id, property_name, archived, parent_id, checkpoints_total}], total, page, pageSize }`.\n"
          }
        }
      },
      "post": {
        "summary": "Create a patrol route (configuration + schedule + checkpoints)",
        "description": "Requires scope `routes:write`. Same flow as the portal editor: the\nschedule is validated in the property's timezone, the route is\ncreated with one schedule series and its checkpoints, an audit row is\nwritten, the planned runs are generated (no back-dated windows of the\ncreation day) and the start notification fires. Every checkpoint must\nbelong to `property_id` (422 `NO_TAGS` otherwise). Validation errors\nanswer 422 with `issues[].code` from `NO_NAME | NO_TAGS |\nNOT_ENOUGH_DATA | INVALID_DATE | ENDDATE | TO_EARLY | DURATION`;\npass `ignore_start_date: true` to allow a start date in the past.\nSubject to the tenant's four-eyes change approval (entity type\n`route_config`): send `change_reason` (body or `X-Change-Reason`\nheader, else 422 `CHANGE_REASON_REQUIRED`) and expect\n`ApprovalPending` with HTTP 200 — nothing is written until the request\nis approved in the portal. Requests that fail validation are rejected\nBEFORE an approval request is filed.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "property_id",
                  "name",
                  "checkpoints",
                  "schedule"
                ],
                "additionalProperties": false,
                "properties": {
                  "property_id": {
                    "type": "integer"
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "notes_user": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 1000
                  },
                  "notes_intern": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 1000
                  },
                  "task_uuid": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid",
                    "description": "Library task linked to the route (ROUTE binding)."
                  },
                  "violation_rule_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  },
                  "ignore_start_date": {
                    "type": "boolean"
                  },
                  "checkpoints": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 200,
                    "items": {
                      "type": "object",
                      "required": [
                        "tag_id",
                        "sequence",
                        "duty"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "tag_id": {
                          "type": "integer"
                        },
                        "sequence": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "Walk order; 0 = no fixed order."
                        },
                        "duty": {
                          "type": "boolean",
                          "description": "Mandatory checkpoint."
                        }
                      }
                    }
                  },
                  "schedule": {
                    "$ref": "#/components/schemas/RouteSchedule"
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Reason for the change approval (alternatively header `X-Change-Reason`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`ApprovalPending` — nothing written yet, an approval request was filed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApprovalPending"
                },
                "examples": {
                  "approvalPending": {
                    "value": {
                      "changed": false,
                      "approval_pending": true,
                      "batch_id": "6f1c…",
                      "entity_type": "route_config",
                      "label": "Rundgangs-Vorgabe"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "`{ data: <same shape as GET /v1/routes/{id}> }`."
          },
          "403": {
            "description": "Property outside the key account's restriction."
          },
          "409": {
            "description": "`REQUEST_PENDING` — an approval request for a route of this name at this property is still open."
          },
          "422": {
            "description": "Schedule/checkpoint validation failed (see `issues[].code`), or `CHANGE_REASON_REQUIRED` (change approval active, no reason given)."
          }
        }
      }
    },
    "/v1/routes/{id}": {
      "get": {
        "summary": "Route detail incl. schedule series and checkpoint list",
        "description": "Requires scope `patrols:read`. Adds `configs` (all schedule series,\noldest first: first_run/last_run, start_time, `duration_run` in\nSECONDS, frequency, repeat fields, `anchor_mode`, `violation_rule_id`,\n`notes_user`) and `checkpoints` (walk order:\nsequence, duty, tag_id, name, uuid, archived, area_id, area_name —\nthe checkpoint's area/floor, null when unassigned). Archived routes\nstay resolvable — runs may reference them.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { …route…, configs: [...], checkpoints: [...] } }`."
          },
          "404": {
            "description": "Route not visible for this key."
          }
        }
      },
      "patch": {
        "summary": "Edit a patrol route (portal semantics)",
        "description": "Requires scope `routes:write`. Partial patch merged over the current\nconfiguration; `schedule` fields apply to every series of the route.\nBehaves like the portal editor:\n- default (\"ab sofort\"): the current version is archived (or deleted\n  when it never ran) and a NEW version is created — **the response\n  carries the new `route_id`**, the path id may answer 404 afterwards;\n- `effective_from` (YYYY-MM-DD): the current version ends the day\n  before and the new version starts on that date (`parent_id` links\n  them);\n- a patch containing only `schedule.last_run` just moves the end date\n  and keeps the id.\nEvery checkpoint must belong to the route's property (422 `NO_TAGS`).\nSubject to the tenant's four-eyes change approval (entity type\n`route_config`): send `change_reason` (body or `X-Change-Reason`\nheader, else 422 `CHANGE_REASON_REQUIRED`) and expect\n`ApprovalPending` with HTTP 200 — the route stays unchanged until the\nrequest is approved in the portal.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "minProperties": 1,
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "notes_user": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 1000
                  },
                  "notes_intern": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 1000
                  },
                  "task_uuid": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  },
                  "violation_rule_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  },
                  "checkpoints": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 200,
                    "items": {
                      "type": "object",
                      "properties": {
                        "tag_id": {
                          "type": "integer"
                        },
                        "sequence": {
                          "type": "integer"
                        },
                        "duty": {
                          "type": "boolean"
                        }
                      }
                    }
                  },
                  "schedule": {
                    "$ref": "#/components/schemas/RouteSchedule"
                  },
                  "effective_from": {
                    "type": "string",
                    "format": "date"
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Reason for the change approval (alternatively header `X-Change-Reason`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: <route detail of the version that is now in effect> }` — `data.route_id` may differ from the path id. Or `ApprovalPending` when the four-eyes rule is active.",
            "content": {
              "application/json": {
                "examples": {
                  "approvalPending": {
                    "value": {
                      "changed": false,
                      "approval_pending": true,
                      "batch_id": "6f1c…",
                      "entity_type": "route_config",
                      "label": "Rundgangs-Vorgabe"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Route not visible for this key."
          },
          "409": {
            "description": "`REQUEST_PENDING` — an approval request for this route is still open."
          },
          "422": {
            "description": "Validation failed, the route has a pending future version, or `CHANGE_REASON_REQUIRED` (change approval active, no reason given)."
          }
        }
      }
    },
    "/v1/routes/{id}/archive": {
      "post": {
        "summary": "End a patrol route series",
        "description": "Requires scope `routes:write`. Same as \"Rundgang beenden\" in the\nportal: sets the series end date (`configs[].last_run`, default =\ntoday in the property's timezone) and removes the not-yet-started\nfuture runs. It does NOT flip the `archived` version flag and there is\nno public un-end; runs that already happened stay in the log book.\nSubject to the tenant's four-eyes change approval (entity type\n`route_config`): send `change_reason` (body or `X-Change-Reason`\nheader, else 422 `CHANGE_REASON_REQUIRED`) and expect\n`ApprovalPending` with HTTP 200 — the series keeps running until the\nrequest is approved in the portal.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "last_run": {
                    "type": "string",
                    "format": "date"
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Reason for the change approval (alternatively header `X-Change-Reason`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: <route detail> }` with the new `last_run`. Or `ApprovalPending` when the four-eyes rule is active.",
            "content": {
              "application/json": {
                "examples": {
                  "approvalPending": {
                    "value": {
                      "changed": false,
                      "approval_pending": true,
                      "batch_id": "6f1c…",
                      "entity_type": "route_config",
                      "label": "Rundgangs-Vorgabe"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Route not visible for this key."
          },
          "409": {
            "description": "`REQUEST_PENDING` — an approval request for this route is still open. `ROUTE_ALREADY_ENDED` — the series already carries an end date (`last_run` in the body; move it with PATCH `schedule.last_run`). `ROUTE_WITHOUT_SCHEDULE` — the route has no series, so there is no end date to set. Both before the change gate, nothing written (since 22.10.2026, same texts as the MCP tool archive_route).",
            "content": {
              "application/json": {
                "examples": {
                  "alreadyEnded": {
                    "value": {
                      "message": "The route already has an end date (2026-11-30). Change it with update_route (schedule.last_run) instead.",
                      "reason": "ROUTE_ALREADY_ENDED",
                      "errorCode": "CONFLICT",
                      "last_run": "2026-11-30"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "`CHANGE_REASON_REQUIRED` (change approval active, no reason given)."
          }
        }
      }
    },
    "/v1/tours": {
      "get": {
        "summary": "List tours (cross-property rounds with stops)",
        "description": "Requires scope `tours:read`. A tour is the portal's cross-property\nround: an ordered list of stops, one property each, with its own\nschedule series — the counterpart of `/v1/routes`, which stays\ninside one property. A tour is visible only when EVERY stop\nproperty lies inside the key account's property restriction; a tour\nwith a foreign stop is absent from the list and answers 404 by id.\n`archived` omitted lists active and archived tours; `archived=true`\n= `active: false`. `property_id` = at least one stop at that\nproperty. `search` matches the name (case-insensitive, `%` and `_`\ntaken literally).\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "archived",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: TourListItem[], total, page, pageSize }`."
          }
        }
      },
      "post": {
        "summary": "Create a tour (head + stops + schedule series)",
        "description": "Requires scope `tours:write`. Same flow as the portal editor: the\ntour is created with its stops and schedule series, the planned\nruns are generated and the change is written to the configuration\naudit. Changes take effect immediately — tours are NOT subject to\nthe four-eyes change approval. Every stop property must lie inside\nthe key account's restriction (403 otherwise); a `route_id` must be\na patrol route of the stop's property. `schedules` may be empty (a\ntour without a date). `change_reason` (body or header\n`X-Change-Reason`) is optional on create and stored with the audit\nrow when given.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "stops"
                ],
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000
                  },
                  "order_mode": {
                    "type": "string",
                    "enum": [
                      "enforced",
                      "free"
                    ],
                    "default": "free",
                    "description": "`enforced` = stops in the given order, `free` = any order."
                  },
                  "esignature_mode": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "required",
                      "off",
                      null
                    ],
                    "description": "null = the tenant default applies."
                  },
                  "active": {
                    "type": "boolean",
                    "default": true
                  },
                  "stops": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 200,
                    "items": {
                      "$ref": "#/components/schemas/TourStopInput"
                    }
                  },
                  "schedules": {
                    "type": "array",
                    "maxItems": 20,
                    "items": {
                      "$ref": "#/components/schemas/TourScheduleInput"
                    }
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Optional on create; stored with the audit row (alternatively header `X-Change-Reason`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ data: Tour }` — the same shape as GET /v1/tours/{id}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Tour"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "A stop property lies outside the key account's restriction."
          },
          "422": {
            "description": "Validation failed (stop or schedule rules, `route_id` not a route of the stop's property)."
          }
        }
      }
    },
    "/v1/tours/{id}": {
      "get": {
        "summary": "Tour detail incl. stops and schedule series",
        "description": "Requires scope `tours:read`. The list row plus `stops[]` in stop\norder and `schedules[]`. `id` is the tour `uuid`. Archived tours stay\nresolvable — runs may reference them. A tour with a stop property\noutside the key's restriction answers 404.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: Tour }`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Tour"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Tour unknown or not visible for this key."
          }
        }
      },
      "patch": {
        "summary": "Edit a tour (partial update; stops and schedules replace as a whole)",
        "description": "Requires scope `tours:write`. Head fields (`name`, `description`,\n`order_mode`, `esignature_mode`, `active`) are patched one by one;\n`stops` and `schedules`, when sent, REPLACE the whole list (send the\ncomplete new list, not a delta). Future runs are regenerated from\nthe new schedule series; runs that already happened stay in the log\nbook. When the change drops future runs (a series shortened or\nremoved, the tour deactivated), a reason is required: send\n`change_reason` in the body or the header `X-Change-Reason`, else\n422 `REASON_REQUIRED`. Changes take effect immediately — no change\napproval. A stop property outside the key's restriction answers\n403; a tour not visible for this key answers 404 (never 403).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-Change-Reason",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 2000
            },
            "description": "Alternative to `change_reason` in the body."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "minProperties": 1,
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 2000
                  },
                  "order_mode": {
                    "type": "string",
                    "enum": [
                      "enforced",
                      "free"
                    ]
                  },
                  "esignature_mode": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "required",
                      "off",
                      null
                    ]
                  },
                  "active": {
                    "type": "boolean"
                  },
                  "stops": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 200,
                    "items": {
                      "$ref": "#/components/schemas/TourStopInput"
                    },
                    "description": "Full replacement of the stop list."
                  },
                  "schedules": {
                    "type": "array",
                    "maxItems": 20,
                    "items": {
                      "$ref": "#/components/schemas/TourScheduleInput"
                    },
                    "description": "Full replacement of the schedule series; `[]` removes every series."
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Required when future runs are dropped (alternatively header `X-Change-Reason`)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: Tour }` — the tour as it is now in effect.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Tour"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "A stop property lies outside the key account's restriction."
          },
          "404": {
            "description": "Tour unknown or not visible for this key."
          },
          "422": {
            "description": "Validation failed, or `REASON_REQUIRED` — future runs are dropped and no reason was given."
          }
        }
      }
    },
    "/v1/tours/{id}/copy": {
      "post": {
        "summary": "Copy a tour (stops, order, time windows, rhythm)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The tour to copy (its `uuid`)."
          },
          {
            "$ref": "#/components/parameters/IdempotencyKeyUuid"
          }
        ],
        "description": "Requires scopes `tours:read` and `tours:write` (the answer carries\nthe values of the source, so the key must be allowed to read it) and\nthe role right to create tours —\ncopying needs the same rights as creating. The source is only read\nand never changed. Unknown and foreign tours, and tours with a stop\nat a property the key cannot see, answer alike (404).\n\nCOPIED: name (with ` (Kopie)` appended unless `name` is given),\ndescription, order mode, signature requirement, every stop in its\norder (property, what is done there, route, arrival offset, tolerance\nwindow, note) and every time window with its rhythm. A time window\nthat carried the name of the tour carries the name of the copy.\n\nNEVER copied: runs, arrivals, history. Every time window starts on\n`start_date` (default: tomorrow in the time zone of the first stop's\nproperty; not in the past). A series end of the source is not taken\nover. The copy is active, also when the source is archived.\n\nThe copy is created through the same path as POST /v1/tours: the\nsame checks of the stops (a stop with a route needs a non-archived\nroute of its property, otherwise 422), the same audit row, and the\nruns are generated as for a new tour. Tours know no change approval;\nno change reason is needed.\n\nIdempotency: pass `Idempotency-Key` (or `uuid`). The same key with\nthe same body answers 200 with `duplicate: true` and the tour created\nfirst. The same key with a different body ⇒ 422\n`IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`; a second call while the first is\nstill running ⇒ 409 `IDEMPOTENCY_KEY_IN_PROGRESS`. A call that failed\nreleases its key.\n",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "uuid": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Idempotency key (alternatively header `Idempotency-Key`)."
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255,
                    "description": "Default: name of the source + ` (Kopie)`, shortened to fit 255 characters."
                  },
                  "start_date": {
                    "type": "string",
                    "format": "date",
                    "description": "Day on which every copied time window starts (YYYY-MM-DD, not in the past). Default: tomorrow in the time zone of the first stop's property."
                  }
                }
              },
              "examples": {
                "defaults": {
                  "summary": "Copy with defaults",
                  "value": {}
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The key was used before with the same body: the tour created first, `duplicate: true`. Nothing written."
          },
          "201": {
            "description": "Copy created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/Tour"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "source_tour_uuid": {
                              "type": "string",
                              "format": "uuid",
                              "description": "The tour this one was copied from."
                            }
                          }
                        }
                      ]
                    },
                    "created": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Missing scope `tours:write` or role right to create tours."
          },
          "404": {
            "description": "Source tour unknown, of another tenant or not visible to the key."
          },
          "409": {
            "description": "`IDEMPOTENCY_KEY_IN_PROGRESS` — the first call with this key has not finished."
          },
          "422": {
            "description": "`COPY_START_DATE_IN_PAST`, `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH`, a stop whose route is archived, or a validation error of the body."
          }
        }
      }
    },
    "/v1/tours/{id}/archive": {
      "post": {
        "summary": "Archive a tour (active = false)",
        "description": "Requires scope `tours:write`. Same as \"Archivieren\" in the portal:\nsets `active: false`, no further runs are generated, future runs\nare removed; runs that already happened stay in the log book and\nthe tour stays readable. Dropping future runs needs a reason:\n`change_reason` in the body or header `X-Change-Reason`, else 422\n`REASON_REQUIRED`. Archiving an archived tour is a no-op (200).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-Change-Reason",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 2000
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: Tour }` with `active: false`."
          },
          "404": {
            "description": "Tour unknown or not visible for this key."
          },
          "422": {
            "description": "`REASON_REQUIRED` — future runs are dropped and no reason was given."
          }
        }
      }
    },
    "/v1/tours/{id}/unarchive": {
      "post": {
        "summary": "Reactivate a tour (active = true)",
        "description": "Requires scope `tours:write`. Sets `active: true` again; the planned\nruns are generated from the schedule series from today on.\nReactivating an active tour is a no-op (200). `change_reason`\n(body or header `X-Change-Reason`) is optional and stored with the\naudit row when given.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-Change-Reason",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 2000
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: Tour }` with `active: true`."
          },
          "404": {
            "description": "Tour unknown or not visible for this key."
          }
        }
      }
    },
    "/v1/control-points": {
      "get": {
        "summary": "List control points (scan points) of the tenant",
        "description": "Requires scope `control_points:read`. Only scan points\n(`CHECKPOINT`/`TASK_POINT`) — work-time and geofence points have\ntheir own surfaces. `archived` omitted lists ALL points (routes and\npatrol runs may reference archived ones); pass `archived=false` for\nthe active set. Ordered by area, then name. Property-restricted key\naccounts only see points on accessible properties. Each row also\ncarries `last_scan_at` (ISO 8601, null = never) and `scans_30d`\n(scans in the last 30 days, planned and free patrols; scans of\narchived free patrols do not count) — one bundled query per page.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "property_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "area_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "archived",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Case-insensitive substring match on the name."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: (ControlPoint & {last_scan_at, scans_30d})[], total, page, pageSize }`."
          }
        }
      },
      "post": {
        "summary": "Create a control point",
        "description": "Requires scope `control_points:write`. Same domain path as the\nportal editor (beacon allocation, area guard, GPS radius rule, task\nlinks, audit trail). The property must belong to the tenant and be\naccessible for the key account (403 otherwise); an archived property\nanswers 400 `PROPERTY_ARCHIVED`. `latitude`/`longitude` go together;\n`gps_radius_m` (20–1000 m) requires coordinates. `task_uuids` links\nexisting tasks of the tenant (404 for an unknown uuid). The response\ncarries the `uuid` for QR printing (`{\"uuid\": \"<uuid>\"}`). Creating\nneeds no change reason (initial creation); a `change_reason` given\nanyway is stored with the point's `created` row.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "property_id",
                  "name"
                ],
                "additionalProperties": false,
                "properties": {
                  "property_id": {
                    "type": "integer"
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "tag_type": {
                    "type": "string",
                    "enum": [
                      "CHECKPOINT",
                      "TASK_POINT"
                    ],
                    "default": "CHECKPOINT"
                  },
                  "notes_user": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 300
                  },
                  "notes_intern": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 300
                  },
                  "area_id": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "sort_order": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "maximum": 10000
                  },
                  "latitude": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "longitude": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "gps_radius_m": {
                    "type": [
                      "number",
                      "null"
                    ],
                    "minimum": 20,
                    "maximum": 1000
                  },
                  "task_uuids": {
                    "type": "array",
                    "maxItems": 50,
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Optional. Creating needs no reason; when given, it is stored with the created row (alternatively header X-Change-Reason)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ data: ControlPoint }`."
          },
          "403": {
            "description": "Property outside the key account's restriction."
          },
          "404": {
            "description": "Property (or a task uuid) not in the tenant."
          },
          "422": {
            "description": "Validation failed (e.g. radius without coordinates)."
          }
        }
      }
    },
    "/v1/control-points/{id}": {
      "get": {
        "summary": "Get a control point",
        "description": "Requires scope `control_points:read`. 404 when not visible for this key.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: ControlPoint }`."
          },
          "404": {
            "description": "Control point not visible for this key."
          }
        }
      },
      "patch": {
        "summary": "Edit a control point",
        "description": "Requires scope `control_points:write`. Partial patch — omitted fields\nstay untouched, `null` clears (area, notes, coordinates, radius).\n`task_uuids`, when present, is the complete new link set of this\npoint (`[]` unlinks all); omitted keeps the current links. `tag_type`\nmay switch between CHECKPOINT and TASK_POINT only.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "minProperties": 1,
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "tag_type": {
                    "type": "string",
                    "enum": [
                      "CHECKPOINT",
                      "TASK_POINT"
                    ]
                  },
                  "notes_user": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 300
                  },
                  "notes_intern": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 300
                  },
                  "area_id": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "sort_order": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0,
                    "maximum": 10000,
                    "description": "Position within the area (0 = first); null = unsorted. Changing area_id without sort_order resets it."
                  },
                  "latitude": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "longitude": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "gps_radius_m": {
                    "type": [
                      "number",
                      "null"
                    ],
                    "minimum": 20,
                    "maximum": 1000
                  },
                  "task_uuids": {
                    "type": "array",
                    "maxItems": 50,
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Alternative to the X-Change-Reason header (same rules)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: ControlPoint }`."
          },
          "404": {
            "description": "Control point (or a task uuid) not visible for this key."
          },
          "422": {
            "$ref": "#/components/responses/ChangeReasonRequired"
          }
        }
      }
    },
    "/v1/control-points/{id}/archive": {
      "post": {
        "summary": "Archive a control point (soft delete)",
        "description": "Requires scope `control_points:write`. Same as the portal recycle bin:\nthe point is soft-deleted (`archived: true`), a bound chip is released.\nThere is no hard delete — routes and runs keep referencing the point.\nIdempotent. 409 `CONTROL_POINT_IN_USE` when the point cannot be\narchived by the key's role.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: ControlPoint }` (archived)."
          },
          "409": {
            "description": "Point cannot be archived."
          },
          "422": {
            "$ref": "#/components/responses/ChangeReasonRequired"
          }
        }
      }
    },
    "/v1/control-points/{id}/unarchive": {
      "post": {
        "summary": "Restore an archived control point",
        "description": "Requires scope `control_points:write`. Idempotent.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: ControlPoint }` (active)."
          },
          "422": {
            "$ref": "#/components/responses/ChangeReasonRequired"
          }
        }
      }
    },
    "/v1/control-points/{id}/chip": {
      "post": {
        "summary": "Bind an NFC chip to the control point",
        "description": "Requires scope `control_points:write`. Same path as \"NFC verbinden\"\nin the portal/app: the chip UID is bound to this point and released\nfrom any other point or account of the tenant (audited). Without\n`overwrite` a chip that is already in use elsewhere answers 409\n`CHIP_IN_USE`; a chip already bound to this point is a no-op (200).\nA point that already holds a DIFFERENT chip also needs `overwrite`\n(409 `CHIP_ALREADY_BOUND`) — a second import run cannot silently\nreplace what the first one bound. `chip_id` is normalized to the\nscanned form (hex, upper case, no separators) and checked (422).\nArchived points answer 400.\n\nThe chip source is EITHER `chip_id` (the UID as scanned) OR\n`from_tag_id` (\"move the chip without a scan\"): the UID is taken from\nthat source tag of the tenant — its current binding, or, when the\nsource has none any more (e.g. after archiving, which releases the\nchip), the most recent UID recorded in the configuration audit for\nthat tag. The source may be archived and of any type (control point,\nwork-time tag). A chip still held by the source itself moves without\n`overwrite`; held by a third tag or account it still needs\n`overwrite` (else 409). Unknown or foreign source tag → 404; source\ntag without any known UID → 404 `SOURCE_CHIP_UNKNOWN`. Exactly one of\nthe two fields is required (else 422).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChipSource"
              },
              "examples": {
                "scanned": {
                  "summary": "UID read by a reader",
                  "value": {
                    "chip_id": "04A1B2C3D4E5F6",
                    "overwrite": false
                  }
                },
                "from_archived_tag": {
                  "summary": "Move the chip of an archived control point (UID from the audit)",
                  "value": {
                    "from_tag_id": 4580
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: ControlPoint }` with `chip_connected: true`."
          },
          "404": {
            "description": "Source tag unknown/foreign, or no UID known for it (`SOURCE_CHIP_UNKNOWN`)."
          },
          "409": {
            "description": "Chip already bound elsewhere (`CHIP_IN_USE`) or the point holds a different chip (`CHIP_ALREADY_BOUND`) — both without overwrite."
          },
          "422": {
            "description": "Neither or both of `chip_id` / `from_tag_id` given. Or CHANGE_REASON_REQUIRED — see components.responses.ChangeReasonRequired."
          }
        }
      }
    },
    "/v1/control-point-areas": {
      "get": {
        "summary": "List the areas of a property (groups of control points)",
        "description": "Requires scope `control_points:read`. The areas (floor, building\nsection, zone) of ONE property, ordered as the portal shows them\n(`sort_order`, then name). Every row carries `control_points_count`\n(active points in the area). No pagination — a property has few\nareas. A property that is foreign, archived or outside the key\naccount's restriction answers 404.\n",
        "parameters": [
          {
            "name": "property_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: ControlPointArea[] }`."
          },
          "404": {
            "description": "Property not visible for this key."
          }
        }
      },
      "post": {
        "summary": "Create an area at a property",
        "description": "Requires scope `control_points:write`. Same domain path as the portal\n(name unique per property, case-insensitive; appended at the end of\nthe order; audit trail `tag_area`). The property must belong to the\ntenant and be accessible for the key account (403 otherwise); an\narchived property answers 400 `PROPERTY_ARCHIVED`; a name already in\nuse answers 409 `TAG_AREA_NAME_DUPLICATE`. Assign points afterwards\nwith `area_id` on POST/PATCH `/v1/control-points`. Creating needs no\nchange reason (initial creation); a `change_reason` given anyway is\nstored with the area's `created` row.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "property_id",
                  "name"
                ],
                "additionalProperties": false,
                "properties": {
                  "property_id": {
                    "type": "integer"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Optional. Creating needs no reason; when given, it is stored with the created row (alternatively header X-Change-Reason)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "`{ data: ControlPointArea }`."
          },
          "400": {
            "description": "`PROPERTY_ARCHIVED`."
          },
          "403": {
            "description": "Property outside the key account's restriction."
          },
          "404": {
            "description": "Property not in the tenant."
          },
          "409": {
            "description": "`TAG_AREA_NAME_DUPLICATE` — an area of this name exists at the property."
          }
        }
      }
    },
    "/v1/control-point-areas/{id}": {
      "patch": {
        "summary": "Rename an area",
        "description": "Requires scope `control_points:write`. Only the name changes;\nreordering and deleting stay in the portal. Idempotent — the same\nname writes nothing and no second audit entry. An area that is\nunknown, foreign or outside the key account's restriction answers\n404; a name already in use answers 409 `TAG_AREA_NAME_DUPLICATE`.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "additionalProperties": false,
                "minProperties": 1,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Alternative to the X-Change-Reason header (same rules)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: ControlPointArea }`."
          },
          "404": {
            "description": "Area not visible for this key."
          },
          "409": {
            "description": "`TAG_AREA_NAME_DUPLICATE`."
          },
          "422": {
            "$ref": "#/components/responses/ChangeReasonRequired"
          }
        }
      }
    },
    "/v1/vacation-balance": {
      "get": {
        "summary": "Vacation balance of an employee (entitlement, used, remaining)",
        "description": "Requires scope `shifts:read`. Without `account_id` the balance of the\nkey's own account is returned; a foreign `account_id` additionally\nrequires the time-tracking view/update gate (else 403). `year`\ndefaults to the current year in the key account's timezone.\n`entitlement_days: null` means no entitlement row is maintained —\nthe vacation-budget feature is off for that person. `used_days` /\n`pending_days` count DISTINCT workdays of approved/pending vacation\nabsences (work-schedule aware, Mon–Fri fallback; public holidays of\nthe person's main property are not counted). `remaining_after_pending_days`\nis `remaining_days` minus `pending_days`. Entitlement and carryover\naccept half days (0.5 steps). Pass `absence_id` to additionally get\nthe per-year request block (\"this request: N workdays, remaining\nafter\"). Customer accounts are blocked (403).\n",
        "parameters": [
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "year",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            }
          },
          {
            "name": "absence_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { account_id, year, entitlement_days, carryover_days, note, source, used_days, pending_days, remaining_days, remaining_after_pending_days, request } }`. `source` is `manual` (maintained by hand) or `rollover` (created by the nightly year rollover), null without entitlement.\n"
          },
          "403": {
            "description": "Foreign account without the view/update gate."
          },
          "404": {
            "description": "Account (or absence_id) not found in this tenant."
          }
        }
      }
    },
    "/v1/vacation-entitlements": {
      "get": {
        "summary": "List vacation entitlement rows of an employee (all years)",
        "description": "Requires scope `shifts:read` and the time-tracking update gate\n(maintenance surface). Newest year first.\n",
        "parameters": [
          {
            "name": "account_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{entitlement_id, account_id, year, days, carryover_days, note, source, rolled_over_at, created_at, updated_at}] }`. `source` is `manual` or `rollover` (row created by the nightly year rollover: entitlement like the previous year, carryover = previous year's remaining days); `rolled_over_at` is set on the previous year's row once its successor was created."
          }
        }
      },
      "put": {
        "summary": "Create or update a vacation entitlement (upsert per year)",
        "description": "Requires scope `shifts:write` and the time-tracking update gate.\nUpsert on (account_id, year) — a second PUT overwrites instead of\nduplicating. `days` 0–400 in half days (0 is a valid maintained entitlement),\n`carryover_days` −400…400 in half days (previous year may be overdrawn). There is\nno automatic year rollover — maintain the next year explicitly.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "account_id",
                  "year",
                  "days"
                ],
                "additionalProperties": false,
                "properties": {
                  "account_id": {
                    "type": "integer"
                  },
                  "year": {
                    "type": "integer",
                    "minimum": 2000,
                    "maximum": 2100
                  },
                  "days": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 400,
                    "multipleOf": 0.5
                  },
                  "carryover_days": {
                    "type": "number",
                    "minimum": -400,
                    "maximum": 400,
                    "multipleOf": 0.5
                  },
                  "note": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The upserted entitlement row."
          },
          "404": {
            "description": "Account not found in this tenant."
          }
        }
      },
      "delete": {
        "summary": "Remove the entitlement of one year",
        "description": "Requires scope `shifts:write` and the time-tracking update gate.\nHard delete — the row is pure configuration, derived usage stays\nuntouched. Missing row (or foreign account) answers 404.\n",
        "parameters": [
          {
            "name": "account_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "year",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 2000,
              "maximum": 2100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: { deleted: true } }`."
          },
          "404": {
            "description": "Entitlement (or account) not found."
          }
        }
      }
    },
    "/v1/time-account/balance": {
      "get": {
        "summary": "Time-account balances as of a date (payroll/HR sync)",
        "description": "Requires scope `shifts:read` AND the time-tracking view/update gate\n(also for the key's own account — there is no self-service balance\ninternally either). Mirrors the internal work-schedules balance:\n`balance_ms` = actual work time − contract target + manual\nadjustments, computed from the first work-schedule model\n(`since`) up to and including `as_of`. Never persisted — always\nderived. Employees without a maintained work-schedule model are not\nreturned. Customer accounts are blocked (403).\n",
        "parameters": [
          {
            "name": "as_of",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "account_id",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "Restrict to one employee; default = all with a model."
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: [{account_id, since, contract_minutes, actual_ms,\nadjustment_minutes, balance_ms}] }`\n"
          },
          "403": {
            "description": "Key account lacks the view/update gate."
          }
        }
      }
    },
    "/v1/qualifications": {
      "get": {
        "summary": "Qualification catalog",
        "description": "Requires scope `accounts:read`. Tenant catalog incl. usage counters\n(`account_count` = assigned employees, `staffing_count` = work-order\nstaffing demand rows). Customer accounts are blocked (403).\nThe counters follow the key account's person scope: a key of a\nsubcontractor account (role `own_only`) counts `account_count` only\nover itself and its own employees, and `staffing_count` is then 0 —\nthe same rule as `GET /v1/accounts`.\n",
        "responses": {
          "200": {
            "description": "`{ data: Qualification[] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Qualification"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create a qualification",
        "description": "Requires scope `accounts:write` and the right to manage catalogs\n(admin roles). `name` is trimmed, 2–120 characters and unique per\ntenant (case-sensitive) — a duplicate answers 409\n`QUALIFICATION_NAME_DUPLICATE`. Creating needs no change reason; a\n`change_reason` given anyway is stored with the `created` row.\n",
        "parameters": [
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 120
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Optional (alternatively header X-Change-Reason)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created qualification.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Qualification"
                }
              }
            }
          },
          "403": {
            "description": "Key account lacks the catalog right."
          },
          "409": {
            "description": "Standard error body with `reason: QUALIFICATION_NAME_DUPLICATE` (also in `error`) — the name already exists in this tenant."
          },
          "422": {
            "description": "Validation failed."
          }
        }
      }
    },
    "/v1/qualifications/{id}": {
      "patch": {
        "summary": "Rename a qualification",
        "description": "Requires scope `accounts:write` and the right to manage catalogs.\nSame name rules as creation (409 `QUALIFICATION_NAME_DUPLICATE`).\nA qualification of another tenant answers 404. The rename is recorded\nin the configuration audit trail; `change_reason` is required when\nthe tenant policy demands one.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 120
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Alternative to the X-Change-Reason header (same rules)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated qualification.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Qualification"
                }
              }
            }
          },
          "404": {
            "description": "Qualification not found in this tenant."
          },
          "409": {
            "description": "Standard error body with `reason: QUALIFICATION_NAME_DUPLICATE` (also in `error`)."
          },
          "422": {
            "$ref": "#/components/responses/ChangeReasonRequired"
          }
        }
      },
      "delete": {
        "summary": "Delete a qualification",
        "description": "Requires scope `accounts:write` and the right to manage catalogs.\nHard delete: assignments to employees are dropped and work-order\nstaffing demand rows lose the qualification (they keep their head\ncount). There is no undo — read `account_count`/`staffing_count`\nfrom the catalog first. A qualification of another tenant answers\n404. `change_reason` is optional and stored in the audit trail.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "404": {
            "description": "Qualification not found in this tenant."
          }
        }
      }
    },
    "/v1/qualifications/account/{id}": {
      "get": {
        "summary": "Qualifications assigned to an employee",
        "description": "Requires scope `accounts:read`. Sorted like the catalog. Follows the\nperson scope of the key's account (a subcontractor key reaches only\nits own people); an account outside that scope answers 404.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: AccountQualification[] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AccountQualification"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Account not found in this tenant or outside the key's person scope."
          }
        }
      },
      "put": {
        "summary": "Set the qualifications of an employee",
        "description": "Requires scope `accounts:write` and the right to edit people. Set\nsemantics: the given ids replace the whole assignment, an empty list\nremoves every qualification. Up to 200 ids; an id that does not exist\nin this tenant answers 422 `UNKNOWN_QUALIFICATION_IDS`. Same person\nscope as GET (outside = 404). The change is recorded in the account\nhistory; `change_reason` is required when the tenant policy demands\none.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "$ref": "#/components/parameters/XChangeReason"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "qualification_ids"
                ],
                "additionalProperties": false,
                "properties": {
                  "qualification_ids": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "maxItems": 200,
                    "uniqueItems": true
                  },
                  "change_reason": {
                    "type": "string",
                    "maxLength": 2000,
                    "description": "Alternative to the X-Change-Reason header (same rules)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`{ data: AccountQualification[] }` — the assignment after the call.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AccountQualification"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Account not found in this tenant or outside the key's person scope."
          },
          "422": {
            "description": "Standard error body with `reason: UNKNOWN_QUALIFICATION_IDS` (also in `error`; the message names the ids), or a schema error."
          }
        }
      }
    },
    "/v1/report-types": {
      "get": {
        "summary": "Report types this key may request",
        "description": "Requires scope `reports:read`. Only the types the key's account may\nrequest (export right of the report, view right of its area, package,\ncompany switch). Subcontractor accounts get an empty list. No mail\ndelivery, no subscriptions, no ZIP — reports are download links.\n",
        "responses": {
          "200": {
            "description": "`{ data: ReportTypeInfo[] }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ReportTypeInfo"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/exports": {
      "post": {
        "summary": "Request a report (PDF/CSV/XLSX) as a download link",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKeyText"
          }
        ],
        "description": "Requires scope `reports:write`. Starts the report in the background\nand answers 202 with the run; poll `GET /v1/exports/{id}` until\n`status` is `ready`, then fetch `download_url` (valid 60 minutes).\n\nRules: `from`/`to` (both included) at most `max_days` of the type\n(patrol_coverage 14, workdays 62, else 92). service_level_summary\ncovers the billing period that contains `to` and is only available\nto accounts without property restriction. Accounts restricted to\ncertain properties must pass `property_id`. `account_id` (time\nreports only): another person only with the right to see other\npeople's times. Subcontractor accounts: 403.\n\nLimits: 10 starts per 10 minutes per key, 2 running reports per\naccount, 5 per company, 50 per company per day → 429\n`EXPORT_LIMIT_REACHED` with `Retry-After`.\n\nIdempotency: an identical request within the same 5-minute window\nreturns the same run (`deduped: true`); with `idempotency_key` the\nsame run permanently — the same key with other parameters → 409.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "type",
                  "from",
                  "to"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "time_entries",
                      "attendance",
                      "patrol_coverage",
                      "incidents",
                      "tasks",
                      "form_responses",
                      "workdays",
                      "service_level_summary"
                    ]
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "pdf",
                      "csv",
                      "xlsx"
                    ],
                    "description": "Default = `default_format` of the type."
                  },
                  "from": {
                    "type": "string",
                    "format": "date",
                    "description": "First day (YYYY-MM-DD)."
                  },
                  "to": {
                    "type": "string",
                    "format": "date",
                    "description": "Last day (YYYY-MM-DD), included."
                  },
                  "property_id": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 1
                  },
                  "account_id": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 1
                  },
                  "locale": {
                    "type": "string",
                    "enum": [
                      "de",
                      "en"
                    ],
                    "description": "Language of the file. Default = the account's language."
                  },
                  "idempotency_key": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9._:-]{8,64}$"
                  }
                }
              },
              "example": {
                "type": "time_entries",
                "format": "pdf",
                "from": "2026-09-01",
                "to": "2026-09-30",
                "property_id": 12,
                "idempotency_key": "stunden-2026-09-p12"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "`{ data: ExportRun & { deduped: boolean } }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/ExportRun"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "deduped": {
                              "type": "boolean"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "`NOT_PERMITTED` (`details.reason`) — or the key lacks `reports:write`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportExportError"
                }
              }
            }
          },
          "404": {
            "description": "`NOT_FOUND` — unknown `account_id`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportExportError"
                }
              }
            }
          },
          "409": {
            "description": "`IDEMPOTENCY_KEY_REUSED`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportExportError"
                }
              }
            }
          },
          "422": {
            "description": "`REPORT_TYPE_UNKNOWN`, `REPORT_FORMAT_UNSUPPORTED`,\n`REPORT_RANGE_TOO_LONG`, `PROPERTY_REQUIRED`, `INVALID_INPUT` —\nor a body that fails the schema (unknown fields are refused).\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportExportError"
                }
              }
            }
          },
          "429": {
            "description": "`EXPORT_LIMIT_REACHED` (`details.limit`, `details.max`), with `Retry-After` (seconds).",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportExportError"
                }
              }
            }
          },
          "503": {
            "description": "`EXPORT_UNAVAILABLE` — try again later.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportExportError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/exports/{id}": {
      "get": {
        "summary": "Status and download link of a requested report",
        "description": "Requires scope `reports:read`. Only runs the same account started via\nREST or the KI-Anbindung; runs from the portal and runs of other\naccounts answer 404. `download_url` appears when `status` is\n`ready`; a new link is issued when less than 5 minutes are left.\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`{ data: ExportRun }`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ExportRun"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "`NOT_PERMITTED` — subcontractor account or export right lost.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportExportError"
                }
              }
            }
          },
          "404": {
            "description": "`NOT_FOUND`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReportExportError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/webhooks": {
      "get": {
        "summary": "List outgoing webhooks",
        "description": "Requires scope `webhooks:read` and the role right to read settings.\nAt most 5 webhooks per company. Answers 404 while webhooks are not\nswitched on for the installation.\n",
        "responses": {
          "200": {
            "description": "All webhooks of the company, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookSubscription"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create an outgoing webhook",
        "description": "Requires scope `webhooks:write` and the role right to change settings.\nTime entry events need the right to see the times of all people.\nThe answer carries the signing secret ONCE.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "name",
                  "url",
                  "events"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "url": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "events": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "$ref": "#/components/schemas/WebhookEventType"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created — with `secret`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WebhookSubscriptionWithSecret"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "`reason`: `WEBHOOK_URL_INVALID`, `WEBHOOK_URL_FORBIDDEN_HOST`,\n`WEBHOOK_QUOTA_REACHED`, `WEBHOOK_EVENT_NOT_PERMITTED`,\n`WEBHOOK_EVENTS_INVALID`, `WEBHOOK_NAME_INVALID`.\n"
          },
          "503": {
            "description": "`WEBHOOKS_NOT_CONFIGURED` — the installation cannot seal secrets."
          }
        }
      }
    },
    "/v1/webhooks/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Get an outgoing webhook",
        "description": "Requires scope `webhooks:read`. Another company's id answers 404.",
        "responses": {
          "200": {
            "description": "The webhook, without secret.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WebhookSubscription"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Change, pause, re-activate or renew the secret",
        "description": "Requires scope `webhooks:write`. `status` accepts `active` and `paused`\n— `active` also re-activates a webhook LiteLog switched off and resets\nthe failure counter. `rotate_secret: true` issues a new secret, which\nthe answer carries ONCE. For `grace_hours` (default 24, 0–168) every\ndelivery additionally carries `X-LiteLog-Signature-Previous`, signed\nwith the previous secret, so a receiver can switch without dropping\ndeliveries; `X-LiteLog-Signature` always uses the new secret.\n`grace_hours: 0` switches at once. A renewal during a running grace\nperiod replaces it.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "minProperties": 1,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "url": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "events": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "$ref": "#/components/schemas/WebhookEventType"
                    }
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "active",
                      "paused"
                    ]
                  },
                  "rotate_secret": {
                    "type": "boolean",
                    "enum": [
                      true
                    ]
                  },
                  "grace_hours": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 168,
                    "default": 24,
                    "description": "Only with `rotate_secret`. Hours the previous secret keeps signing `X-LiteLog-Signature-Previous`."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The changed webhook; with `secret` only after `rotate_secret`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WebhookSubscriptionWithSecret"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete an outgoing webhook",
        "description": "Requires scope `webhooks:write`. Waiting deliveries are dropped.",
        "responses": {
          "204": {
            "description": "Deleted."
          }
        }
      }
    },
    "/v1/webhooks/{id}/test": {
      "post": {
        "summary": "Send a test delivery now",
        "description": "Requires scope `webhooks:write`. Sends one signed request with made-up\nIDs and the header `X-LiteLog-Test: true` and answers how it ended.\nNot retried, counts for no switch-off rule. At most 5 per minute per\ncompany (429 beyond that).\n",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Outcome of the request.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WebhookTestResult"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/webhooks/{id}/deliveries": {
      "get": {
        "summary": "Delivery log of a webhook (last 30 days)",
        "description": "Requires scope `webhooks:read`. Newest first.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/PageSize"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "running",
                "delivered",
                "failed",
                "dead",
                "skipped"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged log.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookDeliveryLogEntry"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "pageSize": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "litelogEvent": {
      "post": {
        "summary": "Event sent to a subscribed URL",
        "description": "LiteLog sends `POST` with a JSON body (`WebhookEnvelope`) to the URL of\nevery active webhook that ordered the event and whose account may see\nit at that moment (property access, time rights).\n\nHeaders: `X-LiteLog-Event` (type), `X-LiteLog-Event-Id` (= `id`),\n`X-LiteLog-Delivery` (id of this delivery), `X-LiteLog-Timestamp`\n(seconds since 1970), `X-LiteLog-Signature: v1=<hex>` with\n`<hex> = HMAC-SHA256(secret, \"<timestamp>.<raw body>\")`.\nRefuse timestamps older than 5 minutes. During the grace period after\na renewal, `X-LiteLog-Signature-Previous` carries the same format\nsigned with the previous secret; accept the request when either\nheader matches the secret you hold.\n\nAnswer with any 2xx within 10 seconds. Redirects are not followed and\ncount as failure. Retries: 1 min, 5 min, 15 min, 1 h, 3 h, 6 h, 12 h,\n24 h (±20 %), then given up. `410 Gone` switches the webhook off at\nonce; 20 failures in a row or more than 1000 waiting deliveries do too.\n",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEnvelope"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Received."
          }
        }
      }
    }
  }
}
