{
  "openapi": "3.1.0",
  "info": {
    "title": "Scalogy Public API",
    "version": "1.0.0",
    "summary": "Lead intake, the site chat assistant, and a health check for scalogy.com.",
    "description": "The public endpoints that scalogy.com exposes to agents and integrations. Submit a lead with POST /api/contact, talk to the site assistant with POST /api/chat, and check availability with GET /api/health. No authentication is required; requests are rate limited at the edge.",
    "contact": { "name": "Scalogy", "url": "https://scalogy.com/contact", "email": "hello@scalogy.com" },
    "termsOfService": "https://scalogy.com/terms"
  },
  "externalDocs": { "description": "Human-readable API documentation", "url": "https://scalogy.com/api-docs" },
  "servers": [{ "url": "https://scalogy.com" }],
  "tags": [
    { "name": "Leads", "description": "Get in touch with Scalogy." },
    { "name": "Assistant", "description": "The chat assistant that answers questions about Scalogy's services." },
    { "name": "Status", "description": "Service availability." }
  ],
  "paths": {
    "/api/contact": {
      "post": {
        "tags": ["Leads"],
        "operationId": "submitContact",
        "summary": "Submit a contact request",
        "description": "Creates a lead. The Scalogy team replies by email, usually within one business day. Only name and email are required.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ContactRequest" },
              "example": {
                "name": "Jordan Rivera",
                "email": "jordan@example.com",
                "businessName": "Rivera Plumbing",
                "industry": "Plumbing",
                "timeWaster": "Missed calls after hours and slow follow-up on quotes",
                "source": "api"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lead accepted.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LeadAccepted" }, "example": { "ok": true, "id": "3f1c8e6a-2b7d-4c1e-9d3f-5a6b7c8d9e0f" } } }
          },
          "400": { "description": "Name or email missing.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" }, "example": { "error": "Name and email are required" } } } },
          "500": { "description": "The lead could not be saved.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/chat": {
      "post": {
        "tags": ["Assistant"],
        "operationId": "chat",
        "summary": "Ask the Scalogy assistant a question",
        "description": "Sends a conversation to the site assistant and returns its next reply. Send an empty messages array to receive the greeting. The assistant answers questions about Scalogy's AI agents, pricing and process, and may offer to collect contact details.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ChatRequest" },
              "example": { "messages": [{ "role": "user", "content": "What does the lead response agent do?" }] }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The assistant's reply.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChatResponse" }, "example": { "reply": "It answers every new inquiry within a minute, by text or email, and books the call." } } }
          },
          "500": { "description": "The assistant is not configured.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "502": { "description": "The upstream model returned an error.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/health": {
      "get": {
        "tags": ["Status"],
        "operationId": "health",
        "summary": "Service health",
        "description": "Returns 200 when the site and its API are serving requests.",
        "responses": {
          "200": {
            "description": "Healthy.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Health" }, "example": { "status": "ok", "service": "scalogy.com", "time": "2026-09-22T17:00:00.000Z" } } }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ContactRequest": {
        "type": "object",
        "required": ["name", "email"],
        "properties": {
          "name": { "type": "string", "description": "Full name." },
          "email": { "type": "string", "format": "email", "description": "Reply-to address." },
          "businessName": { "type": "string", "description": "Company or practice name." },
          "industry": { "type": "string", "description": "Trade or sector, for example Plumbing, Law firm, Dental." },
          "timeWaster": { "type": "string", "description": "The task or problem to automate, in the sender's words." },
          "source": { "type": "string", "description": "Where the request came from; recorded as contact_form_<source>. Defaults to direct.", "default": "direct" },
          "utm_source": { "type": "string" },
          "utm_medium": { "type": "string" },
          "utm_campaign": { "type": "string" }
        }
      },
      "LeadAccepted": {
        "type": "object",
        "required": ["ok"],
        "properties": {
          "ok": { "type": "boolean", "const": true },
          "id": { "type": "string", "format": "uuid", "description": "Identifier of the stored lead." }
        }
      },
      "ChatMessage": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": { "type": "string", "enum": ["user", "assistant"] },
          "content": { "type": "string" }
        }
      },
      "ChatRequest": {
        "type": "object",
        "required": ["messages"],
        "properties": {
          "messages": { "type": "array", "items": { "$ref": "#/components/schemas/ChatMessage" }, "description": "The conversation so far, oldest first. Empty for the opening greeting." }
        }
      },
      "ChatResponse": {
        "type": "object",
        "required": ["reply"],
        "properties": {
          "reply": { "type": "string", "description": "The assistant's next message." }
        }
      },
      "Health": {
        "type": "object",
        "required": ["status"],
        "properties": {
          "status": { "type": "string", "enum": ["ok"] },
          "service": { "type": "string" },
          "time": { "type": "string", "format": "date-time" }
        }
      },
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": { "error": { "type": "string" } }
      }
    }
  }
}
