{
  "openapi": "3.1.0",
  "info": {
    "title": "Building Seattle API",
    "version": "1.0.0",
    "description": "Read-only access to aggregated Seattle construction permit and contractor data. No authentication required."
  },
  "servers": [
    {
      "url": "https://buildingseattle.com"
    }
  ],
  "paths": {
    "/api/permits": {
      "get": {
        "operationId": "searchPermits",
        "summary": "Query permits with optional filters and pagination.",
        "parameters": [
          {
            "name": "neighborhood",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by neighborhood."
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by permit type."
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by permit status."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Free-text search across address, description, permit number, neighborhood, and contractor name."
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching permits.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "per_page": {
                      "type": "integer"
                    },
                    "results": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/contractors": {
      "get": {
        "operationId": "listContractors",
        "summary": "List contractors ranked by active project count (top 20).",
        "responses": {
          "200": {
            "description": "Contractor records, each including an active_projects count.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/stats": {
      "get": {
        "operationId": "getStats",
        "summary": "Aggregate counts and permit value totals for the dashboard.",
        "responses": {
          "200": {
            "description": "Aggregate statistics.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "leads": {
                      "type": "integer"
                    },
                    "permits": {
                      "type": "integer"
                    },
                    "contractors": {
                      "type": "integer"
                    },
                    "active_permits": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}