{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raccoonflow.ai/adapter.schema.json",
  "title": "Raccoon Flow Data Adapter Schema",
  "description": "Public data contract for external data adapters that submit venue, DEX, gateway, agent runtime, manual import, or attestation feed observations into Raccoon Flow.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "adapterId",
    "name",
    "type",
    "status",
    "operator",
    "updatedAt",
    "freshness",
    "targets",
    "outputs"
  ],
  "properties": {
    "schema": {
      "const": "raccoonflow.adapter.v0.1"
    },
    "adapterId": {
      "type": "string",
      "pattern": "^rfad_[a-z0-9_]+$"
    },
    "name": {
      "type": "string"
    },
    "type": {
      "type": "string",
      "enum": [
        "Venue API",
        "DEX Indexer",
        "Gateway",
        "Agent Runtime",
        "Manual Import",
        "Attestation Feed"
      ]
    },
    "status": {
      "type": "string",
      "enum": ["Proposed", "Live", "Paused", "Deprecated", "Failed"]
    },
    "operator": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "type"],
      "properties": {
        "name": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": ["Raccoon Flow", "Venue", "Gateway Provider", "Indexer", "Agent Provider", "Data Partner", "Manual Reviewer"]
        },
        "url": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "freshness": {
      "type": "string",
      "enum": ["Fresh", "Stale", "Missing"]
    },
    "targets": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["type", "name"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["Vault Profile", "Venue Account", "Wallet", "Agent", "Owner", "Execution Controls"]
          },
          "name": {
            "type": "string"
          },
          "profileId": {
            "type": "string"
          },
          "profileJson": {
            "type": "string",
            "format": "uri"
          },
          "venueName": {
            "type": "string"
          },
          "externalId": {
            "type": "string"
          },
          "walletAddress": {
            "type": "string"
          }
        }
      }
    },
    "outputs": {
      "type": "object",
      "additionalProperties": false,
      "required": ["metrics", "observations", "evidence"],
      "properties": {
        "metrics": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "aumUsd": { "type": "number", "minimum": 0 },
            "return7dPct": { "type": "number" },
            "return30dPct": { "type": "number" },
            "maxDrawdownPct": { "type": "number", "minimum": 0 },
            "volatility30dPct": { "type": "number", "minimum": 0 },
            "pnlUsd": { "type": "number" },
            "sampleWindowDays": { "type": "integer", "minimum": 1 }
          }
        },
        "observations": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["type", "status"],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "Trade Summary",
                  "Position Summary",
                  "Risk Limit",
                  "Owner Hint",
                  "Agent Identity Hint",
                  "Execution Control",
                  "Data Freshness",
                  "Anomaly"
                ]
              },
              "status": {
                "type": "string",
                "enum": ["Observed", "Missing", "Partial", "Flagged"]
              },
              "label": {
                "type": "string"
              },
              "value": {
                "type": ["string", "number", "boolean"]
              },
              "confidence": {
                "type": "string",
                "enum": ["Low", "Medium", "High"]
              }
            }
          }
        },
        "evidence": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["evidenceId", "type", "status"],
            "properties": {
              "evidenceId": {
                "type": "string",
                "pattern": "^rfev_[a-z0-9_]+$"
              },
              "type": {
                "type": "string"
              },
              "status": {
                "type": "string",
                "enum": ["Missing", "Submitted", "Verified", "Rejected", "Expired", "Revoked"]
              },
              "evidenceUrl": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    },
    "mapping": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "profileFields": {
          "type": "array",
          "items": { "type": "string" }
        },
        "evidenceTypes": {
          "type": "array",
          "items": { "type": "string" }
        },
        "ratingInputs": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "quality": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "confidence": {
          "type": "string",
          "enum": ["Low", "Medium", "High"]
        },
        "latencySeconds": {
          "type": "integer",
          "minimum": 0
        },
        "coverage": {
          "type": "string",
          "enum": ["Complete", "Partial", "Unknown"]
        },
        "notes": {
          "type": "string"
        }
      }
    }
  }
}
