{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vizcatalogue.dev/schema/ch.schema.json",
  "title": "Chart entry spec",
  "type": "object",
  "required": ["code", "name", "ovp_version", "chart_type", "meta", "use_when", "not_when", "data_shape", "canvas", "layout", "rules", "roles", "overrides", "anti_patterns", "qa"],
  "properties": {
    "code": {"type": "string", "pattern": "^CH-[A-Z]{3}-[0-9]{2}$"},
    "name": {"type": "string", "minLength": 2},
    "ovp_version": {"type": "string", "pattern": "^[01]\\.[0-9]+$"},
    "chart_type": {"type": "string", "enum": ["bar_h", "bar_v", "bar_v_stacked", "line", "area", "waterfall", "bar_h_div", "matrix", "pie", "scatter", "heatmap", "treemap", "step", "indexed_line", "timeline", "interval", "gantt", "lollipop", "dots_h", "bullet", "slope", "bar_paired", "waffle", "funnel", "bump", "table_bars", "bar_paired_h", "spine", "surplus_deficit", "likert", "histogram", "strip", "boxplot", "pyramid", "beeswarm", "violin", "area_stacked", "sparkline_strip", "fan", "marimekko", "column_line", "hexbin", "kpi_table", "prop_symbol", "pictogram", "radar", "parliament", "gauge", "streamgraph", "horizon", "sunburst", "circle_pack", "parallel", "splom", "chord", "choropleth", "symbol_map", "route_progress", "dot_density", "flow_map", "sankey", "network"]},
    "meta": {
      "type": "object",
      "required": ["intent", "form", "data_required", "relations"],
      "properties": {
        "intent": {"type": "array", "items": {"type": "string"}, "minItems": 1},
        "form": {"type": "string", "minLength": 3},
        "data_required": {"type": "string", "minLength": 5},
        "relations": {
          "type": "object",
          "required": ["family", "implemented_by"],
          "properties": {
            "family": {"type": "string", "pattern": "^[A-Z]{3}$"},
            "alternatives": {"type": "array", "items": {"type": "string"}},
            "see_instead": {
              "type": "array",
              "items": {
                "type": "object",
                "required": ["when", "use"],
                "properties": {
                  "when": {"type": "string"},
                  "use": {"type": "string", "pattern": "^CH-[A-Z]{3}-[0-9]{2}$"}
                }
              }
            },
            "implemented_by": {"type": "array", "items": {"type": "string"}, "minItems": 1}
          }
        }
      }
    },
    "use_when": {"type": "array", "items": {"type": "string"}, "minItems": 1},
    "not_when": {"type": "array", "items": {"type": "string"}, "minItems": 1},
    "data_shape": {"type": "object"},
    "canvas": {
      "type": "object",
      "required": ["width", "height"],
      "properties": {
        "width": {"type": "integer", "minimum": 100},
        "height": {"type": "integer", "minimum": 100}
      }
    },
    "layout": {"type": "object"},
    "scale": {"type": "object"},
    "rules": {"type": "array", "items": {"type": "string"}, "minItems": 1},
    "roles": {
      "type": "object",
      "additionalProperties": {
        "type": "array",
        "minItems": 1,
        "items": {
          "anyOf": [
            {"type": "string"},
            {"type": "array", "items": {"type": "string"}, "minItems": 1}
          ]
        }
      }
    },
    "overrides": {
      "type": "object",
      "propertyNames": {"pattern": "^DL-[0-9]{2}$"},
      "additionalProperties": {"type": "object"}
    },
    "anti_patterns": {"type": "array", "items": {"type": "string"}, "minItems": 1},
    "qa": {"type": "array", "items": {"type": "string"}, "minItems": 1}
  }
}
