{
  "openapi": "3.1.0",
  "info": {
    "title": "OKC HVAC Calculator API",
    "version": "1.0.0",
    "description": "Public, versioned REST API for the OKC HVAC repair-or-replace decision tool, powered by Covington Heat & Air. Estimates only. Final diagnosis, equipment recommendations, availability, and pricing require an on-site evaluation.",
    "contact": {
      "name": "Covington Heat & Air",
      "url": "https://okchvaccalculator.com"
    }
  },
  "servers": [
    {
      "url": "https://okchvaccalculator.com/api/v1",
      "description": "Version 1"
    }
  ],
  "tags": [
    {
      "name": "Business",
      "description": "Business and service-area info"
    },
    {
      "name": "Calculator",
      "description": "Repair-or-replace decision tool"
    },
    {
      "name": "Content",
      "description": "Insights articles, categories, FAQ"
    },
    {
      "name": "Leads",
      "description": "Protected write endpoints (require API key)"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Envelope": {
        "type": "object",
        "properties": {
          "apiVersion": {
            "type": "string",
            "example": "1.0.0"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "data": {}
        },
        "required": [
          "apiVersion",
          "timestamp",
          "data"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "apiVersion": {
            "type": "string"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": {}
            }
          }
        }
      },
      "CalculatorInput": {
        "type": "object",
        "required": [
          "systemType",
          "issueType"
        ],
        "properties": {
          "systemType": {
            "type": "string",
            "example": "ac"
          },
          "issueType": {
            "type": "string",
            "example": "not_cooling"
          },
          "safetyFlags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "isAfterHours": {
            "type": "boolean"
          },
          "systemAge": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 60
          },
          "priorRepairs": {
            "type": "string"
          },
          "repairCostInput": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0
          },
          "repairCostType": {
            "type": [
              "string",
              "null"
            ]
          },
          "replaceCostInput": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0
          },
          "replaceCostType": {
            "type": [
              "string",
              "null"
            ]
          },
          "efficiency": {
            "type": [
              "string",
              "null"
            ]
          },
          "homeSize": {
            "type": [
              "number",
              "null"
            ]
          },
          "utilityBill": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    }
  },
  "paths": {
    "/business": {
      "get": {
        "tags": [
          "Business"
        ],
        "summary": "Get business information",
        "responses": {
          "200": {
            "description": "Business info",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Envelope"
                }
              }
            }
          }
        }
      }
    },
    "/service-area": {
      "get": {
        "tags": [
          "Business"
        ],
        "summary": "Get service area (optionally check a city/zip)",
        "parameters": [
          {
            "name": "cityZip",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "required": false
          }
        ],
        "responses": {
          "200": {
            "description": "Service area"
          }
        }
      }
    },
    "/calculator/meta": {
      "get": {
        "tags": [
          "Calculator"
        ],
        "summary": "Calculator metadata and assumptions",
        "responses": {
          "200": {
            "description": "Meta"
          }
        }
      }
    },
    "/calculator/input-schema": {
      "get": {
        "tags": [
          "Calculator"
        ],
        "summary": "Machine-readable input schema",
        "responses": {
          "200": {
            "description": "Input schema"
          }
        }
      }
    },
    "/calculator/results-schema": {
      "get": {
        "tags": [
          "Calculator"
        ],
        "summary": "Machine-readable results schema",
        "responses": {
          "200": {
            "description": "Results schema"
          }
        }
      }
    },
    "/calculator/run": {
      "post": {
        "tags": [
          "Calculator"
        ],
        "summary": "Run a repair-or-replace analysis",
        "description": "Runs the decision engine and returns a recommendation. Estimates only. Final diagnosis, equipment recommendations, availability, and pricing require an on-site evaluation.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CalculatorInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Decision result with disclaimer and optional safety hard-stop"
          },
          "422": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/articles": {
      "get": {
        "tags": [
          "Content"
        ],
        "summary": "List published articles",
        "parameters": [
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "author",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Article list"
          }
        }
      }
    },
    "/articles/{slug}": {
      "get": {
        "tags": [
          "Content"
        ],
        "summary": "Get a published article by slug",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Article"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/categories": {
      "get": {
        "tags": [
          "Content"
        ],
        "summary": "List content categories",
        "responses": {
          "200": {
            "description": "Categories"
          }
        }
      }
    },
    "/faq": {
      "get": {
        "tags": [
          "Content"
        ],
        "summary": "List published FAQ entries",
        "responses": {
          "200": {
            "description": "FAQ"
          }
        }
      }
    },
    "/lead": {
      "post": {
        "tags": [
          "Leads"
        ],
        "summary": "Submit a lead (protected)",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "phone",
                  "consent"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "phone": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  },
                  "cityZip": {
                    "type": "string"
                  },
                  "consent": {
                    "type": "boolean"
                  },
                  "consentText": {
                    "type": "string"
                  },
                  "message": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Lead stored"
          },
          "401": {
            "description": "Unauthorized"
          },
          "422": {
            "description": "Validation error"
          }
        }
      }
    },
    "/booking-request": {
      "post": {
        "tags": [
          "Leads"
        ],
        "summary": "Submit a booking request (protected)",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "phone",
                  "consent"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "phone": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  },
                  "cityZip": {
                    "type": "string"
                  },
                  "preferredTime": {
                    "type": "string"
                  },
                  "serviceType": {
                    "type": "string"
                  },
                  "notes": {
                    "type": "string"
                  },
                  "consent": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Booking request stored"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/report/email": {
      "post": {
        "tags": [
          "Leads"
        ],
        "summary": "Email a decision report (protected)",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "consent",
                  "result"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "consent": {
                    "type": "boolean"
                  },
                  "result": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Email sent"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    }
  }
}