{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://analysisreports.github.io/schemas/cds.schema.json",
  "title": "Synthetic Sovereign CDS & Risk Premium Registry Schema",
  "type": "object",
  "required": ["$schema", "metadata", "methodology_note", "sovereigns"],
  "properties": {
    "$schema": {"const": "https://analysisreports.github.io/schemas/cds.schema.json"},
    "methodology_note": {"type": "string", "minLength": 1},
    "metadata": {
      "type": "object",
      "required": [
        "title",
        "domain",
        "version",
        "author",
        "license",
        "endpoint",
        "documentation",
        "last_updated",
        "total_sovereigns",
        "evaluated_sovereigns"
      ],
      "properties": {
        "title": {"type": "string", "minLength": 1},
        "domain": {"type": "string", "minLength": 1},
        "version": {"type": "string", "minLength": 1},
        "author": {"type": "string", "minLength": 1},
        "license": {"type": "string", "minLength": 1},
        "endpoint": {"type": "string", "format": "uri"},
        "documentation": {"type": "string", "format": "uri"},
        "last_updated": {"type": "string", "format": "date-time"},
        "total_sovereigns": {"type": "integer", "minimum": 1},
        "evaluated_sovereigns": {"type": "integer", "minimum": 0},
        "insufficient_data_sovereigns": {"type": "integer", "minimum": 0},
        "insufficient_data_entities": {"type": "array", "items": {"type": "string"}},
        "excluded_areas": {"type": "array", "items": {"type": "string"}},
        "rules_source": {"type": "string", "format": "uri"},
        "root_index": {"type": "string", "format": "uri"}
      }
    },
    "sovereigns": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "object",
        "required": [
          "entity_id",
          "iso2",
          "country_name",
          "status",
          "risk_score",
          "synthetic_cds_bps",
          "implied_default_prob_pct",
          "active_pillars",
          "total_pillars",
          "pillar_scores",
          "inputs"
        ],
        "properties": {
          "entity_id": {"type": "string", "pattern": "^GEO_[A-Z0-9_]+$"},
          "iso2": {"type": "string", "pattern": "^[A-Z]{2}$"},
          "country_name": {"type": "string", "minLength": 1},
          "status": {
            "type": "string",
            "enum": [
              "LOW_RISK",
              "MODERATE_RISK",
              "ELEVATED_RISK",
              "HIGH_STRESS",
              "DISTRESS",
              "INSUFFICIENT_DATA"
            ]
          },
          "risk_score": {"type": ["number", "null"], "minimum": 0, "maximum": 100},
          "synthetic_cds_bps": {"type": ["number", "null"], "minimum": 0},
          "implied_default_prob_pct": {"type": ["number", "null"], "minimum": 0, "maximum": 100},
          "active_pillars": {"type": "integer", "minimum": 0},
          "total_pillars": {"type": "integer", "minimum": 1},
          "pillar_scores": {"type": "object"},
          "inputs": {"type": "object"}
        }
      }
    }
  }
}
