{
  "openapi": "3.1.0",
  "info": {"title": "Wazi Tools Automation API", "version": "1.0.0", "description": "Private pilot for workspace-scoped lead automation. Keys expire after 90 days and can be revoked in Wazi."},
  "servers": [{"url": "https://api.wazi.tools/v1"}],
  "components": {
    "securitySchemes": {"apiKey": {"type": "http", "scheme": "bearer", "description": "Wazi automation key issued from app.wazi.tools/integrations/automation"}},
    "schemas": {
      "Lead": {"type": "object", "required": ["id", "name", "company", "email", "phone", "stage", "source", "createdAt"], "properties": {"id": {"type":"string"}, "name": {"type":"string"}, "company": {"type":"string"}, "email": {"type":"string"}, "phone": {"type":"string"}, "stage": {"type":"string"}, "source": {"type":"string"}, "createdAt": {"type":"string"}}},
      "LeadEvent": {"type":"object", "required":["id","type","occurredAt","lead"], "properties":{"id":{"type":"string"},"type":{"const":"lead.created"},"occurredAt":{"type":"string","format":"date-time"},"lead":{"$ref":"#/components/schemas/Lead"}}}
    }
  },
  "paths": {
    "/health": {"get": {"summary":"Service health", "responses":{"200":{"description":"Healthy"}}}},
    "/leads": {
      "get": {"summary":"List accessible leads", "security":[{"apiKey":[]}], "parameters":[{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":25}},{"name":"cursor","in":"query","schema":{"type":"string"}}], "responses":{"200":{"description":"Leads and nextCursor"},"401":{"description":"Invalid key or current access"}}},
      "post": {"summary":"Create a lead", "security":[{"apiKey":[]}], "parameters":[{"name":"Idempotency-Key","in":"header","required":true,"schema":{"type":"string","minLength":8,"maxLength":128}}], "requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":false,"required":["name"],"properties":{"name":{"type":"string","maxLength":160},"company":{"type":"string","maxLength":160},"email":{"type":"string","maxLength":254},"phone":{"type":"string","maxLength":40},"source":{"type":"string","maxLength":80},"stage":{"type":"string","maxLength":80}}}}}}, "responses":{"201":{"description":"Created lead"},"200":{"description":"Idempotent replay"},"400":{"description":"Invalid input"},"409":{"description":"Idempotency key used with different input"}}}
    },
    "/lead-events": {"get": {"summary":"Poll lead-created events (newest first)", "security":[{"apiKey":[]}], "parameters":[{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":25}},{"name":"cursor","in":"query","schema":{"type":"string"}}], "responses":{"200":{"description":"Events and nextCursor"},"401":{"description":"Invalid key or current access"}}}}
  }
}
