{
  "openapi": "3.1.0",
  "info": {
    "title": "JILONG.ONE Public Lead API",
    "version": "1.0.0",
    "description": "Public intake API for AI agents and customers to route accounting, tax, property, immigration, energy, customer-service, and document-review requests into JILONG ERP human-reviewed queues."
  },
  "servers": [
    {
      "url": "https://jilong.one"
    }
  ],
  "paths": {
    "/api/public-lead": {
      "get": {
        "operationId": "describePublicLeadIntake",
        "summary": "Describe the public lead intake contract",
        "tags": ["PublicLead"],
        "responses": {
          "200": {
            "description": "Machine-readable lead intake capabilities",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicLeadCapabilities"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createPublicLead",
        "summary": "Route a public consultation into the JILONG ERP review queue",
        "description": "Creates a human-reviewed ERP lead. It does not submit official filings, create final accounting entries, transfer energy supply, sign contracts, or send customer-facing replies automatically.",
        "tags": ["PublicLead"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PublicLeadRequest"
              },
              "examples": {
                "accountingTax": {
                  "summary": "Accounting and tax lead",
                  "value": {
                    "service": "accounting_tax",
                    "department": "gestoria",
                    "message": "Customer wants invoice upload, bookkeeping, and VAT filing preparation.",
                    "summary": "New accounting and tax consultation from an AI agent.",
                    "contactName": "Example Company",
                    "contactMethod": "WhatsApp",
                    "contactValue": "+34 example",
                    "source": "agent-cli"
                  }
                },
                "property": {
                  "summary": "Property operations lead",
                  "value": {
                    "service": "property",
                    "department": "property",
                    "message": "Customer wants help with rent settlement, utilities, IBI, and community fees.",
                    "summary": "Property management consultation for ERP follow-up.",
                    "contactName": "Property Owner",
                    "contactMethod": "WeChat",
                    "contactValue": "wechat-id",
                    "source": "agent-cli"
                  }
                },
                "energy": {
                  "summary": "Energy contract lead",
                  "value": {
                    "service": "energy",
                    "department": "energy",
                    "message": "Customer wants electricity and gas contract review and supplier-transfer support.",
                    "summary": "Energy department lead for staff confirmation.",
                    "contactName": "Energy Customer",
                    "contactMethod": "WhatsApp",
                    "contactValue": "+34 example",
                    "source": "agent-cli"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lead queued for ERP review",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicLeadResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "500": {
            "description": "Lead could not be stored"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "PublicLeadCapabilities": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "schema": { "type": "string" },
          "acceptedServices": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ServiceCategory" }
          },
          "humanReviewRequired": { "type": "boolean" }
        }
      },
      "PublicLeadRequest": {
        "type": "object",
        "required": ["message", "summary"],
        "properties": {
          "service": {
            "$ref": "#/components/schemas/ServiceCategory"
          },
          "department": {
            "type": "string",
            "description": "Suggested JILONG department such as gestoria, property, immigration, energy, or customer_service."
          },
          "message": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000,
            "description": "Customer request or agent-routed consultation."
          },
          "summary": {
            "type": "string",
            "maxLength": 2000,
            "description": "Short operational summary for staff review."
          },
          "contactName": {
            "type": "string",
            "maxLength": 200
          },
          "contactMethod": {
            "type": "string",
            "description": "Preferred contact channel, for example WhatsApp, WeChat, email, or phone."
          },
          "contactValue": {
            "type": "string",
            "maxLength": 300
          },
          "source": {
            "type": "string",
            "description": "Source website, agent, CLI, or campaign name."
          }
        }
      },
      "PublicLeadResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "leadId": { "type": "string" },
          "status": { "type": "string" },
          "humanReviewRequired": { "type": "boolean" },
          "message": { "type": "string" }
        }
      },
      "ServiceCategory": {
        "type": "string",
        "enum": [
          "accounting_tax",
          "property",
          "immigration",
          "energy",
          "customer_service"
        ]
      }
    }
  }
}
