{
  "openapi": "3.1.0",
  "info": {
    "title": "LongRiver LAB Lead API",
    "version": "1.0.0",
    "description": "Public lead submission endpoint for longriver-lab.com. Delivers inquiry notifications to the LongRiver LAB team via Telegram and optionally WhatsApp. Implemented as a Cloudflare Worker (`lr-labs-telegram-leads`).",
    "contact": {
      "name": "LongRiver LAB",
      "url": "https://longriver-lab.com/#contact"
    }
  },
  "servers": [
    {
      "url": "https://longriver-lab.com",
      "description": "Production"
    },
    {
      "url": "https://www.longriver-lab.com",
      "description": "Production (www)"
    }
  ],
  "paths": {
    "/api/lead": {
      "post": {
        "operationId": "submitLead",
        "summary": "Submit a contact or application lead",
        "description": "Accepts a JSON lead from the website contact form or compatible agents. Requires privacy consent. Name must be at least 2 characters. Phone is optional but validated when provided (9–15 digits).",
        "tags": ["Leads"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/LeadRequest" },
              "examples": {
                "minimal": {
                  "summary": "Required fields only",
                  "value": {
                    "name": "Ada Lovelace",
                    "phone": "",
                    "message": "We need licensing support for a EU fintech MVP.",
                    "source": "agent",
                    "consentPrivacy": true,
                    "consentMarketing": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lead accepted and notification delivered",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/LeadSuccess" }
              }
            }
          },
          "400": {
            "description": "Validation error (invalid JSON, name, phone, or missing privacy consent)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/LeadError" },
                "examples": {
                  "missingConsent": {
                    "value": { "ok": false, "error": "Missing privacy consent" }
                  }
                }
              }
            }
          },
          "405": {
            "description": "Method not allowed (only POST is supported)"
          },
          "502": {
            "description": "Notification delivery failed",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/LeadError" }
              }
            }
          }
        }
      },
      "options": {
        "operationId": "leadCorsPreflight",
        "summary": "CORS preflight",
        "responses": {
          "204": {
            "description": "CORS preflight OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "LeadRequest": {
        "type": "object",
        "required": ["name", "consentPrivacy"],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2,
            "description": "Contact full name"
          },
          "phone": {
            "type": "string",
            "description": "Optional phone number (9–15 digits when provided)"
          },
          "message": {
            "type": "string",
            "description": "Free-text inquiry or project summary"
          },
          "source": {
            "type": "string",
            "default": "labs-web",
            "description": "Lead source identifier (e.g. labs-web, agent)"
          },
          "consentPrivacy": {
            "type": "boolean",
            "description": "Must be true — consent to personal data processing"
          },
          "consentMarketing": {
            "type": "boolean",
            "default": false,
            "description": "Optional consent to marketing communications"
          },
          "submittedAt": {
            "type": "string",
            "format": "date-time",
            "description": "Client-side submission timestamp (optional, informational)"
          }
        }
      },
      "LeadSuccess": {
        "type": "object",
        "required": ["ok"],
        "properties": {
          "ok": { "type": "boolean", "enum": [true] },
          "channels": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "channel": { "type": "string" },
                "ok": { "type": "boolean" },
                "skipped": { "type": "boolean" }
              }
            }
          }
        }
      },
      "LeadError": {
        "type": "object",
        "required": ["ok", "error"],
        "properties": {
          "ok": { "type": "boolean", "enum": [false] },
          "error": { "type": "string" }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Leads",
      "description": "Contact and application submissions"
    }
  ]
}
