{
  "openapi": "3.1.0",
  "info": {
    "title": "AZ Deal Map API",
    "version": "1.0.0",
    "description": "Bounded Arizona wholesale-deal intelligence. Marketing observations are not title, MLS, appraisal, ownership, availability, or investment advice."
  },
  "servers": [
    {
      "url": "https://azdealmap.com/api/v1"
    }
  ],
  "security": [
    {
      "bearerApiKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerApiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key shown once. Keep it server-side."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "maxLength": 128
        }
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 25
        }
      },
      "Cursor": {
        "name": "cursor",
        "in": "query",
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "Meta": {
        "type": "object",
        "required": [
          "request_id",
          "as_of",
          "next_cursor",
          "has_more",
          "credits_charged",
          "credits_remaining"
        ],
        "properties": {
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "as_of": {
            "type": "string",
            "format": "date-time"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          },
          "has_more": {
            "type": "boolean"
          },
          "credits_charged": {
            "type": "integer"
          },
          "credits_remaining": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "request_id"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string",
                "format": "uuid"
              },
              "details": {}
            }
          }
        }
      },
      "Envelope": {
        "type": "object",
        "required": [
          "data",
          "meta"
        ],
        "properties": {
          "data": {},
          "meta": {
            "$ref": "#/components/schemas/Meta"
          }
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Structured error; errors consume zero credits.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "operationId": "getHealth",
        "security": [],
        "summary": "Service readiness",
        "responses": {
          "200": {
            "description": "Ready"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/live-deals": {
      "get": {
        "operationId": "listLiveDeals",
        "summary": "Active marketed-offer observations",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          },
          {
            "name": "zip",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "city",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "min_price",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "max_price",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One credit per newly billed deal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Envelope"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/properties/search": {
      "get": {
        "operationId": "searchProperties",
        "summary": "Bounded property search; address, ZIP, or city required",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          },
          {
            "name": "address",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 3
            }
          },
          {
            "name": "zip",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "city",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One credit per newly billed property; empty results cost zero"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/properties/{property_id}": {
      "get": {
        "operationId": "getProperty",
        "summary": "Property lookup",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "name": "property_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One property credit"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/properties/{property_id}/events": {
      "get": {
        "operationId": "listPropertyEvents",
        "summary": "Bounded marketing-event history",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          },
          {
            "name": "property_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Two credits per newly billed event; range capped at 366 days"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/markets/{zip}": {
      "get": {
        "operationId": "getMarket",
        "summary": "Latest non-sparse ZIP metric bundle",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "name": "zip",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^\\d{5}$"
            }
          },
          {
            "name": "as_of",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Five credits per newly billed snapshot bundle"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/usage": {
      "get": {
        "operationId": "listUsage",
        "summary": "Owning-account usage only",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Zero credits"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  }
}
