{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.hoodbuybutton.com/schemas/off-switch-index-v1.json",
  "title": "Off-Switch Index compact route response",
  "description": "Stable compact representation returned by GET /api/v1/routes.",
  "type": "object",
  "required": ["schemaVersion", "generatedAt", "expiresAt", "request", "summary", "chain", "token", "market", "bestRoute", "routes", "warnings", "sources", "links"],
  "properties": {
    "schemaVersion": { "type": "string", "const": "1.0.0" },
    "generatedAt": { "type": "string", "format": "date-time" },
    "expiresAt": { "type": "string", "format": "date-time" },
    "request": {
      "type": "object",
      "required": ["chainId", "token", "amountUsd", "routeLimit", "representation"],
      "properties": {
        "chainId": { "type": "integer", "const": 4663 },
        "token": { "$ref": "#/$defs/address" },
        "amountUsd": { "type": "number", "minimum": 1, "maximum": 100000 },
        "routeLimit": { "type": "integer", "minimum": 1, "maximum": 20 },
        "representation": { "type": "string", "const": "compact" }
      },
      "additionalProperties": true
    },
    "summary": {
      "type": "object",
      "required": ["state", "evidence", "coverage", "statement"],
      "properties": {
        "state": { "$ref": "#/$defs/state" },
        "evidence": { "type": "string" },
        "coverage": { "type": "string" },
        "statement": { "type": "string" }
      },
      "additionalProperties": true
    },
    "chain": {
      "type": "object",
      "required": ["id", "name", "state", "blockNumber", "blockAt", "lagSeconds"],
      "properties": {
        "id": { "type": "integer", "const": 4663 },
        "name": { "type": "string", "const": "Robinhood Chain" },
        "state": { "$ref": "#/$defs/state" },
        "blockNumber": { "type": ["integer", "null"] },
        "blockAt": { "type": ["string", "null"], "format": "date-time" },
        "lagSeconds": { "type": ["number", "null"] }
      },
      "additionalProperties": true
    },
    "token": { "$ref": "#/$defs/token" },
    "market": {
      "type": "object",
      "required": ["state", "poolsDetected", "poolsReturned", "poolsOmitted", "truncated", "priceUsd", "liquidityUsd", "volume24hUsd"],
      "properties": {
        "state": { "$ref": "#/$defs/state" },
        "poolsDetected": { "type": "integer", "minimum": 0 },
        "poolsReturned": { "type": "integer", "minimum": 0, "maximum": 20 },
        "poolsOmitted": { "type": "integer", "minimum": 0 },
        "truncated": { "type": "boolean" },
        "priceUsd": { "type": ["number", "null"] },
        "liquidityUsd": { "type": ["number", "null"] },
        "volume24hUsd": { "type": ["number", "null"] }
      },
      "additionalProperties": true
    },
    "bestRoute": {
      "oneOf": [
        { "$ref": "#/$defs/route" },
        { "type": "null" }
      ]
    },
    "routes": {
      "type": "array",
      "maxItems": 20,
      "items": { "$ref": "#/$defs/route" }
    },
    "warnings": {
      "type": "array",
      "items": { "type": "string" }
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "kind"],
        "properties": {
          "name": { "type": "string" },
          "kind": { "type": "string" },
          "url": { "type": ["string", "null"], "format": "uri" },
          "address": { "type": ["string", "null"] }
        },
        "additionalProperties": true
      }
    },
    "links": { "$ref": "#/$defs/links" }
  },
  "$defs": {
    "address": {
      "type": "string",
      "pattern": "^0x[a-fA-F0-9]{40}$"
    },
    "state": {
      "type": "string",
      "enum": ["on", "degraded", "unknown"]
    },
    "token": {
      "type": "object",
      "required": ["address", "name", "symbol", "decimals", "verifiedSource", "explorer"],
      "properties": {
        "address": { "$ref": "#/$defs/address" },
        "name": { "type": "string" },
        "symbol": { "type": "string" },
        "decimals": { "type": ["integer", "null"] },
        "verifiedSource": { "type": "boolean" },
        "explorer": { "type": ["string", "null"], "format": "uri" }
      },
      "additionalProperties": true
    },
    "tokenRef": {
      "type": "object",
      "required": ["address", "symbol", "name"],
      "properties": {
        "address": {
          "oneOf": [
            { "$ref": "#/$defs/address" },
            { "type": "null" }
          ]
        },
        "symbol": { "type": ["string", "null"] },
        "name": { "type": ["string", "null"] }
      },
      "additionalProperties": true
    },
    "quote": {
      "type": "object",
      "required": ["state", "amountUsd"],
      "properties": {
        "state": { "$ref": "#/$defs/state" },
        "evidence": { "type": "string" },
        "amountUsd": { "type": "number" },
        "source": { "type": ["string", "null"] },
        "inputAmount": { "type": ["string", "null"] },
        "inputSymbol": { "type": ["string", "null"] },
        "outputAmount": { "type": ["string", "null"] },
        "outputSymbol": { "type": ["string", "null"] },
        "spotOutputAmount": { "type": ["string", "null"] },
        "routeCostPct": { "type": ["number", "null"] },
        "gasEstimate": { "type": ["string", "null"] },
        "initializedTicksCrossed": { "type": ["integer", "null"] },
        "reason": { "type": "string" }
      },
      "additionalProperties": true
    },
    "route": {
      "type": "object",
      "required": ["rank", "state", "evidence", "protocol", "pair", "inputToken", "outputToken", "priceUsd", "liquidityUsd", "volume24hUsd", "trades24h", "feeBps", "quote", "links"],
      "properties": {
        "rank": { "type": "integer", "minimum": 1, "maximum": 20 },
        "state": { "$ref": "#/$defs/state" },
        "evidence": { "type": "string" },
        "protocol": { "type": "string" },
        "pair": {
          "oneOf": [
            { "$ref": "#/$defs/address" },
            { "type": "null" }
          ]
        },
        "inputToken": { "$ref": "#/$defs/tokenRef" },
        "outputToken": { "$ref": "#/$defs/tokenRef" },
        "priceUsd": { "type": ["number", "null"] },
        "liquidityUsd": { "type": ["number", "null"] },
        "volume24hUsd": { "type": ["number", "null"] },
        "trades24h": {
          "type": "object",
          "required": ["buys", "sells", "total"],
          "properties": {
            "buys": { "type": "integer", "minimum": 0 },
            "sells": { "type": "integer", "minimum": 0 },
            "total": { "type": "integer", "minimum": 0 }
          }
        },
        "feeBps": { "type": ["number", "null"] },
        "quote": { "$ref": "#/$defs/quote" },
        "links": { "$ref": "#/$defs/routeLinks" }
      },
      "additionalProperties": true
    },
    "routeLinks": {
      "type": "object",
      "required": ["swap", "market", "explorer"],
      "properties": {
        "swap": { "type": ["string", "null"], "format": "uri" },
        "market": { "type": ["string", "null"], "format": "uri" },
        "explorer": { "type": ["string", "null"], "format": "uri" }
      },
      "additionalProperties": true
    },
    "links": {
      "type": "object",
      "required": ["self", "human", "documentation", "openapi", "schema", "apiCatalog", "health"],
      "properties": {
        "self": { "type": "string", "format": "uri" },
        "human": { "type": "string", "format": "uri" },
        "documentation": { "type": "string", "format": "uri" },
        "openapi": { "type": "string", "format": "uri" },
        "schema": { "type": "string", "format": "uri" },
        "apiCatalog": { "type": "string", "format": "uri" },
        "health": { "type": "string", "format": "uri" }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
