{
  "openapi": "3.1.0",
  "info": {
    "title": "FreeUpToHours Public API",
    "summary": "Public lead intake API for FreeUpToHours audit and automation inquiries.",
    "description": "Use this API only after explicit user consent to request a FreeUpToHours website audit, AI automation audit, or free homepage review.",
    "version": "1.0.0",
    "termsOfService": "https://freeuptohours.com/privacy",
    "contact": {
      "name": "FreeUpToHours",
      "url": "https://freeuptohours.com/audit"
    }
  },
  "servers": [
    {
      "url": "https://freeuptohours.com"
    }
  ],
  "tags": [
    {
      "name": "Leads",
      "description": "Consent-based lead submissions for audits and inquiries."
    }
  ],
  "paths": {
    "/api/leads": {
      "post": {
        "operationId": "submitLeadInquiry",
        "tags": ["Leads"],
        "summary": "Submit a qualified audit or automation inquiry",
        "description": "Creates a lead row for a user who has explicitly asked to contact FreeUpToHours. Do not call this endpoint without user consent.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LeadInquiry"
              },
              "examples": {
                "websiteAudit": {
                  "summary": "Website audit request",
                  "value": {
                    "name": "Juan dela Cruz",
                    "contact": "Messenger: juandelacruz",
                    "business": "Dental clinic in Baguio",
                    "currentSite": "https://example.com",
                    "challenge": "Slow site and low Messenger inquiries.",
                    "subject": "Free homepage and site audit request",
                    "antiSpam": "hours",
                    "startedAt": "1781234567890",
                    "pageUrl": "https://freeuptohours.com/"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lead accepted or honeypot submission ignored.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadAccepted"
                }
              }
            }
          },
          "400": {
            "description": "The submission is missing required fields or failed validation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "The upstream Google Sheets webhook failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "503": {
            "description": "Lead intake is temporarily unavailable because the webhook is not configured.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "x-consent-required": true,
        "x-human-review": true
      }
    }
  },
  "components": {
    "schemas": {
      "LeadInquiry": {
        "type": "object",
        "required": ["name", "contact", "currentSite", "antiSpam", "startedAt"],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "The user's name."
          },
          "contact": {
            "type": "string",
            "minLength": 5,
            "maxLength": 120,
            "description": "Phone, Messenger, WhatsApp, or email where Oliver can reply."
          },
          "business": {
            "type": "string",
            "maxLength": 160,
            "description": "Business name or type."
          },
          "currentSite": {
            "type": "string",
            "minLength": 1,
            "maxLength": 300,
            "description": "Current website, Facebook page, Google Business Profile, or public business page to audit."
          },
          "challenge": {
            "type": "string",
            "maxLength": 1000,
            "description": "What the user wants checked first."
          },
          "subject": {
            "type": "string",
            "maxLength": 160,
            "default": "Free homepage and site audit request"
          },
          "antiSpam": {
            "type": "string",
            "enum": ["hours", "HOURS"],
            "description": "Must be the word HOURS/hours."
          },
          "startedAt": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^[0-9]{10,20}$"
              },
              {
                "type": "number"
              }
            ],
            "description": "Client-side Unix epoch timestamp in milliseconds. Submissions faster than 1.5 seconds are rejected."
          },
          "website": {
            "type": "string",
            "maxLength": 100,
            "description": "Honeypot field. Leave empty or omit."
          },
          "pageUrl": {
            "type": "string",
            "maxLength": 300,
            "description": "Page where the inquiry started."
          }
        },
        "additionalProperties": false
      },
      "LeadAccepted": {
        "type": "object",
        "required": ["ok"],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  }
}
