{
  "openapi": "3.0.3",
  "info": {
    "title": "Trout Lumber API",
    "version": "1.0.0",
    "description": "Machine-readable inventory and slab reservation for Trout Lumber (Sharon, VT). Reservations are requests to hold a slab; staff follow up by email. Do not invent phone, hours, or policies not stated on the site."
  },
  "servers": [
    {
      "url": "https://troutlumber.com"
    }
  ],
  "paths": {
    "/slabs.json": {
      "get": {
        "summary": "List inventory",
        "operationId": "listSlabs",
        "responses": {
          "200": {
            "description": "Inventory feed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/slabs.csv": {
      "get": {
        "summary": "List inventory as CSV",
        "operationId": "listSlabsCsv",
        "responses": {
          "200": {
            "description": "CSV inventory",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/api/reserve": {
      "post": {
        "summary": "Request to reserve a slab",
        "operationId": "reserveSlab",
        "description": "Creates a reservation request (KV backup + Google Sheet via Apps Script). Returns {ok:true} on success. Origin header, if present, must be https://troutlumber.com (or *.workers.dev). Omit Origin for non-browser clients. Honeypot field website must be empty.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReservationRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Origin not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Could not persist request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ReservationRequest": {
        "type": "object",
        "required": [
          "slabId",
          "name",
          "email",
          "delivery"
        ],
        "properties": {
          "slabId": {
            "type": "string",
            "pattern": "^[A-Za-z0-9-]{1,40}$",
            "example": "TL-1001"
          },
          "slabName": {
            "type": "string",
            "maxLength": 200,
            "description": "Species or display name"
          },
          "price": {
            "type": "string",
            "maxLength": 200,
            "description": "Display price string"
          },
          "name": {
            "type": "string",
            "maxLength": 200
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 200
          },
          "phone": {
            "type": "string",
            "maxLength": 200
          },
          "delivery": {
            "type": "string",
            "enum": [
              "Pickup",
              "Shipping"
            ]
          },
          "comments": {
            "type": "string",
            "maxLength": 2000
          },
          "pageUrl": {
            "type": "string",
            "maxLength": 200
          },
          "address": {
            "type": "string",
            "maxLength": 500,
            "description": "Required when delivery=Shipping unless street/city/state/zip provided"
          },
          "street": {
            "type": "string",
            "maxLength": 200
          },
          "apt": {
            "type": "string",
            "maxLength": 200
          },
          "city": {
            "type": "string",
            "maxLength": 200
          },
          "state": {
            "type": "string",
            "maxLength": 200,
            "description": "US state code preferred"
          },
          "zip": {
            "type": "string",
            "maxLength": 200
          },
          "website": {
            "type": "string",
            "description": "Honeypot; leave empty. Non-empty yields fake ok:true."
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "enum": [
              false
            ]
          },
          "error": {
            "type": "string"
          },
          "field": {
            "type": "string"
          }
        }
      }
    }
  }
}