{
  "openapi": "3.0.3",
  "info": {
    "title": "Payby Lead Capture",
    "description": "Internal webhook behind the 'Agendar demonstração' form on payby.com.br. It forwards a restaurant's demo-request to Payby's sales team. This is not a general-purpose developer API — there is no SLA and no public authentication path. It exists to be transparent about what this endpoint does, not to invite third-party integration.\n\n**Versioning policy**: the path is versioned (`/api/v1/...`). A breaking change ships under a new version path (`/api/v2/...`); the previous version keeps working for at least 90 days after that, and responses from a version being phased out will carry a `Sunset` header naming the date it stops working. `/api/submit-lead` (no version) is a legacy alias of `/api/v1/submit-lead` kept for backward compatibility — new integrations should use the versioned path.",
    "version": "1.0.0",
    "contact": {
      "url": "https://payby.com.br/contact/"
    }
  },
  "servers": [
    {
      "url": "https://payby.com.br"
    }
  ],
  "security": [],
  "paths": {
    "/api/v1/submit-lead": {
      "post": {
        "operationId": "submitLead",
        "summary": "Submit a restaurant demo-request lead",
        "description": "Used exclusively by the lead-capture form on the Payby homepage. Rate-limited per IP (5 requests/minute) — every response carries RateLimit-* headers, and a 429 additionally carries Retry-After.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LeadSubmission"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lead accepted and forwarded",
            "headers": {
              "RateLimit-Limit": {"$ref": "#/components/headers/RateLimit-Limit"},
              "RateLimit-Remaining": {"$ref": "#/components/headers/RateLimit-Remaining"},
              "RateLimit-Reset": {"$ref": "#/components/headers/RateLimit-Reset"}
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {"type": "boolean", "enum": [true]}
                  },
                  "required": ["success"]
                }
              }
            }
          },
          "400": {
            "description": "Missing a required field",
            "headers": {
              "RateLimit-Limit": {"$ref": "#/components/headers/RateLimit-Limit"},
              "RateLimit-Remaining": {"$ref": "#/components/headers/RateLimit-Remaining"},
              "RateLimit-Reset": {"$ref": "#/components/headers/RateLimit-Reset"}
            },
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/ErrorResponse"}
              }
            }
          },
          "405": {
            "description": "Wrong HTTP method — only POST is accepted",
            "headers": {
              "Allow": {
                "schema": {"type": "string", "example": "POST, OPTIONS"}
              }
            },
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/ErrorResponse"}
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (5 requests/minute per IP)",
            "headers": {
              "RateLimit-Limit": {"$ref": "#/components/headers/RateLimit-Limit"},
              "RateLimit-Remaining": {"$ref": "#/components/headers/RateLimit-Remaining"},
              "RateLimit-Reset": {"$ref": "#/components/headers/RateLimit-Reset"},
              "Retry-After": {"$ref": "#/components/headers/Retry-After"}
            },
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/ErrorResponse"}
              }
            }
          },
          "500": {
            "description": "Server-side failure (misconfiguration or the downstream notification failed)",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/ErrorResponse"}
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "LeadSubmission": {
        "type": "object",
        "required": ["restaurante", "nome", "telefone", "email"],
        "properties": {
          "restaurante": {"type": "string", "description": "Restaurant name"},
          "nome": {"type": "string", "description": "Contact person's full name"},
          "telefone": {"type": "string", "description": "WhatsApp number"},
          "email": {"type": "string", "format": "email"},
          "cidade": {"type": "string", "description": "City, optional"},
          "mesas": {"type": "string", "description": "Number of tables, optional"},
          "pdv": {"type": "string", "description": "Current POS system, optional"},
          "mensagem": {"type": "string", "description": "Free-text message, optional"},
          "origem": {"type": "string", "description": "Which page/CTA the lead came from, set automatically by the site"}
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {"type": "string", "example": "missing_required_fields"},
              "message": {"type": "string"},
              "hint": {"type": "string", "description": "How to resolve the error, when applicable"}
            }
          }
        }
      }
    },
    "headers": {
      "RateLimit-Limit": {
        "description": "Requests allowed per window (draft-ietf-httpapi-ratelimit-headers)",
        "schema": {"type": "integer", "example": 5}
      },
      "RateLimit-Remaining": {
        "description": "Requests left in the current window",
        "schema": {"type": "integer", "example": 4}
      },
      "RateLimit-Reset": {
        "description": "Seconds until the window resets",
        "schema": {"type": "integer", "example": 42}
      },
      "Retry-After": {
        "description": "Seconds to wait before retrying (RFC 7231)",
        "schema": {"type": "integer", "example": 42}
      }
    }
  }
}
