{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "matrix",
  "type": "object",
  "required": ["published_at", "groups"],
  "additionalProperties": false,
  "properties": {
    "published_at": {"type": "string"},
    "groups": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["group", "rows"],
        "additionalProperties": false,
        "properties": {
          "group": {"type": "string"},
          "rows": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["code", "label", "value", "unit", "as_of", "cadence"],
              "additionalProperties": false,
              "properties": {
                "code": {"type": "string"},
                "label": {"type": "string"},
                "value": {"type": ["number", "null"]},
                "unit": {"type": "string"},
                "as_of": {"type": ["string", "null"], "pattern": "^\\d{4}-\\d{2}-\\d{2}$"},
                "cadence": {"type": "string"}
              }
            }
          }
        }
      }
    },
    "tariffs": {
      "description": "Effective tariff rate history (customs duties / goods imports, NIPA quarterly SAAR). Added 2026-09-28; optional so older matrix.json files still validate.",
      "type": "object",
      "required": ["as_of", "rate_pct", "numerator", "denominator", "method", "history"],
      "additionalProperties": false,
      "properties": {
        "as_of": {"type": ["string", "null"], "pattern": "^\\d{4}-\\d{2}-\\d{2}$"},
        "rate_pct": {"type": ["number", "null"], "minimum": 0, "maximum": 100},
        "numerator": {"type": "string"},
        "denominator": {"type": "string"},
        "method": {"type": "string"},
        "history": {
          "type": "object",
          "required": ["dates", "rate_pct", "customs_bn", "goods_imports_bn"],
          "additionalProperties": false,
          "properties": {
            "dates": {"type": "array", "items": {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$"}},
            "rate_pct": {"type": "array", "items": {"type": "number"}},
            "customs_bn": {"type": "array", "items": {"type": "number"}},
            "goods_imports_bn": {"type": "array", "items": {"type": "number"}}
          }
        }
      }
    }
  }
}
