{
  "openapi": "3.1.0",
  "info": {
    "title": "DirectDine Menu API",
    "version": "1.0.0",
    "description": "POS-neutral REST API for reading and writing restaurant menu data on DirectDine. Designed to be compatible with Order Harmony Hub, Square Catalog v2 adapters, Toast Menus v2 bridges, Clover Inventory, and custom POS integrations.\n\n**Auth:** Per-restaurant API keys. Send as `Authorization: Bearer ddk_live_...` or `X-API-Key: ddk_live_...`.\n\n**Per-location scoping:** Every API key is bound to a single location (branch). All reads, writes, availability toggles, and webhook deliveries are automatically scoped to that location plus restaurant-wide menu items. Multi-branch restaurants must issue one key per branch.\n\n**Versioning:** URL-versioned (`/menu-api-v1-*`). Additions are non-breaking; removals require a new major version.\n\n**Rate limit:** 120 requests/minute per key by default. `429` includes `Retry-After`.\n\n**Idempotency:** All write requests support an `Idempotency-Key` header (24h dedupe window).\n\n**Currency:** All prices are integers in **minor units** (e.g. cents) using the restaurant's `currency_code`.",
    "contact": { "name": "DirectDine", "url": "https://directdine.co.za" },
    "license": { "name": "Proprietary" }
  },
  "servers": [
    { "url": "https://ypmzikfaibkbiqdwfqba.supabase.co/functions/v1", "description": "Production" }
  ],
  "security": [{ "BearerAuth": [] }, { "ApiKeyAuth": [] }],
  "tags": [
    { "name": "Menu",       "description": "Read full menu snapshot or deltas" },
    { "name": "Categories", "description": "Manage menu categories" },
    { "name": "Items",      "description": "Manage menu items" },
    { "name": "Sync",       "description": "Bulk upsert the entire menu tree" },
    { "name": "Orders",     "description": "Inject external orders (Uber Eats, DoorDash, etc.) and update lifecycle status" },
    { "name": "Webhooks",   "description": "Subscribe to real-time menu change events" }
  ],
  "paths": {
    "/menu-api-v1-menu": {
      "get": {
        "tags": ["Menu"],
        "summary": "Full menu snapshot",
        "description": "Returns categories + items in a single document. Supports `updated_since` for incremental sync and ETag/`If-None-Match` for cache validation. Pass `include=variants,addons` to embed full variant groups and addon groups per item (otherwise only `has_variants`/`has_addons` flags are returned).",
        "parameters": [
          { "name": "updated_since", "in": "query", "schema": { "type": "string", "format": "date-time" }, "description": "ISO-8601. Returns only rows changed at or after this timestamp." },
          { "name": "include", "in": "query", "schema": { "type": "string", "example": "variants,addons" }, "description": "Comma-separated list of relations to embed. Supported values: `variants`, `addons`. Omit for the lightweight default response." },
          { "name": "If-None-Match", "in": "header", "schema": { "type": "string" }, "description": "ETag from a previous response. Returns `304` when unchanged." }
        ],
        "responses": {
          "200": {
            "description": "Snapshot returned",
            "headers": { "ETag": { "schema": { "type": "string" } } },
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Menu" } } }
          },
          "304": { "description": "Not modified" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/menu-api-v1-menu/me": {"get": {"tags": ["Menu"], "summary": "Who am I", "description": "Works with any valid key, whatever its scopes. Returns the restaurant, branch, scopes and webhooks, so a POS hub can link itself when a key is pasted.", "responses": {"200": {"description": "OK", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Me"}}}}, "401": {"$ref": "#/components/responses/Unauthorized"}}}},
    "/menu-api-v1-menu/categories": {
      "get": {
        "tags": ["Categories"],
        "summary": "List categories",
        "parameters": [
          { "name": "limit",  "in": "query", "schema": { "type": "integer", "default": 100, "maximum": 500 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "default": 0 } },
          { "name": "updated_since", "in": "query", "schema": { "type": "string", "format": "date-time" } }
        ],
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "type": "object", "properties": { "categories": { "type": "array", "items": { "$ref": "#/components/schemas/Category" } } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/menu-api-v1-menu/items": {
      "get": {
        "tags": ["Items"],
        "summary": "List items",
        "parameters": [
          { "name": "limit",  "in": "query", "schema": { "type": "integer", "default": 100, "maximum": 500 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "default": 0 } },
          { "name": "updated_since", "in": "query", "schema": { "type": "string", "format": "date-time" } },
          { "name": "category_id", "in": "query", "schema": { "type": "string", "format": "uuid" } },
          { "name": "include", "in": "query", "schema": { "type": "string", "example": "variants,addons" }, "description": "Comma-separated list of relations to embed per item. Supported values: `variants`, `addons`." }
        ],
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "type": "object", "properties": { "items": { "type": "array", "items": { "$ref": "#/components/schemas/Item" } } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/menu-api-v1-write/categories": {
      "post": {
        "tags": ["Categories"],
        "summary": "Create category",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CategoryInput" } } } },
        "responses": {
          "201": { "description": "Created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Category" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/menu-api-v1-write/categories/{id}": {
      "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" }, "description": "Internal UUID or `external_id` (POS-supplied)." }],
      "patch": {
        "tags": ["Categories"], "summary": "Update category",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CategoryInput" } } } },
        "responses": { "200": { "description": "Updated", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Category" } } } }, "404": { "$ref": "#/components/responses/NotFound" } }
      },
      "delete": {
        "tags": ["Categories"], "summary": "Soft-delete category",
        "responses": { "204": { "description": "Deleted" }, "404": { "$ref": "#/components/responses/NotFound" } }
      }
    },
    "/menu-api-v1-write/items": {
      "post": {
        "tags": ["Items"],
        "summary": "Create item (idempotent on external_id)",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ItemInput" } } } },
        "responses": {
          "201": { "description": "Created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Item" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/menu-api-v1-write/items/{id}": {
      "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
      "patch": {
        "tags": ["Items"], "summary": "Update item",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ItemInput" } } } },
        "responses": { "200": { "description": "Updated", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Item" } } } } }
      },
      "delete": {
        "tags": ["Items"], "summary": "Delete item",
        "responses": { "204": { "description": "Deleted" } }
      }
    },
    "/menu-api-v1-write/items/{id}/availability": {
      "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
      "patch": {
        "tags": ["Items"], "summary": "Quick 86 / un-86",
        "description": "Requires `availability:write` scope only.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["is_available"], "properties": { "is_available": { "type": "boolean" } } } } } },
        "responses": { "200": { "description": "OK" }, "403": { "$ref": "#/components/responses/Forbidden" } }
      }
    },
    "/menu-api-v1-write/sync": {
      "post": {
        "tags": ["Sync"],
        "summary": "Bulk upsert the entire menu tree",
        "description": "Diffs the supplied tree against the current state using `external_id` as the anchor, then applies inserts/updates/soft-deletes in one operation. Returns a per-row result array.",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": {
            "type": "object",
            "properties": {
              "categories": { "type": "array", "items": { "$ref": "#/components/schemas/CategoryInput" } },
              "items":      { "type": "array", "items": { "$ref": "#/components/schemas/ItemInput" } },
              "mode": { "type": "string", "enum": ["merge", "replace"], "default": "merge" }
            }
          } } }
        },
        "responses": {
          "200": { "description": "Sync complete", "content": { "application/json": { "schema": { "type": "object", "properties": {
            "results": { "type": "array", "items": { "type": "object", "properties": {
              "external_id": { "type": "string" },
              "kind": { "type": "string", "enum": ["category","item"] },
              "action": { "type": "string", "enum": ["created","updated","deleted","unchanged","error"] },
              "internal_id": { "type": "string", "format": "uuid" },
              "error": { "type": "string" }
            } } }
          } } } } }
        }
      }
    },
    "/menu-api-v1-orders": {
      "post": {
        "tags": ["Orders"],
        "summary": "Inject an external order",
        "description": "Creates a paid/accepted order originating from a third-party channel (Uber Eats, DoorDash, Bolt Food, etc.). Requires `orders:write` scope. De-duplicates on `(source, external_id)`; pass `Idempotency-Key` for safe retries (24h replay window). All money fields are integer minor units; `subtotal_minor`/`total_minor` are computed from `items[]` if omitted.",
        "parameters": [
          { "name": "Idempotency-Key", "in": "header", "schema": { "type": "string" }, "description": "Optional. 24h replay window." }
        ],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OrderInjectInput" } } } },
        "responses": {
          "201": { "description": "Created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OrderInjectResult" } } } },
          "200": { "description": "Deduped — order already exists for `(source, external_id)`", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/OrderInjectResult" } } } },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" }
        }
      }
    },
    "/menu-api-v1-orders/{id}/status": {
      "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" }, "description": "Internal order UUID or the channel's `external_id`." }],
      "patch": {
        "tags": ["Orders"],
        "summary": "Update order lifecycle status",
        "description": "Pushes lifecycle updates back to the order. Requires `orders:write` scope.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["status"], "properties": { "status": { "type": "string", "enum": ["paid","accepted","preparing","ready","completed","cancelled"] } } } } } },
        "responses": {
          "200": { "description": "Updated" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/menu-api-v1-webhooks": {
      "get": {
        "tags": ["Webhooks"], "summary": "List webhook subscriptions",
        "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "type": "object", "properties": { "webhooks": { "type": "array", "items": { "$ref": "#/components/schemas/Webhook" } } } } } } } }
      },
      "post": {
        "tags": ["Webhooks"], "summary": "Register a webhook",
        "requestBody": { "required": true, "content": { "application/json": { "schema": {
          "type": "object", "required": ["name","url"],
          "properties": {
            "name":   { "type": "string", "example": "POS Sync – Production" },
            "url":    { "type": "string", "format": "uri", "example": "https://my-pos.example.com/webhooks/directdine" },
            "events": { "type": "array", "items": { "$ref": "#/components/schemas/EventType" } }
          }
        } } } },
        "responses": { "201": { "description": "Created. The signing `secret` is returned **once** — store it.", "content": { "application/json": { "schema": { "type": "object", "properties": { "webhook": { "$ref": "#/components/schemas/Webhook" }, "secret": { "type": "string", "example": "whsec_…" } } } } } } }
      }
    },
    "/menu-api-v1-webhooks/{id}": {
      "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
      "patch": { "tags": ["Webhooks"], "summary": "Update webhook", "responses": { "200": { "description": "Updated" } } },
      "delete": { "tags": ["Webhooks"], "summary": "Delete webhook", "responses": { "204": { "description": "Deleted" } } }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "DirectDine API key" },
      "ApiKeyAuth": { "type": "apiKey", "in": "header", "name": "X-API-Key" }
    },
    "schemas": {
      "Menu": {
        "type": "object",
        "properties": {
          "restaurant_id": { "type": "string", "format": "uuid" },
          "currency_code": { "type": "string", "example": "ZAR" },
          "currency_symbol": { "type": "string", "example": "R" },
          "generated_at": { "type": "string", "format": "date-time" },
          "categories": { "type": "array", "items": { "$ref": "#/components/schemas/Category" } },
          "items":      { "type": "array", "items": { "$ref": "#/components/schemas/Item" } }
        }
      },
      "Category": {
        "type": "object",
        "properties": {
          "id":           { "type": "string", "format": "uuid" },
          "external_id":  { "type": "string", "nullable": true },
          "name":         { "type": "string" },
          "sort_order":   { "type": "integer" },
          "available_from": { "type": "string", "nullable": true, "example": "11:00" },
          "available_until":{ "type": "string", "nullable": true, "example": "15:00" },
          "updated_at":   { "type": "string", "format": "date-time" }
        }
      },
      "CategoryInput": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "external_id": { "type": "string" },
          "name":        { "type": "string" },
          "sort_order":  { "type": "integer" },
          "available_from": { "type": "string" },
          "available_until":{ "type": "string" }
        }
      },
      "Item": {
        "type": "object",
        "properties": {
          "id":           { "type": "string", "format": "uuid" },
          "external_id":  { "type": "string", "nullable": true },
          "category_id":  { "type": "string", "format": "uuid" },
          "name":         { "type": "string" },
          "description":  { "type": "string", "nullable": true },
          "price_minor":  { "type": "integer", "description": "Price in minor units (e.g. cents).", "example": 9999 },
          "currency_code":{ "type": "string", "example": "ZAR" },
          "image_url":    { "type": "string", "format": "uri", "nullable": true },
          "is_available": { "type": "boolean" },
          "tax_rate_bps": { "type": "integer", "nullable": true, "description": "Basis points (15% = 1500). null = inherit restaurant default." },
          "has_variants": { "type": "boolean", "description": "Whether this item has selectable variants. Always present." },
          "has_addons":   { "type": "boolean", "description": "Whether this item has optional addons. Always present." },
          "variant_groups": { "type": "array", "description": "Only included when `?include=variants` is set on the request.", "items": { "$ref": "#/components/schemas/VariantGroup" } },
          "addon_groups":   { "type": "array", "description": "Only included when `?include=addons` is set on the request.", "items": { "$ref": "#/components/schemas/AddonGroup" } },
          "updated_at":   { "type": "string", "format": "date-time" }
        }
      },
      "ItemInput": {
        "type": "object",
        "required": ["name","price_minor","category_external_id"],
        "properties": { "addon_groups": { "type": "array", "items": { "$ref": "#/components/schemas/AddonGroupInput" }, "description": "When sent, the dish's whole set of add-on groups." }, "size_groups": { "type": "array", "items": { "$ref": "#/components/schemas/TillSizeGroup" }, "description": "When sent, the dish's whole set of sizes. Leave out to keep sizes made in DirectDine." },
          "external_id":  { "type": "string" },
          "category_external_id": { "type": "string" },
          "name":         { "type": "string" },
          "description":  { "type": "string" },
          "price_minor":  { "type": "integer" },
          "image_url":    { "type": "string", "format": "uri" },
          "is_available": { "type": "boolean", "default": true },
          "tax_rate_bps": { "type": "integer" }
        }
      },
      "VariantGroup": {
        "type": "object",
        "description": "A size group (e.g. Size, Crust): one choice per group. Written with `size_groups` on the write API, read back as `variant_groups`.",
        "properties": { "external_id": { "type": "string", "nullable": true, "description": "The till's own id, when the till sent it on the write API." },
          "id":            { "type": "string" },
          "name":          { "type": "string", "example": "Size" },
          "min_selection": { "type": "integer", "example": 1 },
          "max_selection": { "type": "integer", "example": 1 },
          "variants":      { "type": "array", "items": { "$ref": "#/components/schemas/Variant" } }
        }
      },
      "Variant": {
        "type": "object",
        "properties": { "external_id": { "type": "string", "nullable": true, "description": "The till's own id, when the till sent it on the write API." },
          "id":          { "type": "string" },
          "name":        { "type": "string", "example": "Large" },
          "price_minor": { "type": "integer", "description": "Replacement price for the item when this variant is selected (not additive)." },
          "is_default":  { "type": "boolean" },
          "sort_order":  { "type": "integer" }
        }
      },
      "AddonGroup": {
        "type": "object",
        "properties": { "external_id": { "type": "string", "nullable": true, "description": "The till's own id, when the till sent it on the write API." },
          "id":            { "type": "string" },
          "name":          { "type": "string", "example": "Extras" },
          "min_selection": { "type": "integer", "example": 0 },
          "max_selection": { "type": "integer", "example": 5 },
          "addons":        { "type": "array", "items": { "$ref": "#/components/schemas/Addon" } }
        }
      },
      "Addon": {
        "type": "object",
        "properties": { "external_id": { "type": "string", "nullable": true, "description": "The till's own id, when the till sent it on the write API." },
          "id":             { "type": "string" },
          "name":           { "type": "string", "example": "Extra Cheese" },
          "price_minor":    { "type": "integer", "description": "Default addon price; additive on top of the item." },
          "is_preselected": { "type": "boolean" },
          "sort_order":     { "type": "integer" },
          "variant_prices_minor": {
            "type": "object",
            "additionalProperties": { "type": "integer" },
            "description": "Optional per-variant price overrides. Map of `variant_id → price_minor`. Falls back to `price_minor` when the selected variant is not present."
          }
        }
      },
      "TillSize": {"type": "object", "required": ["name"], "properties": {"external_id": {"type": "string", "description": "The till's id for this size (Square/Clover variation id)."}, "name": {"type": "string", "example": "Large"}, "price_minor": {"type": "integer", "description": "The FULL price of the dish in this size (replaces the dish price). 0 means the dish price."}}},
      "TillSizeGroup": {"type": "object", "required": ["name", "sizes"], "description": "Sizes owned by the till. When `size_groups` is sent on an item it is the dish's whole set of sizes: groups and sizes not in it are removed. Only one size group per dish may carry prices (sizes' prices replace the dish price and add up across groups). A pick-one choice that costs extra on top (\"+R20 calzone base\") is an add-on group with min_selection 1 and max_selection 1 instead.", "properties": {"external_id": {"type": "string"}, "name": {"type": "string", "example": "Size"}, "required": {"type": "boolean", "default": true, "description": "Must be picked before the dish can be ordered."}, "display_order": {"type": "integer"}, "sizes": {"type": "array", "items": {"$ref": "#/components/schemas/TillSize"}}}},
      "AddonOptionInput": {"type": "object", "required": ["name"], "properties": {"external_id": {"type": "string"}, "name": {"type": "string"}, "price_minor": {"type": "integer", "description": "Added on top of the dish price."}, "is_available": {"type": "boolean"}}},
      "AddonGroupInput": {"type": "object", "required": ["name"], "description": "An add-on group. min_selection 1 and max_selection 1 makes it a required pick-one (e.g. Meat Temp): the diner must choose, and checkout refuses an order without it.", "properties": {"external_id": {"type": "string"}, "name": {"type": "string"}, "min_selection": {"type": "integer", "default": 0}, "max_selection": {"type": "integer", "nullable": true}, "display_order": {"type": "integer"}, "addons": {"type": "array", "items": {"$ref": "#/components/schemas/AddonOptionInput"}}}},
      "TillIds": {"type": "object", "description": "On every order line sent to webhooks (`till`): the till's own ids for the dish, each size chosen and each add-on; null where the till never sent one, names always present.", "properties": {"item_external_id": {"type": "string", "nullable": true}, "sizes": {"type": "array", "items": {"type": "object", "properties": {"id": {"type": "string", "nullable": true}, "name": {"type": "string"}, "group": {"type": "string", "nullable": true}, "external_id": {"type": "string", "nullable": true}}}}, "addons": {"type": "array", "items": {"type": "object", "properties": {"id": {"type": "string", "nullable": true}, "name": {"type": "string"}, "quantity": {"type": "integer"}, "external_id": {"type": "string", "nullable": true}}}}}},
      "Me": {"type": "object", "description": "Who a key belongs to: the one-click connect handshake for POS hubs.", "properties": {"restaurant": {"type": "object", "properties": {"id": {"type": "string", "format": "uuid"}, "name": {"type": "string"}, "slug": {"type": "string"}, "currency_code": {"type": "string"}}}, "location": {"type": "object", "nullable": true, "description": "The branch a branch key works for; null for a restaurant key.", "properties": {"id": {"type": "string", "format": "uuid"}, "name": {"type": "string"}}}, "locations": {"type": "array", "items": {"type": "object", "properties": {"id": {"type": "string", "format": "uuid"}, "name": {"type": "string"}, "is_active": {"type": "boolean"}}}}, "key": {"type": "object", "properties": {"id": {"type": "string"}, "name": {"type": "string"}, "prefix": {"type": "string"}, "scopes": {"type": "array", "items": {"type": "string"}}, "is_test": {"type": "boolean"}, "payload_profile": {"type": "string"}, "rate_limit_per_minute": {"type": "integer"}, "expires_at": {"type": "string", "format": "date-time", "nullable": true}}}, "webhooks": {"type": "array", "items": {"type": "object", "properties": {"id": {"type": "string"}, "name": {"type": "string"}, "events": {"type": "array", "items": {"type": "string"}}, "enabled": {"type": "boolean"}, "location_id": {"type": "string", "nullable": true}, "healthy": {"type": "boolean"}, "last_success_at": {"type": "string", "nullable": true}, "last_failure_at": {"type": "string", "nullable": true}}}}}},
      "Webhook": {
        "type": "object",
        "properties": {
          "id":      { "type": "string", "format": "uuid" },
          "name":    { "type": "string" },
          "url":     { "type": "string", "format": "uri" },
          "events":  { "type": "array", "items": { "$ref": "#/components/schemas/EventType" } },
          "enabled": { "type": "boolean" },
          "location_id": { "type": "string", "format": "uuid", "description": "Branch this webhook fires for. Inherited from the API key — cannot be set to another location." },
          "consecutive_failures": { "type": "integer" },
          "last_success_at": { "type": "string", "format": "date-time", "nullable": true },
          "last_failure_at": { "type": "string", "format": "date-time", "nullable": true }
        }
      },
      "EventType": {
        "type": "string",
        "enum": [
          "menu.item.created","menu.item.updated","menu.item.deleted",
          "menu.item.availability_changed",
          "menu.category.created","menu.category.updated","menu.category.deleted"
        ]
      },
      "WebhookEvent": {
        "type": "object",
        "description": "Payload POSTed to your webhook URL. Verify the `X-DirectDine-Signature` header before trusting. `location_id` is the branch the change applies to, or null for restaurant-wide menu items. Order events (order.*) carry `data.items[]`, read when the event is sent, each with `till` (TillIds).",
        "properties": {
          "id":            { "type": "string", "format": "uuid" },
          "type":          { "$ref": "#/components/schemas/EventType" },
          "created_at":    { "type": "string", "format": "date-time" },
          "restaurant_id": { "type": "string", "format": "uuid" },
          "location_id":   { "type": "string", "format": "uuid", "nullable": true },
          "data":          { "type": "object" }
        }
      },
      "OrderInjectInput": {
        "type": "object",
        "required": ["source","external_id","order_type","customer","items"],
        "properties": {
          "source":      { "type": "string", "example": "uber_eats", "description": "Channel identifier, e.g. `uber_eats`, `doordash`, `bolt_food`." },
          "external_id": { "type": "string", "description": "Channel's order ID. Used for de-duplication with `source`." },
          "order_type":  { "type": "string", "enum": ["delivery","pickup"] },
          "status":      { "type": "string", "enum": ["paid","accepted","preparing","ready","cancelled"], "default": "paid" },
          "customer": {
            "type": "object",
            "required": ["name","phone"],
            "properties": {
              "name":  { "type": "string" },
              "phone": { "type": "string" },
              "email": { "type": "string", "format": "email" }
            }
          },
          "delivery_address": { "type": "string", "description": "Required when `order_type` is `delivery`." },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["name","quantity","price_minor"],
              "properties": {
                "external_id": { "type": "string", "description": "Optional menu item external_id for matching." },
                "name":        { "type": "string" },
                "quantity":    { "type": "integer", "minimum": 1 },
                "price_minor": { "type": "integer", "description": "Per-unit price in minor units." },
                "notes":       { "type": "string" }
              }
            }
          },
          "subtotal_minor":  { "type": "integer", "description": "Optional. Computed from items if omitted." },
          "delivery_fee_minor": { "type": "integer", "default": 0 },
          "tax_minor":       { "type": "integer", "default": 0 },
          "tip_minor":       { "type": "integer", "default": 0 },
          "total_minor":     { "type": "integer", "description": "Optional. Computed from items + fees if omitted." },
          "notes":           { "type": "string" },
          "scheduled_for":   { "type": "string", "format": "date-time", "description": "Optional ISO-8601 pickup/delivery time." }
        }
      },
      "OrderInjectResult": {
        "type": "object",
        "properties": {
          "order_id":    { "type": "string", "format": "uuid" },
          "external_id": { "type": "string" },
          "source":      { "type": "string" },
          "status":      { "type": "string" },
          "deduped":     { "type": "boolean", "description": "`true` when this `(source, external_id)` was already ingested." }
        }
      },
      "Error": {
        "type": "object",
        "properties": { "error": { "type": "string" } }
      }
    },
    "responses": {
      "BadRequest":    { "description": "Validation error",    "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Unauthorized":  { "description": "Missing/invalid key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Forbidden":     { "description": "Missing scope",       "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "NotFound":      { "description": "Not found",            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "RateLimited":   { "description": "Rate limit exceeded",  "headers": { "Retry-After": { "schema": { "type": "integer" } } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    }
  }
}
