{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://quantkit.co/data/crypto-fees/crypto-exchange-fees.schema.json",
  "title": "QuantKit crypto exchange fees v1",
  "description": "Every figure is a sourced field. as_of is the date of the cited source version, or the check date when the source shows none. A conflicting field has value null and either variants (a scope per value) or a dispute (two or more positions); it is never resolved silently.",
  "type": "object",
  "required": ["schema_version", "dataset_id", "dataset_version", "meta", "venues", "notices", "changes"],
  "properties": {
    "schema_version": {"type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$"},
    "dataset_id": {"const": "crypto-exchange-fees"},
    "dataset_version": {"type": "string"},
    "meta": {"type": "object", "required": ["as_of", "generated_by", "license", "canonical_url"], "properties": {"as_of": {"$ref": "#/$defs/date"}, "generated_by": {"type": "string"}, "license": {"type": "string"}, "canonical_url": {"type": "string", "format": "uri"}, "method_url": {"type": "string"}, "tier": {"type": "string"}, "research_sha256": {"type": "string"}}},
    "venues": {"type": "array", "items": {"type": "object", "required": ["id", "name", "spot_vip0", "perps_vip0", "native_token_discount", "funding", "deposits_and_withdrawals"]}},
    "notices": {"type": "array", "items": {"type": "object", "required": ["id", "venue_id", "title", "text", "as_of", "refs", "sources"]}},
    "changes": {"type": "array", "items": {"type": "object", "required": ["id", "date", "venue_id", "category", "summary", "source_url"], "properties": {"category": {"enum": ["fees", "funding", "geo_regulation"]}}}}
  },
  "$defs": {
    "date": {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$"},
    "field": {
      "type": "object", "required": ["value", "status", "as_of"],
      "properties": {
        "value": {}, "unit": {"type": "string"}, "note": {"type": "string"}, "as_of": {"$ref": "#/$defs/date"}, "source_url": {"type": ["string", "null"], "pattern": "^https://"},
        "status": {"enum": ["verified", "conflicting", "unknown", "blocked", "not_applicable"]},
        "variants": {"type": "array", "minItems": 2, "items": {"type": "object", "required": ["scope_id", "label", "value", "as_of", "source_url"]}},
        "dispute": {"type": "object", "required": ["positions"], "properties": {"positions": {"type": "array", "minItems": 2, "items": {"type": "object", "required": ["claim", "as_of", "source_url"]}}}}
      },
      "allOf": [
        {"if": {"properties": {"status": {"const": "verified"}}}, "then": {"properties": {"value": {"not": {"type": "null"}}, "source_url": {"type": "string"}}, "required": ["source_url"]}},
        {"if": {"properties": {"status": {"enum": ["unknown", "blocked", "not_applicable", "conflicting"]}}}, "then": {"properties": {"value": {"type": "null"}}}},
        {"if": {"properties": {"status": {"const": "conflicting"}}}, "then": {"anyOf": [{"required": ["variants"]}, {"required": ["dispute"]}]}}
      ]
    }
  }
}
