{
  "openapi": "3.1.0",
  "info": {
    "title": "CT Foreclosure Docket API",
    "version": "1.0.0",
    "description": "Internal business research. Full initial sync plus observed changes. No redistribution or resale."
  },
  "servers": [
    {
      "url": "https://ct-foreclosure-monitor.pages.dev"
    }
  ],
  "paths": {
    "/v1/cases": {
      "get": {
        "summary": "List eligible cases",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "town",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "stage",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "filedFrom",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "filedTo",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "records": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Case"
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "changesCursor": {
                      "type": "string"
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing API key"
          },
          "402": {
            "description": "Active API plan required"
          },
          "429": {
            "description": "Request quota exhausted"
          },
          "503": {
            "description": "Source unavailable; retry with backoff"
          }
        }
      }
    },
    "/v1/cases/{id}": {
      "get": {
        "summary": "Retrieve an eligible case",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "record": {
                      "$ref": "#/components/schemas/Case"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing API key"
          },
          "402": {
            "description": "Active API plan required"
          },
          "429": {
            "description": "Request quota exhausted"
          },
          "503": {
            "description": "Source unavailable; retry with backoff"
          },
          "404": {
            "description": "Case absent or no longer eligible"
          }
        }
      }
    },
    "/v1/changes": {
      "get": {
        "summary": "Read observed changes after a cursor",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "changes": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Change"
                      }
                    },
                    "nextCursor": {
                      "type": "string"
                    },
                    "hasMore": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing API key"
          },
          "402": {
            "description": "Active API plan required"
          },
          "429": {
            "description": "Request quota exhausted"
          },
          "503": {
            "description": "Source unavailable; retry with backoff"
          },
          "410": {
            "description": "Cursor expired; repeat initial synchronization"
          }
        }
      }
    },
    "/v1/coverage": {
      "get": {
        "summary": "Inspect coverage and freshness",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "eligibleCount": {
                      "type": "integer"
                    },
                    "publishedCount": {
                      "type": "integer"
                    },
                    "checkedLast24h": {
                      "type": "integer"
                    },
                    "attemptedLast24h": {
                      "type": "integer"
                    },
                    "refreshErrors": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing API key"
          },
          "402": {
            "description": "Active API plan required"
          },
          "429": {
            "description": "Request quota exhausted"
          },
          "503": {
            "description": "Source unavailable; retry with backoff"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Case": {
        "type": "object",
        "properties": {
          "id": {
            "type": [
              "string",
              "null"
            ]
          },
          "town": {
            "type": [
              "string",
              "null"
            ]
          },
          "address": {
            "type": [
              "string",
              "null"
            ]
          },
          "ownerName": {
            "type": [
              "string",
              "null"
            ]
          },
          "mailingAddress": {
            "type": [
              "string",
              "null"
            ]
          },
          "caseNumber": {
            "type": [
              "string",
              "null"
            ]
          },
          "propertyType": {
            "type": [
              "string",
              "null"
            ]
          },
          "sourceUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "filedDate": {
            "type": [
              "string",
              "null"
            ]
          },
          "firstSeen": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": [
              "string",
              "null"
            ]
          },
          "stage": {
            "type": [
              "string",
              "null"
            ]
          },
          "checkedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "attemptedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "refreshError": {
            "type": [
              "string",
              "null"
            ]
          },
          "propertyValue": {
            "type": [
              "number",
              "null"
            ]
          },
          "courtValue": {
            "type": [
              "number",
              "null"
            ]
          },
          "courtDebt": {
            "type": [
              "number",
              "null"
            ]
          },
          "estimatedEquity": {
            "type": [
              "number",
              "null"
            ]
          },
          "livingArea": {
            "type": [
              "number",
              "null"
            ]
          },
          "units": {
            "type": [
              "number",
              "null"
            ]
          }
        }
      },
      "Change": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "recordId": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "observedAt": {
            "type": "string",
            "format": "date-time"
          },
          "changedFields": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}
