{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://signalshopper.com/signals/schema/grid.schema.json",
 "title": "Signal Shopper grid feed",
 "description": "A heat map for one symbol: one or more panels, each a table of rows by columns. Every panel's values, market and model tables need one list per row and one entry per column; a schema cannot express that, so Signal Shopper checks it when the feed loads.",
 "type": "object",
 "required": [
  "format",
  "symbol",
  "columns",
  "panels"
 ],
 "properties": {
  "format": {
   "const": "signalshopper.grid/1"
  },
  "provider": {
   "type": "string"
  },
  "symbol": {
   "type": "string",
   "minLength": 1
  },
  "asOf": {
   "type": "string",
   "format": "date-time"
  },
  "refreshSeconds": {
   "type": "number",
   "minimum": 5,
   "description": "How often the feed changes, in seconds. The page reads it again after this long while it is on screen."
  },
  "rowLabel": {
   "type": "string",
   "minLength": 1
  },
  "columnLabel": {
   "type": "string",
   "minLength": 1
  },
  "legend": {
   "type": "object",
   "required": [
    "positive",
    "negative"
   ],
   "properties": {
    "positive": {
     "type": "string",
     "minLength": 1
    },
    "negative": {
     "type": "string",
     "minLength": 1
    }
   }
  },
  "valueName": {
   "type": "string",
   "minLength": 1,
   "description": "What a value is called, for example \"net gamma\". Defaults to \"gap\"."
  },
  "valueFormat": {
   "enum": [
    "percent",
    "number"
   ],
   "description": "\"percent\" (default) for a fraction shown as a percentage, \"number\" for a number shown as it is."
  },
  "valueUnit": {
   "type": "string",
   "minLength": 1,
   "description": "The unit of a \"number\" value, for example \"$M\"."
  },
  "columns": {
   "type": "array",
   "minItems": 1,
   "maxItems": 60,
   "items": {
    "type": "string",
    "minLength": 1
   }
  },
  "panels": {
   "type": "array",
   "minItems": 1,
   "maxItems": 6,
   "items": {
    "type": "object",
    "required": [
     "key",
     "label",
     "rows",
     "values"
    ],
    "properties": {
     "key": {
      "type": "string",
      "minLength": 1
     },
     "label": {
      "type": "string",
      "minLength": 1
     },
     "rows": {
      "type": "array",
      "minItems": 1,
      "maxItems": 200,
      "items": {
       "type": [
        "number",
        "string"
       ]
      }
     },
     "values": {
      "$ref": "#/$defs/matrix",
      "description": "The value per cell: positive is drawn green, negative red, null is left empty. A fraction unless valueFormat is \"number\"."
     },
     "market": {
      "$ref": "#/$defs/matrix"
     },
     "model": {
      "$ref": "#/$defs/matrix"
     }
    }
   }
  }
 },
 "$defs": {
  "matrix": {
   "type": "array",
   "items": {
    "type": "array",
    "items": {
     "type": [
      "number",
      "null"
     ]
    }
   }
  }
 }
}
