{
  "openapi": "3.1.0",
  "info": {
    "title": "The Fisherman — Order & Reservation API",
    "version": "1.1.0",
    "description": "Public endpoints for programmatic food orders and table reservations. Table bookings return status pending_confirmation until the restaurant confirms. Prefer type reservation with date (YYYY-MM-DD) and time (HH:MM 24h) within opening hours 08:00–21:00 Asia/Ho_Chi_Minh."
  },
  "servers": [
    { "url": "https://the-fisherman-garden-vegan-restaurant-cafe.netlify.app" }
  ],
  "paths": {
    "/.netlify/functions/check-availability": {
      "get": {
        "operationId": "checkAvailability",
        "summary": "Check if a table slot is available",
        "description": "Returns available:true/false with reason and optional time suggestions. Use before submitOrder for reservations.",
        "x-openai-isConsequential": false,
        "parameters": [
          { "name": "date", "in": "query", "required": true, "schema": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" }, "description": "YYYY-MM-DD" },
          { "name": "time", "in": "query", "required": true, "schema": { "type": "string", "pattern": "^\\d{2}:\\d{2}$" }, "description": "HH:MM 24h" },
          { "name": "guests", "in": "query", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Availability result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "available": { "type": "boolean" },
                    "reason": { "type": "string", "nullable": true },
                    "suggestions": { "type": "array", "items": { "type": "string" } }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/.netlify/functions/submit-order": {
      "post": {
        "operationId": "submitOrder",
        "summary": "Submit an order or reservation",
        "description": "Stores the submission in the restaurant order log. For table bookings use type reservation with date, time, guests, customer_name, customer_contact. Returns pending_confirmation for reservations.",
        "x-openai-isConsequential": true,
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/Submission" },
              "examples": {
                "reservation": {
                  "summary": "Table reservation",
                  "value": {
                    "type": "reservation",
                    "customer_name": "Anna",
                    "customer_contact": "anna@example.com",
                    "date": "2026-07-10",
                    "time": "19:00",
                    "guests": "2",
                    "contact_method": "email",
                    "channel": "email",
                    "notes": "Window seat if possible",
                    "botcheck": ""
                  }
                },
                "order": {
                  "summary": "Food order",
                  "value": {
                    "type": "order",
                    "order_id": "FG-EXAMPLE",
                    "customer_name": "Anna",
                    "customer_contact": "+84901234567",
                    "contact_method": "phone",
                    "channel": "zalo",
                    "order_type": "Dine-in (table)",
                    "guests": "2",
                    "items": "2× Vegan Pho — 140,000 ₫",
                    "total": "140,000 ₫",
                    "botcheck": ""
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "status": { "type": "string", "enum": ["pending_confirmation", "received"] },
                    "id": { "type": "string" },
                    "message": { "type": "string" },
                    "reservation": {
                      "type": "object",
                      "properties": {
                        "name": { "type": "string" },
                        "date": { "type": "string" },
                        "time": { "type": "string" },
                        "guests": { "type": "string" }
                      }
                    },
                    "menu": {
                      "type": "object",
                      "properties": {
                        "url": { "type": "string" },
                        "suggestion": { "type": "string" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": { "description": "Invalid payload" },
          "409": { "description": "Slot unavailable" },
          "413": { "description": "Payload too large" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Submission": {
        "type": "object",
        "required": ["type", "customer_contact"],
        "properties": {
          "type": { "type": "string", "enum": ["order", "reservation"] },
          "order_id": { "type": "string", "maxLength": 64 },
          "customer_name": { "type": "string", "maxLength": 120 },
          "customer_contact": { "type": "string", "maxLength": 160 },
          "contact_method": { "type": "string", "enum": ["phone", "email"] },
          "channel": { "type": "string", "enum": ["zalo", "whatsapp", "email"] },
          "order_type": { "type": "string" },
          "guests": { "type": "string" },
          "date": { "type": "string" },
          "time": { "type": "string" },
          "items": { "type": "string" },
          "total": { "type": "string" },
          "notes": { "type": "string" },
          "message": { "type": "string" },
          "subject": { "type": "string" },
          "from_name": { "type": "string" },
          "botcheck": {
            "type": "string",
            "description": "Honeypot — must be empty."
          }
        }
      }
    }
  }
}
