{
  "openapi": "3.1.0",
  "info": {
    "title": "Tabak Brucker API",
    "description": "REST API fuer den Tabak Brucker Online-Shop. Bietet lesenden Zugriff auf Produkte, Kategorien und Suche. Alle Preise in EUR. Mindestbestellalter: 18 Jahre.",
    "version": "1.0.0",
    "contact": {
      "name": "Tabak Brucker",
      "url": "https://www.tabak-brucker.de"
    }
  },
  "servers": [
    {
      "url": "https://www.tabak-brucker.de/api/v1",
      "description": "Produktiv-Server"
    }
  ],
  "paths": {
    "/produkte": {
      "get": {
        "operationId": "listProducts",
        "summary": "Alle Produkte auflisten (paginiert)",
        "description": "Gibt eine paginierte Liste aller aktiven Produkte zurueck. Optional filterbar nach Kategorie oder Marke.",
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "description": "Seitennummer (ab 1)",
            "schema": { "type": "integer", "minimum": 1, "default": 1 }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Produkte pro Seite (1-100)",
            "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 50 }
          },
          {
            "name": "kategorie_id",
            "in": "query",
            "description": "Filter nach Kategorie-ID",
            "schema": { "type": "integer" }
          },
          {
            "name": "marke_id",
            "in": "query",
            "description": "Filter nach Marken-ID",
            "schema": { "type": "integer" }
          }
        ],
        "responses": {
          "200": {
            "description": "Liste von Produkten",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "metadata": { "$ref": "#/components/schemas/PaginationMetadata" },
                    "products": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Product" }
                    }
                  }
                }
              }
            }
          },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/produkte/{id}": {
      "get": {
        "operationId": "getProduct",
        "summary": "Einzelnes Produkt abrufen",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Produkt-ID",
            "schema": { "type": "integer" }
          }
        ],
        "responses": {
          "200": {
            "description": "Produktdaten",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Product" }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/kategorien": {
      "get": {
        "operationId": "listCategories",
        "summary": "Alle Kategorien auflisten",
        "responses": {
          "200": {
            "description": "Liste aller Kategorien",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "metadata": {
                      "type": "object",
                      "properties": {
                        "count": { "type": "integer", "description": "Anzahl Kategorien" }
                      }
                    },
                    "categories": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Category" }
                    }
                  }
                }
              }
            }
          },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/kategorien/{id}": {
      "get": {
        "operationId": "getCategory",
        "summary": "Einzelne Kategorie abrufen",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Kategorie-ID",
            "schema": { "type": "integer" }
          }
        ],
        "responses": {
          "200": {
            "description": "Kategoriedaten",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Category" }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/suche": {
      "get": {
        "operationId": "searchProducts",
        "summary": "Produktsuche",
        "description": "Volltextsuche ueber Produktnamen, Artikelnummer, EAN und Beschreibung. Ergebnisse nach Relevanz sortiert.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "description": "Suchbegriff (mindestens 2 Zeichen)",
            "schema": { "type": "string", "minLength": 2 }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Max. Anzahl Ergebnisse (1-50)",
            "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 20 }
          }
        ],
        "responses": {
          "200": {
            "description": "Suchergebnisse",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "metadata": {
                      "type": "object",
                      "properties": {
                        "query": { "type": "string" },
                        "count": { "type": "integer" }
                      }
                    },
                    "products": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Product" }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Suchbegriff zu kurz",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Error" }
              }
            }
          },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Product": {
        "type": "object",
        "properties": {
          "id": { "type": "integer", "description": "Produkt-ID", "example": 307535 },
          "name": { "type": "string", "description": "Produktname", "example": "Marlboro Gold 20er" },
          "sku": { "type": "string", "description": "Artikelnummer", "example": "tc-126" },
          "url": { "type": "string", "format": "uri", "description": "Produkt-URL", "example": "https://www.tabak-brucker.de/marlboro-gold-20er" },
          "price": { "type": "string", "description": "Bruttopreis (inkl. MwSt.)", "example": "9.40" },
          "price_net": { "type": "string", "description": "Nettopreis (exkl. MwSt.)", "example": "7.90" },
          "price_formatted": { "type": "string", "description": "Formatierter Preis", "example": "9,40 Euro" },
          "currency": { "type": "string", "enum": ["EUR"], "description": "Waehrung" },
          "in_stock": { "type": "boolean", "description": "Ob Produkt lieferbar ist" },
          "availability": { "type": "string", "description": "Verfuegbarkeitstext", "example": "sofort versandbereit" },
          "delivery_time": { "type": "string", "description": "Lieferzeit-Angabe", "example": "Lieferzeit: 1-3 Werktage**" },
          "brand": { "type": "string", "description": "Markenname", "example": "Marlboro" },
          "manufacturer": { "type": "string", "description": "Herstellername", "example": "Philip Morris GmbH" },
          "gtin13": { "type": "string", "description": "EAN/GTIN-13 Barcode", "example": "4023500757133" },
          "image": { "type": "string", "format": "uri", "description": "Produktbild-URL" },
          "category": { "type": "string", "description": "Kategoriename", "example": "Marlboro" },
          "unit_price": { "type": "string", "description": "Grundpreis", "example": "0,47 \u20ac/Stk" }
        },
        "required": ["id", "name", "sku", "url", "price", "price_net", "currency", "in_stock", "availability"]
      },
      "Category": {
        "type": "object",
        "properties": {
          "id": { "type": "integer", "description": "Kategorie-ID", "example": 100 },
          "name": { "type": "string", "description": "Kategoriename", "example": "Zigaretten" },
          "url": { "type": "string", "format": "uri", "description": "Kategorie-URL" },
          "parent_id": { "type": "integer", "description": "ID der uebergeordneten Kategorie (0 = Hauptkategorie)" },
          "description": { "type": "string", "description": "Kategorie-Beschreibung" }
        },
        "required": ["id", "name"]
      },
      "PaginationMetadata": {
        "type": "object",
        "properties": {
          "page": { "type": "integer", "description": "Aktuelle Seite" },
          "limit": { "type": "integer", "description": "Eintraege pro Seite" },
          "count": { "type": "integer", "description": "Anzahl in dieser Antwort" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string", "description": "Fehlermeldung" }
        }
      }
    },
    "responses": {
      "NotFound": {
        "description": "Ressource nicht gefunden",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" }
          }
        }
      },
      "RateLimited": {
        "description": "Rate-Limit ueberschritten (max. 30 Requests/Minute)",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": { "type": "string" },
                "retry_after": { "type": "integer", "description": "Sekunden bis zum naechsten erlaubten Request" }
              }
            }
          }
        }
      }
    }
  }
}
