{
  "openapi": "3.1.0",
  "info": {
    "title": "Filtracuriosos Webhook API",
    "description": "Webhook-based API for receiving lead events from Filtracuriosos quizzes. Configure your webhook URL in the quiz settings to receive lead data in real-time.",
    "version": "1.0.0",
    "contact": {
      "name": "Filtracuriosos Support",
      "url": "https://filtracuriosos.com/Contact"
    }
  },
  "servers": [
    {
      "url": "https://filtracuriosos.com",
      "description": "Production"
    }
  ],
  "paths": {
    "/functions/sendLeadWebhook": {
      "post": {
        "summary": "Receive Lead Webhook",
        "description": "Webhook endpoint that fires when a new lead completes a quiz. Configure your target URL in the quiz settings.",
        "operationId": "receiveLeadWebhook",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LeadWebhookPayload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook received successfully"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "LeadWebhookPayload": {
        "type": "object",
        "properties": {
          "event": {
            "type": "string",
            "enum": ["lead_created"],
            "description": "Event type"
          },
          "quiz_id": {
            "type": "string",
            "description": "ID of the quiz"
          },
          "quiz_title": {
            "type": "string",
            "description": "Title of the quiz"
          },
          "lead": {
            "$ref": "#/components/schemas/Lead"
          }
        }
      },
      "Lead": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "phone": { "type": "string" },
          "status": {
            "type": "string",
            "enum": ["qualified", "disqualified"]
          },
          "responses": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "question": { "type": "string" },
                "answer": { "type": "string" }
              }
            }
          },
          "ai_close_score": {
            "type": "number",
            "description": "0-100 probability to close"
          },
          "ai_tier": {
            "type": "string",
            "enum": ["alto", "medio", "bajo"]
          },
          "appointment_date": { "type": "string", "format": "date" },
          "appointment_time": { "type": "string" },
          "utm_source": { "type": "string" },
          "utm_medium": { "type": "string" },
          "utm_campaign": { "type": "string" },
          "created_date": { "type": "string", "format": "date-time" }
        }
      }
    }
  }
}
