{
 "openapi": "3.1.0",
 "info": {
  "title": "Druckpilot REST-API",
  "version": "1.0.0",
  "description": "Lesen von Kunden, Standorten, Geräten, Verträgen und Artikeln; Liefern von Zählerständen. Authentifizierung mit API-Schlüssel (Verwaltung → API & Schnittstellen) im Header `Authorization: Bearer dp_…`. Höchstens 300 Anfragen pro Minute und IP. Beträge in CHF als exakte Dezimalzahlen."
 },
 "servers": [
  {
   "url": "/api/v1"
  }
 ],
 "security": [
  {
   "schluessel": []
  }
 ],
 "paths": {
  "/kunden": {
   "get": {
    "summary": "Kunden",
    "tags": [
     "Stammdaten"
    ],
    "parameters": [
     {
      "name": "seite",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "default": 1
      }
     },
     {
      "name": "pro_seite",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 500,
       "default": 100
      }
     },
     {
      "name": "kunde_id",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": ""
     },
     {
      "name": "suche",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Teil des Namens/der Nummer (Gross-/Kleinschreibung egal)"
     },
     {
      "name": "aktiv",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "nur aktive (true) oder inaktive (false)"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "seite": {
           "type": "integer"
          },
          "pro_seite": {
           "type": "integer"
          },
          "daten": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Kunde"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     }
    }
   }
  },
  "/kunden/{id}": {
   "get": {
    "summary": "Ein Kunde",
    "tags": [
     "Stammdaten"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Kunde"
        }
       }
      }
     },
     "401": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     },
     "404": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     }
    }
   }
  },
  "/standorte": {
   "get": {
    "summary": "Standorte",
    "tags": [
     "Stammdaten"
    ],
    "parameters": [
     {
      "name": "seite",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "default": 1
      }
     },
     {
      "name": "pro_seite",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 500,
       "default": 100
      }
     },
     {
      "name": "kunde_id",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": ""
     },
     {
      "name": "standort_id",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": ""
     },
     {
      "name": "suche",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Teil des Namens/der Nummer (Gross-/Kleinschreibung egal)"
     },
     {
      "name": "aktiv",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "nur aktive (true) oder inaktive (false)"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "seite": {
           "type": "integer"
          },
          "pro_seite": {
           "type": "integer"
          },
          "daten": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Standort"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     }
    }
   }
  },
  "/geraete": {
   "get": {
    "summary": "Geräte mit letztem Zählerstand",
    "tags": [
     "Stammdaten"
    ],
    "parameters": [
     {
      "name": "seite",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "default": 1
      }
     },
     {
      "name": "pro_seite",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 500,
       "default": 100
      }
     },
     {
      "name": "kunde_id",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": ""
     },
     {
      "name": "standort_id",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": ""
     },
     {
      "name": "vertrag_id",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": ""
     },
     {
      "name": "seriennr",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "genaue Seriennummer"
     },
     {
      "name": "suche",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Teil des Namens/der Nummer (Gross-/Kleinschreibung egal)"
     },
     {
      "name": "aktiv",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "nur aktive (true) oder inaktive (false)"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "seite": {
           "type": "integer"
          },
          "pro_seite": {
           "type": "integer"
          },
          "daten": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Geraet"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     }
    }
   }
  },
  "/geraete/{id}": {
   "get": {
    "summary": "Ein Gerät",
    "tags": [
     "Stammdaten"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Geraet"
        }
       }
      }
     },
     "401": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     },
     "404": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     }
    }
   }
  },
  "/vertraege": {
   "get": {
    "summary": "Verträge mit Positionen und Geräten",
    "tags": [
     "Stammdaten"
    ],
    "parameters": [
     {
      "name": "seite",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "default": 1
      }
     },
     {
      "name": "pro_seite",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 500,
       "default": 100
      }
     },
     {
      "name": "kunde_id",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": ""
     },
     {
      "name": "vertrag_id",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": ""
     },
     {
      "name": "suche",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Teil des Namens/der Nummer (Gross-/Kleinschreibung egal)"
     },
     {
      "name": "aktiv",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "laufend (true) oder beendet (false)"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "seite": {
           "type": "integer"
          },
          "pro_seite": {
           "type": "integer"
          },
          "daten": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Vertrag"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     }
    }
   }
  },
  "/artikel": {
   "get": {
    "summary": "Artikel mit Kontierung",
    "tags": [
     "Stammdaten"
    ],
    "parameters": [
     {
      "name": "seite",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "default": 1
      }
     },
     {
      "name": "pro_seite",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 500,
       "default": 100
      }
     },
     {
      "name": "suche",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Teil des Namens/der Nummer (Gross-/Kleinschreibung egal)"
     },
     {
      "name": "aktiv",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "nur aktive (true) oder inaktive (false)"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "seite": {
           "type": "integer"
          },
          "pro_seite": {
           "type": "integer"
          },
          "daten": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Artikel"
           }
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     }
    }
   }
  },
  "/zaehlerstaende": {
   "post": {
    "summary": "Zählerstände liefern (Fernablesung)",
    "tags": [
     "Zählerstände"
    ],
    "description": "Braucht einen Schlüssel mit Schreibrecht. Höchstens 1000 Einträge pro Anfrage. Jeder Eintrag wird einzeln geprüft (z. B. Zähler darf nicht sinken). 200 wenn alle gespeichert, sonst 207 mit Ergebnis pro Eintrag.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "array",
        "maxItems": 1000,
        "items": {
         "$ref": "#/components/schemas/ZaehlerstandNeu"
        }
       },
       "example": [
        {
         "seriennr": "A1B2C3D4",
         "datum": "2026-11-30",
         "sw": 123456,
         "co": 45678
        }
       ]
      }
     }
    },
    "responses": {
     "200": {
      "description": "alle gespeichert",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ZaehlerErgebnis"
        }
       }
      }
     },
     "207": {
      "description": "teilweise gespeichert",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ZaehlerErgebnis"
        }
       }
      }
     },
     "401": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     },
     "403": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     },
     "422": {
      "description": "Fehler",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fehler"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "schluessel": {
    "type": "http",
    "scheme": "bearer",
    "description": "API-Schlüssel dp_…"
   }
  },
  "schemas": {
   "Fehler": {
    "type": "object",
    "properties": {
     "fehler": {
      "type": "string"
     }
    }
   },
   "Adresse": {
    "type": "object",
    "properties": {
     "zeile1": {
      "type": "string"
     },
     "zeile2": {
      "type": "string"
     },
     "strasse": {
      "type": "string"
     },
     "plz": {
      "type": "string"
     },
     "ort": {
      "type": "string"
     },
     "land": {
      "type": "string"
     }
    }
   },
   "Kunde": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "kundennr": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "uid": {
      "type": [
       "string",
       "null"
      ]
     },
     "aktiv": {
      "type": "boolean"
     },
     "versandart": {
      "type": "string",
      "enum": [
       "pdf",
       "e_bill",
       "post"
      ]
     },
     "rechnung_email": {
      "type": [
       "string",
       "null"
      ]
     },
     "ebill_empfaenger_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "zahlungsfrist_tage": {
      "type": "integer"
     },
     "rechnungsadresse": {
      "$ref": "#/components/schemas/Adresse"
     },
     "erstellt_am": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Standort": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "kunde_id": {
      "type": "string",
      "format": "uuid"
     },
     "bezeichnung": {
      "type": "string"
     },
     "kontakt_name": {
      "type": [
       "string",
       "null"
      ]
     },
     "kontakt_telefon": {
      "type": [
       "string",
       "null"
      ]
     },
     "aktiv": {
      "type": "boolean"
     },
     "adresse": {
      "$ref": "#/components/schemas/Adresse"
     }
    }
   },
   "Geraet": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "seriennr": {
      "type": "string"
     },
     "inventarnr": {
      "type": [
       "string",
       "null"
      ]
     },
     "status": {
      "type": "string"
     },
     "hersteller": {
      "type": "string"
     },
     "modell": {
      "type": "string"
     },
     "farbfaehig": {
      "type": "boolean"
     },
     "standort_id": {
      "type": [
       "string",
       "null"
      ],
      "format": "uuid"
     },
     "kunde_id": {
      "type": [
       "string",
       "null"
      ],
      "format": "uuid"
     },
     "installiert_am": {
      "type": [
       "string",
       "null"
      ],
      "format": "date"
     },
     "garantie_bis": {
      "type": [
       "string",
       "null"
      ],
      "format": "date"
     },
     "gebaeude": {
      "type": [
       "string",
       "null"
      ]
     },
     "etage": {
      "type": [
       "string",
       "null"
      ]
     },
     "raum": {
      "type": [
       "string",
       "null"
      ]
     },
     "aktiv": {
      "type": "boolean"
     },
     "letzter_zaehlerstand": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "datum": {
        "type": "string",
        "format": "date"
       },
       "sw": {
        "type": "integer"
       },
       "co": {
        "type": "integer"
       },
       "quelle": {
        "type": "string"
       }
      }
     }
    }
   },
   "Vertrag": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "vertragsnr": {
      "type": "string"
     },
     "kunde_id": {
      "type": "string",
      "format": "uuid"
     },
     "beginn": {
      "type": "string",
      "format": "date"
     },
     "ende": {
      "type": [
       "string",
       "null"
      ],
      "format": "date"
     },
     "kuendigungsfrist_monate": {
      "type": "integer"
     },
     "turnus": {
      "type": "string",
      "enum": [
       "monat",
       "quartal",
       "halbjahr",
       "jahr"
      ]
     },
     "verrechnung": {
      "type": "string",
      "enum": [
       "voraus",
       "nachhinein"
      ]
     },
     "naechste_periode_ab": {
      "type": "string",
      "format": "date"
     },
     "bemerkung": {
      "type": [
       "string",
       "null"
      ]
     },
     "positionen": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "artikel_id": {
         "type": "string",
         "format": "uuid"
        },
        "artikelnr": {
         "type": "string"
        },
        "art": {
         "type": "string"
        },
        "text": {
         "type": [
          "string",
          "null"
         ]
        },
        "preis_chf": {
         "type": "number",
         "description": "bis 5 Nachkommastellen"
        },
        "inklusiv_menge": {
         "type": [
          "integer",
          "null"
         ]
        },
        "gueltig_ab": {
         "type": "string",
         "format": "date"
        },
        "gueltig_bis": {
         "type": [
          "string",
          "null"
         ],
         "format": "date"
        }
       }
      }
     },
     "geraete": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "geraet_id": {
         "type": "string",
         "format": "uuid"
        },
        "seriennr": {
         "type": "string"
        },
        "gueltig_von": {
         "type": "string",
         "format": "date"
        },
        "gueltig_bis": {
         "type": [
          "string",
          "null"
         ],
         "format": "date"
        }
       }
      }
     }
    }
   },
   "Artikel": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "artikelnr": {
      "type": "string"
     },
     "bezeichnung": {
      "type": "string"
     },
     "art": {
      "type": "string"
     },
     "einheit": {
      "type": "string"
     },
     "standardpreis_chf": {
      "type": [
       "number",
       "null"
      ]
     },
     "erloeskonto": {
      "type": "string"
     },
     "mwst_code": {
      "type": "string"
     },
     "kostenstelle": {
      "type": [
       "string",
       "null"
      ]
     },
     "aktiv": {
      "type": "boolean"
     }
    }
   },
   "ZaehlerstandNeu": {
    "type": "object",
    "required": [
     "datum",
     "sw"
    ],
    "description": "geraet_id oder seriennr angeben",
    "properties": {
     "geraet_id": {
      "type": "string",
      "format": "uuid"
     },
     "seriennr": {
      "type": "string"
     },
     "datum": {
      "type": "string",
      "format": "date"
     },
     "sw": {
      "type": "integer",
      "minimum": 0
     },
     "co": {
      "type": "integer",
      "minimum": 0,
      "default": 0
     }
    }
   },
   "ZaehlerErgebnis": {
    "type": "object",
    "properties": {
     "gespeichert": {
      "type": "integer"
     },
     "ergebnisse": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "index": {
         "type": "integer"
        },
        "ok": {
         "type": "boolean"
        },
        "id": {
         "type": "string",
         "format": "uuid"
        },
        "geraet_id": {
         "type": "string",
         "format": "uuid"
        },
        "fehler": {
         "type": "string"
        }
       }
      }
     }
    }
   }
  }
 }
}
