{
  "openapi": "3.1.0",
  "info": {
    "title": "מתווכים — קליטת לידים",
    "version": "1.0.0",
    "description": "קליטת לידים ממקור חיצוני. מפתח נפרד לכל ערוץ, ושם הערוץ נשמר על כל ליד. תיעוד מלא עם דוגמאות ל-Make ול-n8n: https://0.0.0.0:3000/docs/api"
  },
  "servers": [
    {
      "url": "https://0.0.0.0:3000"
    }
  ],
  "paths": {
    "/api/v1/public/leads/{key}": {
      "post": {
        "summary": "קליטת ליד חדש",
        "description": "הלקוח מזוהה לפי הטלפון. פנייה נוספת מאותו מספר מצטרפת לליד הפתוח במקום לפתוח כפילות. שליחה כפולה של אותו טופס אינה יוצרת שני לידים.",
        "operationId": "ingestLead",
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "description": "מפתח המקור, מתוך ניהול משרד ← אינטגרציות ← מקורות לידים. שווה ערך לסיסמה — אין להטמיע בקוד של דף גלוי.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{20,64}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LeadInput"
              },
              "examples": {
                "minimal": {
                  "summary": "המינימום",
                  "value": {
                    "name": "ישראל ישראלי",
                    "phone": "050-1234567"
                  }
                },
                "full": {
                  "summary": "ליד מלא ממודעה של נכס",
                  "value": {
                    "name": "ישראל ישראלי",
                    "phone": "050-1234567",
                    "email": "israel@example.com",
                    "message": "מעוניין בדירת 4 חדרים",
                    "intent": "buy",
                    "pageUrl": "https://example.com/apartment-4-rooms"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "הפנייה נקלטה",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    }
                  },
                  "required": [
                    "ok"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "שדה חסר, שגוי, או שם שדה שאינו מוכר"
          },
          "404": {
            "description": "המפתח אינו מוכר"
          },
          "429": {
            "description": "יותר מ-10 פניות בדקה מאותה כתובת"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "LeadInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "phone"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 120,
            "description": "שם הלקוח"
          },
          "phone": {
            "type": "string",
            "maxLength": 25,
            "description": "מספר ישראלי בכל צורה מקובלת — \"050-1234567\", \"+972501234567\", \"0501234567\""
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 200,
            "description": "נשמר על הכרטיס ומאפשר זיהוי פניות עתידיות מאותה כתובת"
          },
          "message": {
            "type": "string",
            "maxLength": 2000,
            "description": "מה שהלקוח כתב — נכנס לציר הזמן של הליד"
          },
          "intent": {
            "type": "string",
            "enum": [
              "buy",
              "sell",
              "rent_in",
              "rent_out",
              "info"
            ],
            "description": "מה הלקוח רוצה. חסר ⇒ „לא ידוע”"
          },
          "propertyId": {
            "type": "string",
            "minLength": 26,
            "maxLength": 26,
            "description": "הנכס שהמודעה פרסמה. מזהה שאינו של המשרד — מתעלמים ממנו והליד עדיין נקלט"
          },
          "pageUrl": {
            "type": "string",
            "maxLength": 300,
            "description": "העמוד שממנו הגיעה הפנייה"
          },
          "website": {
            "type": "string",
            "maxLength": 200,
            "description": "מלכודת בוטים. יש להשאיר ריק — בקשה שממלאת אותו מוחזרת כהצלחה ואינה נקלטת"
          }
        }
      }
    }
  }
}