{
  "openapi": "3.1.0",
  "info": {
    "title": "1inks API",
    "version": "1.2.0",
    "description": "Kurzlinks und dynamische QR-Codes von 1inks.\n\n**Anmeldung:** jeder Aufruf mit `Authorization: Bearer <API-Key>`. Schlüssel legt ein Administrator im Portal unter *API-Schlüssel* an; er wird nur einmal angezeigt.\n\n**Reichweite:** Ein *Admin-Schlüssel* sieht alle Kunden. Ein *Kunden-Schlüssel* sieht und ändert nur Links seines Kunden und nur auf dessen freigegebenen Domains – andere Links antworten mit 404.\n\n**QR-Codes:** Der Code zeigt immer auf die Kurz-URL (`qr_url`), nie direkt auf das Ziel. So lässt sich das Ziel nach dem Druck ändern. Das Design (Farben, Formen, Rahmen, Logo) gehört zum Link; `GET /links/{id}/qr` liefert es als druckfähiges SVG – identisch mit dem Portal-Download. PNG/JPG/PDF erzeugt der Aufrufer aus dem SVG (der MCP-Server `xmc-1inks-mcp` macht das automatisch).\n\n**Klicks und Scans (ab 1.2):** `GET /clicks` und `GET /links/{id}/clicks` liefern jeden Aufruf einzeln – Zeitpunkt (UTC), Quelle (`qr` = Scan, `link` = Aufruf), Geräteklasse, Land und `is_first` (erster Aufruf des Links). Mehr wird nicht herausgegeben: 1inks speichert keine IP-Adressen; Stadt, Browser und Besucher-Kennung bleiben im Portal. Bots sind ausgeblendet. `GET /stats` fasst viele Links (Tag oder ID-Liste) in einem Aufruf zusammen, `GET /stats/{id}?bucket=hour` zählt stündlich in Europe/Berlin.\n\n**Webhooks (ab 1.2):** `POST /webhooks` meldet jeden Aufruf (`click`) oder nur den ersten je Link (`click.first`) sofort an Ihre https-Adresse – signiert, mit Wiederholung bei Fehlern. Einzelheiten und Prüfcode im Abschnitt *Webhooks*.\n\n**Pakete:** Schnittstelle und KI-Assistenten gibt es ab dem Paket Business. Fehlt eine Funktion im Paket des Kunden (Schnittstelle, Webhooks, Statistik, Druckdateien, Website-Farben), antwortet die API mit 403 und `{ \"error\": \"…\", \"code\": \"paket\", \"funktion\": \"…\", \"ab_paket\": \"Business\" }`.\n\n**Fehler:** JSON `{ \"error\": \"…\" }` mit HTTP-Status 400/401/403/404/409/422/429/500."
  },
  "servers": [
    {
      "url": "https://app.1inks.de/api/public/v1"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "tags": [
    {
      "name": "Konto",
      "description": "Was darf dieser Schlüssel?"
    },
    {
      "name": "Links",
      "description": "Kurzlinks anlegen, lesen, ändern"
    },
    {
      "name": "QR-Codes",
      "description": "Design und Ausgabe der QR-Codes"
    },
    {
      "name": "Statistik",
      "description": "Klicks und Scans"
    },
    {
      "name": "Webhooks",
      "description": "Benachrichtigung in Echtzeit, sobald ein Link aufgerufen oder gescannt wird"
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "tags": [
          "Konto"
        ],
        "summary": "Schlüssel-Info",
        "responses": {
          "200": {
            "description": "Reichweite des Schlüssels",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/domains": {
      "get": {
        "tags": [
          "Konto"
        ],
        "summary": "Nutzbare Kurzlink-Domains",
        "responses": {
          "200": {
            "description": "Domains",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Domain"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/customers": {
      "get": {
        "tags": [
          "Konto"
        ],
        "summary": "Kunden (Kunden-Schlüssel: nur der eigene)",
        "responses": {
          "200": {
            "description": "Kunden",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Customer"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/presets": {
      "get": {
        "tags": [
          "QR-Codes"
        ],
        "summary": "Gespeicherte QR-Designs je Kunde",
        "parameters": [
          {
            "name": "customer_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Vorlagen",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Preset"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/links": {
      "get": {
        "tags": [
          "Links"
        ],
        "summary": "Links auflisten (neueste zuerst)",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 1000
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "domain",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "examples": {
              "d": {
                "value": "1inks.de"
              }
            }
          },
          {
            "name": "tag",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "customer_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Links",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Link"
                      }
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "tags": [
          "Links"
        ],
        "summary": "Link + QR-Code anlegen",
        "description": "Ohne `qr_design`/`preset_id` greift die Standard-Vorlage des Kunden, sonst Schwarz auf Weiß. `preset_id` und `qr_design` lassen sich kombinieren (`qr_design` gewinnt).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LinkCreate"
              },
              "examples": {
                "einfach": {
                  "value": {
                    "domain": "1inks.de",
                    "target_url": "https://www.beispiel.de/aktion",
                    "title": "Flyer Herbst"
                  }
                },
                "gestaltet": {
                  "value": {
                    "domain": "1inks.de",
                    "target_url": "https://www.beispiel.de",
                    "slug": "herbst26",
                    "tags": [
                      "flyer"
                    ],
                    "qr_design": {
                      "fg_color": "#0E9AA7",
                      "module_shape": "dots",
                      "eye_shape": "round",
                      "frame_text": "Jetzt scannen",
                      "frame_color": "#0E9AA7"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Angelegt",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LinkCreated"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/links/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          },
          "description": "Link-ID"
        }
      ],
      "get": {
        "tags": [
          "Links"
        ],
        "summary": "Link lesen",
        "responses": {
          "200": {
            "description": "Link",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Link"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "tags": [
          "Links"
        ],
        "summary": "Link ändern (Ziel, Titel, Tags, aktiv, Ablauf, gedruckt)",
        "description": "Deaktivieren statt löschen: `{\"active\": false}`. Gedruckte Codes (`printed: true`) sind gegen versehentliche Zieländerung geschützt.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LinkPatch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Geändert",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Link"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/links/{id}/qr": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          },
          "description": "Link-ID"
        }
      ],
      "get": {
        "tags": [
          "QR-Codes"
        ],
        "summary": "QR-Code als SVG (im gespeicherten Design)",
        "parameters": [
          {
            "name": "size",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1024,
              "minimum": 64,
              "maximum": 8192
            },
            "description": "Breite in Pixel (Vektor – skaliert verlustfrei)"
          },
          {
            "name": "margin",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 4,
              "minimum": 0,
              "maximum": 8
            },
            "description": "Ruhezone in Modulen (Norm: 4)"
          },
          {
            "name": "transparent",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1"
              ],
              "default": "0"
            },
            "description": "1 = ohne Hintergrundfläche"
          }
        ],
        "responses": {
          "200": {
            "description": "SVG",
            "content": {
              "image/svg+xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/links/{id}/design": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          },
          "description": "Link-ID"
        }
      ],
      "get": {
        "tags": [
          "QR-Codes"
        ],
        "summary": "QR-Design lesen",
        "responses": {
          "200": {
            "description": "Design",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QrDesign"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "put": {
        "tags": [
          "QR-Codes"
        ],
        "summary": "QR-Design ändern (nur übergebene Felder)",
        "description": "Der gedruckte Code bleibt gültig – das Design betrifft nur neue Exporte. Optional `preset_id`, um eine Vorlage zu übernehmen.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/QrDesignInput"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "preset_id": {
                        "type": "string",
                        "format": "uuid"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Neues Design",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QrDesign"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/links/{id}/brand": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          },
          "description": "Link-ID"
        }
      ],
      "post": {
        "tags": [
          "QR-Codes"
        ],
        "summary": "Farben und Icon der Zielseite auslesen",
        "description": "Vorschläge, damit der QR-Code zur Zielseite passt (Kontrast zum Hintergrund selbst prüfen: mindestens 4,5 : 1).",
        "responses": {
          "200": {
            "description": "Vorschläge",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Brand"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/stats/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          },
          "description": "Link-ID"
        }
      ],
      "get": {
        "tags": [
          "Statistik"
        ],
        "summary": "Klicks und Scans eines Links",
        "description": "`bucket=hour` zählt stündlich in Europe/Berlin; jeder Eintrag in `series` trägt dann Beginn mit Offset (`2026-11-19T23:00:00+01:00`), `count`, `qr` und `visitors`. `day`/`week` ohne `tz` bleiben wie in 1.1 (UTC-Kalender); mit `tz=Europe/Berlin` beginnen Tage um Mitternacht deutscher Zeit.",
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 30,
              "maximum": 3650
            }
          },
          {
            "name": "bucket",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "hour",
                "day",
                "week"
              ],
              "default": "day"
            }
          },
          {
            "name": "tz",
            "in": "query",
            "description": "Zeitzone des Verlaufs; Standard bei hour: Europe/Berlin",
            "schema": {
              "type": "string",
              "enum": [
                "Europe/Berlin",
                "UTC"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Beginn (ISO 8601 mit Zone), ersetzt days",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Ende, ausschließlich (Standard: jetzt)",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Kennzahlen, Verlauf und Aufschlüsselungen",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/stats": {
      "get": {
        "tags": [
          "Statistik"
        ],
        "summary": "Kennzahlen vieler Links in einem Aufruf",
        "description": "Für Kampagnen mit einem Link je Empfänger: Summen im Zeitraum (`total`, `qr`, `link`, `unique_visitors`) und, unabhängig vom Zeitraum, `first_click_at`/`last_click_at` (`null` = noch nie aufgerufen). Ohne Filter alle Links des Schlüssels, neueste zuerst.",
        "parameters": [
          {
            "name": "tag",
            "in": "query",
            "description": "Nur Links mit diesem Tag",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "link_ids",
            "in": "query",
            "description": "Kommagetrennte Link-IDs (max. 200)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "customer_id",
            "in": "query",
            "description": "Nur Admin-Schlüssel",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 30,
              "maximum": 3650
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 500
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ein Eintrag je Link",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "from": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "to": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/LinkSummary"
                      }
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/clicks": {
      "get": {
        "tags": [
          "Statistik"
        ],
        "summary": "Einzelne Aufrufe und Scans vieler Links",
        "description": "Älteste zuerst. Zum Weiterblättern und für spätere Abfragen `cursor` = `next_cursor` der letzten Antwort setzen – so geht auch kein verspätet gemeldeter Aufruf verloren. Ohne Filter alle Links des Schlüssels.",
        "parameters": [
          {
            "name": "tag",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "link_ids",
            "in": "query",
            "description": "Kommagetrennte Link-IDs (max. 200)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "customer_id",
            "in": "query",
            "description": "Nur Admin-Schlüssel",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "since",
            "in": "query",
            "description": "Aufrufe ab (ISO 8601 mit Zone)",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "until",
            "in": "query",
            "description": "Aufrufe vor",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "next_cursor der vorigen Antwort",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Eine Seite Aufrufe",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClickPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/links/{id}/clicks": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          },
          "description": "Link-ID"
        }
      ],
      "get": {
        "tags": [
          "Statistik"
        ],
        "summary": "Einzelne Aufrufe und Scans eines Links",
        "description": "Wie `GET /clicks`, für genau einen Link.",
        "parameters": [
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "until",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Eine Seite Aufrufe",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClickPage"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Webhooks auflisten",
        "responses": {
          "200": {
            "description": "Webhooks dieses Schlüssels bzw. Kunden",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Webhook"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Webhook anmelden",
        "description": "Ein Kunden-Schlüssel erhält Ereignisse aller Links seines Kunden, ein Admin-Schlüssel wahlweise eines Kunden (`customer_id`) oder aller Links. `tag` schränkt auf Links mit diesem Tag ein. Ohne `secret` wird eines erzeugt und **nur in dieser Antwort** als `secret` zurückgegeben. Höchstens 10 Webhooks je Kunde.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookCreate"
              },
              "examples": {
                "kampagne": {
                  "value": {
                    "url": "https://crm.beispiel.de/hooks/1inks",
                    "events": [
                      "click.first",
                      "click"
                    ],
                    "tag": "azubi-2027",
                    "description": "Anrufliste Azubipaket"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Angemeldet",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Webhook"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "secret": {
                          "type": "string",
                          "description": "Nur wenn erzeugt; wird nie wieder angezeigt"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/webhooks/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          },
          "description": "Webhook-ID"
        }
      ],
      "get": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Webhook lesen",
        "responses": {
          "200": {
            "description": "Webhook",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Webhook"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Webhook ändern, pausieren oder Secret erneuern",
        "description": "`active: false` pausiert (offene Zustellungen warten), `rotate_secret: true` erzeugt ein neues Secret und gibt es einmal zurück.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookPatch"
              },
              "examples": {
                "pausieren": {
                  "value": {
                    "active": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Geändert",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Webhook"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Webhook abmelden",
        "description": "Löscht den Webhook samt Zustellprotokoll; offene Zustellungen entfallen.",
        "responses": {
          "204": {
            "description": "Abgemeldet"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/webhooks/{id}/ping": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          },
          "description": "Webhook-ID"
        }
      ],
      "post": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Testereignis senden",
        "description": "Sendet sofort ein signiertes `ping` und antwortet mit dem Ergebnis der Zustellung (kein Wiederholen). Max. 10 je Minute.",
        "responses": {
          "200": {
            "description": "Zustellung",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDelivery"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/webhooks/{id}/deliveries": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          },
          "description": "Webhook-ID"
        }
      ],
      "get": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Zustellprotokoll",
        "description": "Neueste zuerst, 30 Tage aufbewahrt.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "delivered",
                "failed"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Zustellungen",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookDelivery"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "API-Key aus dem Portal"
      }
    },
    "responses": {
      "Error": {
        "description": "Fehler",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                }
              },
              "required": [
                "error"
              ]
            }
          }
        }
      }
    },
    "schemas": {
      "Me": {
        "type": "object",
        "properties": {
          "key": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "key_prefix": {
                "type": "string"
              }
            }
          },
          "scope": {
            "type": "string",
            "enum": [
              "admin",
              "customer"
            ]
          },
          "customer": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "active": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "Domain": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "hostname": {
            "type": "string"
          }
        }
      },
      "Customer": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "brand_color": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Preset": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "is_default": {
            "type": "boolean"
          },
          "design": {
            "$ref": "#/components/schemas/QrDesignInput"
          }
        }
      },
      "QrDesignInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "fg_color": {
            "type": "string",
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "examples": [
              "#0E9AA7"
            ],
            "description": "Modulfarbe"
          },
          "bg_color": {
            "type": "string",
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "examples": [
              "#0E9AA7"
            ],
            "description": "Hintergrund"
          },
          "eye_color": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "examples": [
              "#0E9AA7"
            ],
            "description": "Farbe der drei Ecken (null = wie fg_color)"
          },
          "module_shape": {
            "type": "string",
            "enum": [
              "square",
              "rounded",
              "dots"
            ]
          },
          "eye_shape": {
            "type": "string",
            "enum": [
              "square",
              "rounded",
              "round"
            ]
          },
          "frame_text": {
            "type": "string",
            "maxLength": 40,
            "description": "Text unter dem Code (leer = kein Rahmen)"
          },
          "frame_color": {
            "type": "string",
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "examples": [
              "#0E9AA7"
            ]
          },
          "logo_url": {
            "type": [
              "string",
              "null"
            ],
            "description": "PNG als data:image/png;base64,… (mittig, max. ~300 KB)"
          }
        }
      },
      "QrDesign": {
        "allOf": [
          {
            "$ref": "#/components/schemas/QrDesignInput"
          },
          {
            "type": "object",
            "properties": {
              "error_correction": {
                "type": "string",
                "enum": [
                  "H"
                ]
              }
            }
          }
        ]
      },
      "Link": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "domain": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "short_url": {
            "type": "string",
            "description": "Zum Weitergeben"
          },
          "qr_url": {
            "type": "string",
            "description": "Inhalt des QR-Codes (zählt als Scan)"
          },
          "target_url": {
            "type": "string"
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "customer_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "printed": {
            "type": "boolean"
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string"
          },
          "updated_at": {
            "type": "string"
          }
        }
      },
      "LinkCreate": {
        "type": "object",
        "required": [
          "domain",
          "target_url"
        ],
        "properties": {
          "domain": {
            "type": "string",
            "examples": [
              "1inks.de"
            ]
          },
          "target_url": {
            "type": "string",
            "format": "uri"
          },
          "slug": {
            "type": "string",
            "description": "Wunschkürzel; ohne Angabe 5 Zeichen zufällig"
          },
          "title": {
            "type": "string"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "customer_id": {
            "type": "string",
            "format": "uuid",
            "description": "Nur Admin-Schlüssel; Kunden-Schlüssel setzen ihn automatisch"
          },
          "active": {
            "type": "boolean",
            "default": true
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "utm": {
            "type": "object",
            "properties": {
              "source": {
                "type": "string"
              },
              "medium": {
                "type": "string"
              },
              "campaign": {
                "type": "string"
              }
            }
          },
          "preset_id": {
            "type": "string",
            "format": "uuid"
          },
          "qr_design": {
            "$ref": "#/components/schemas/QrDesignInput"
          }
        }
      },
      "LinkCreated": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Link"
          },
          {
            "type": "object",
            "properties": {
              "qr_design": {
                "$ref": "#/components/schemas/QrDesign"
              },
              "qr_svg_url": {
                "type": "string",
                "description": "GET mit Bearer-Key liefert den gestalteten Code als SVG"
              },
              "qr_png_base64": {
                "type": "string",
                "description": "Veraltet: schlichter Schwarz-Weiß-Code (1024 px) ohne Design"
              }
            }
          }
        ]
      },
      "LinkPatch": {
        "type": "object",
        "properties": {
          "target_url": {
            "type": "string"
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "customer_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "expires_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "printed": {
            "type": "boolean"
          }
        }
      },
      "Brand": {
        "type": "object",
        "properties": {
          "colors": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "logo": {
            "type": [
              "string",
              "null"
            ],
            "description": "Icon als data:image/png;base64"
          },
          "logoSuggestions": {
            "type": "array",
            "items": {}
          }
        }
      },
      "Click": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Fortlaufend in Eingangsreihenfolge"
          },
          "link_id": {
            "type": "string",
            "format": "uuid"
          },
          "domain": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "ts": {
            "type": "string",
            "format": "date-time",
            "description": "Zeitpunkt des Aufrufs (UTC)"
          },
          "source": {
            "type": "string",
            "enum": [
              "qr",
              "link"
            ],
            "description": "qr = QR-Scan"
          },
          "device": {
            "type": [
              "string",
              "null"
            ],
            "description": "Geräteklasse: mobil, desktop, tablet"
          },
          "country": {
            "type": [
              "string",
              "null"
            ],
            "description": "ISO-3166-Ländercode"
          },
          "is_first": {
            "type": "boolean",
            "description": "Erster Aufruf dieses Links überhaupt"
          }
        }
      },
      "ClickPage": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Click"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "description": "ID des letzten Eintrags; leer, wenn nichts Neues kam"
          }
        }
      },
      "LinkSummary": {
        "type": "object",
        "properties": {
          "link_id": {
            "type": "string",
            "format": "uuid"
          },
          "domain": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "short_url": {
            "type": "string"
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "customer_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "total": {
            "type": "integer"
          },
          "qr": {
            "type": "integer"
          },
          "link": {
            "type": "integer"
          },
          "unique_visitors": {
            "type": "integer"
          },
          "first_click_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_click_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Webhook": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "url": {
            "type": "string"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "click",
                "click.first"
              ]
            }
          },
          "tag": {
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "customer_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "null = alle Links (Admin)"
          },
          "created_at": {
            "type": "string"
          },
          "updated_at": {
            "type": "string"
          },
          "last_success_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "last_failure_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "consecutive_failures": {
            "type": "integer"
          }
        }
      },
      "WebhookCreate": {
        "type": "object",
        "required": [
          "url"
        ],
        "additionalProperties": false,
        "properties": {
          "url": {
            "type": "string",
            "description": "Öffentliche https-Adresse, Port 443"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "click",
                "click.first"
              ]
            },
            "default": [
              "click.first"
            ]
          },
          "tag": {
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          },
          "secret": {
            "type": "string",
            "minLength": 16,
            "description": "Eigenes Secret (optional)"
          },
          "customer_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Nur Admin"
          },
          "active": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "WebhookPatch": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "url": {
            "type": "string"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "click",
                "click.first"
              ]
            }
          },
          "tag": {
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "secret": {
            "type": "string",
            "minLength": 16
          },
          "rotate_secret": {
            "type": "boolean",
            "enum": [
              true
            ]
          }
        }
      },
      "WebhookDelivery": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "= X-1inks-Delivery"
          },
          "webhook_id": {
            "type": "string",
            "format": "uuid"
          },
          "event": {
            "type": "string",
            "enum": [
              "click",
              "click.first",
              "ping"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "delivered",
              "failed"
            ]
          },
          "attempts": {
            "type": "integer"
          },
          "click_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "link_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string"
          },
          "last_attempt_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "next_attempt_at": {
            "type": [
              "string",
              "null"
            ],
            "description": "Nur bei pending"
          },
          "last_status": {
            "type": [
              "integer",
              "null"
            ],
            "description": "HTTP-Status Ihrer Antwort"
          },
          "last_error": {
            "type": [
              "string",
              "null"
            ]
          },
          "duration_ms": {
            "type": [
              "integer",
              "null"
            ]
          },
          "delivered_at": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "WebhookEvent": {
        "type": "object",
        "description": "Rumpf jeder Zustellung (POST, application/json)",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Zustell-ID, zum Entdoppeln"
          },
          "type": {
            "type": "string",
            "enum": [
              "click",
              "click.first",
              "ping"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "api_version": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "properties": {
              "click": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "integer"
                  },
                  "ts": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "source": {
                    "type": "string",
                    "enum": [
                      "qr",
                      "link"
                    ]
                  },
                  "device": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "country": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "is_first": {
                    "type": "boolean"
                  }
                }
              },
              "link": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "domain": {
                    "type": "string"
                  },
                  "slug": {
                    "type": "string"
                  },
                  "short_url": {
                    "type": "string"
                  },
                  "title": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "customer_id": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}