{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://files.remotivelabs.com/schemas/dashboard-0.1.schema.json",
  "title": "Remotive Dashboard Layout",
  "description": "Schema for Remotive Studio dashboard layout configuration. Compatible with JSON Schema Drafts 4, 6, and 7. To enable strict validation, change all 'additionalProperties: true' to 'additionalProperties: false' throughout this schema.",
  "$comment": "STRICT MODE: This schema uses lenient validation by default (additionalProperties: true). To enable strict validation that rejects unknown properties, search and replace 'additionalProperties\": true' with 'additionalProperties\": false' in this file.",
  "definitions": {
    "Signal": {
      "type": "object",
      "description": "Reference to a signal by namespace, frame, and signal name",
      "required": ["namespace", "frame", "signal"],
      "properties": {
        "namespace": {
          "type": "string",
          "description": "Signal namespace identifier"
        },
        "frame": {
          "type": "string",
          "description": "Frame name containing the signal"
        },
        "signal": {
          "type": "string",
          "description": "Signal name within the frame"
        }
      },
      "additionalProperties": true
    },
    "Frame": {
      "type": "object",
      "description": "Reference to a signal by namespace, frame, and signal name",
      "required": ["namespace", "frame"],
      "properties": {
        "namespace": {
          "type": "string",
          "description": "Signal namespace identifier"
        },
        "frame": {
          "type": "string",
          "description": "Frame name containing the signal"
        },
        "signals": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Signal"
          },
          "description": "List of signals to display in the frame"
        }
      },
      "additionalProperties": true
    },
    "GridConfig": {
      "type": "object",
      "description": "Grid position and size for panel layout",
      "required": ["x", "y", "w", "h"],
      "properties": {
        "x": {
          "type": "integer",
          "minimum": 0,
          "description": "X position in grid units"
        },
        "y": {
          "type": "integer",
          "minimum": 0,
          "description": "Y position in grid units"
        },
        "w": {
          "type": "integer",
          "minimum": 1,
          "description": "Width in grid units"
        },
        "h": {
          "type": "integer",
          "minimum": 1,
          "description": "Height in grid units"
        }
      },
      "additionalProperties": true
    },
    "TimeseriesPanelContent": {
      "type": "object",
      "description": "Data content for a timeseries panel",
      "required": ["signals"],
      "properties": {
        "signals": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Signal"
          },
          "description": "List of signals to display in the chart"
        },
        "frames": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Frame"
          },
          "description": "List of frames to display as cycle-time charts"
        }
      },
      "additionalProperties": true
    },
    "TimeseriesPanelSettings": {
      "type": "object",
      "description": "Display settings for a timeseries panel",
      "properties": {
        "syncChart": {
          "type": "boolean",
          "description": "Whether to sync chart width with global setting. Default: true"
        },
        "chartWidthSeconds": {
          "type": "number",
          "minimum": 1,
          "description": "Per-panel chart width in seconds. Only used when syncChart is false"
        },
        "useSuggestedMinMax": {
          "type": "boolean",
          "description": "Use signal-defined min/max for Y-axis. Default: false"
        },
        "valueAsHex": {
          "type": "boolean",
          "description": "Deprecated: accepted for backward compatibility but ignored. The rollover tooltip always shows hex now."
        },
        "yAxisSettings": {
          "type": "object",
          "description": "Y-axis settings. showDecimal/showHex/showNamed select which label representations to render.",
          "properties": {
            "showDecimal": {
              "type": "boolean",
              "description": "Show the decimal value on Y-axis labels. Default: true"
            },
            "showHex": {
              "type": "boolean",
              "description": "Show the hex value on Y-axis labels. Default: false"
            },
            "showNamed": {
              "type": "boolean",
              "description": "Show the named value (enum name) on Y-axis labels where available. Default: true"
            }
          },
          "additionalProperties": false
        },
        "maxFps": {
          "type": "number",
          "minimum": 5,
          "maximum": 120,
          "description": "Max animation frame rate for the chart (increments of 5). Default: 60"
        }
      },
      "additionalProperties": true
    },
    "GaugePanelContent": {
      "type": "object",
      "description": "Data content for a gauge panel",
      "required": ["signals"],
      "properties": {
        "signals": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Signal"
          },
          "description": "List of signals to display as gauges"
        }
      },
      "additionalProperties": true
    },
    "GaugePanelSettings": {
      "type": "object",
      "description": "Display settings for a gauge panel",
      "properties": {
        "height": {
          "type": "number",
          "description": "Height of each gauge row in pixels"
        }
      },
      "additionalProperties": true
    },
    "MapPanelContent": {
      "type": "object",
      "description": "Data content for a map panel",
      "properties": {
        "signals": {
          "type": "object",
          "description": "Latitude and longitude signal references",
          "properties": {
            "latitude": {
              "$ref": "#/definitions/Signal"
            },
            "longitude": {
              "$ref": "#/definitions/Signal"
            }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": true
    },
    "FrameDistributionPanelContent": {
      "type": "object",
      "description": "Data content for a frame distribution panel",
      "properties": {
        "namespace": {
          "type": "string",
          "description": "The namespace to subscribe to for frame distribution"
        }
      },
      "additionalProperties": true
    },
    "VideoPanelContent": {
      "type": "object",
      "description": "Data content for a video panel",
      "required": ["videoName"],
      "properties": {
        "videoName": {
          "type": "string",
          "description": "A name like 'front-camera' is used to share one dashboard with multiple recordings/videos"
        },
        "videoFilePath": {
          "type": "string",
          "description": "Path to the video file"
        },
        "recordingSessionPath": {
          "type": "string",
          "description": "Path to the recording session"
        }
      },
      "additionalProperties": true
    },
    "TracePanelContent": {
      "type": "object",
      "description": "Data content for a trace panel",
      "required": ["frames"],
      "properties": {
        "frames": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Frame"
          },
          "description": "List of frames to display in the trace panel"
        }
      },
      "additionalProperties": true
    },
    "TracePanelSettings": {
      "type": "object",
      "description": "Display settings for a trace panel",
      "properties": {
        "sortOrder": {
          "type": "string",
          "enum": ["newest-first", "oldest-first"],
          "description": "Sort order for the trace panel. Default: newest-first"
        },
        "groupByFrame": {
          "type": "boolean",
          "description": "Whether to group frames by frame name. Default: false"
        },
        "expandSignals": {
          "type": "boolean",
          "description": "Whether to expand or collapse signals. Default: false"
        },
        "bufferSize": {
          "type": "integer",
          "minimum": 100,
          "description": "The number of entries to display in the trace panel. Default: 10000"
        }
      },
      "additionalProperties": true
    },
    "TimeseriesPanelConfig": {
      "type": "object",
      "description": "Timeseries chart panel configuration",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["timeseries"],
          "description": "Panel type identifier"
        },
        "content": {
          "$ref": "#/definitions/TimeseriesPanelContent"
        },
        "settings": {
          "$ref": "#/definitions/TimeseriesPanelSettings"
        },
        "grid": {
          "$ref": "#/definitions/GridConfig"
        }
      },
      "additionalProperties": true
    },
    "GaugePanelConfig": {
      "type": "object",
      "description": "Gauge panel configuration for displaying signal values",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["gauge"],
          "description": "Panel type identifier"
        },
        "content": {
          "$ref": "#/definitions/GaugePanelContent"
        },
        "settings": {
          "$ref": "#/definitions/GaugePanelSettings"
        },
        "grid": {
          "$ref": "#/definitions/GridConfig"
        }
      },
      "additionalProperties": true
    },
    "MapPanelConfig": {
      "type": "object",
      "description": "Map panel configuration for displaying geographic data",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["map"],
          "description": "Panel type identifier"
        },
        "content": {
          "$ref": "#/definitions/MapPanelContent"
        },
        "grid": {
          "$ref": "#/definitions/GridConfig"
        }
      },
      "additionalProperties": true
    },
    "FrameDistributionPanelConfig": {
      "type": "object",
      "description": "Frame distribution panel for CAN frame visualization",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["frameDistribution"],
          "description": "Panel type identifier"
        },
        "content": {
          "$ref": "#/definitions/FrameDistributionPanelContent"
        },
        "grid": {
          "$ref": "#/definitions/GridConfig"
        }
      },
      "additionalProperties": true
    },
    "VideoPanelConfig": {
      "type": "object",
      "description": "Video panel configuration (recording-specific, not portable between recordings)",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["video"],
          "description": "Panel type identifier"
        },
        "content": {
          "$ref": "#/definitions/VideoPanelContent"
        },
        "grid": {
          "$ref": "#/definitions/GridConfig"
        }
      },
      "additionalProperties": true
    },
    "TracePanelConfig": {
      "type": "object",
      "description": "Trace panel configuration",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["trace"],
          "description": "Panel type identifier"
        },
        "content": {
          "$ref": "#/definitions/TracePanelContent"
        },
        "settings": {
          "$ref": "#/definitions/TracePanelSettings"
        },
        "grid": {
          "$ref": "#/definitions/GridConfig"
        }
      },
      "additionalProperties": true
    },
    "MarkdownPanelContent": {
      "type": "object",
      "description": "Data content for a markdown panel",
      "properties": {
        "text": {
          "type": "string",
          "description": "Markdown text to render"
        }
      },
      "additionalProperties": true
    },
    "MarkdownPanelConfig": {
      "type": "object",
      "description": "Markdown notes panel configuration",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["markdown"],
          "description": "Panel type identifier"
        },
        "content": {
          "$ref": "#/definitions/MarkdownPanelContent"
        },
        "grid": {
          "$ref": "#/definitions/GridConfig"
        }
      },
      "additionalProperties": true
    },
    "PanelConfig": {
      "type": "object",
      "description": "Union of all panel configuration types",
      "discriminator": {
        "propertyName": "type"
      },
      "oneOf": [
        { "$ref": "#/definitions/TimeseriesPanelConfig" },
        { "$ref": "#/definitions/GaugePanelConfig" },
        { "$ref": "#/definitions/MapPanelConfig" },
        { "$ref": "#/definitions/FrameDistributionPanelConfig" },
        { "$ref": "#/definitions/VideoPanelConfig" },
        { "$ref": "#/definitions/TracePanelConfig" },
        { "$ref": "#/definitions/MarkdownPanelConfig" }
      ]
    }
  },
  "type": "object",
  "required": ["schema", "panels"],
  "properties": {
    "schema": {
      "type": "string",
      "enum": ["remotive-dashboard:0.1"],
      "description": "Schema identifier and version (format: name:version)"
    },
    "name": {
      "type": "string",
      "description": "Optional name for the dashboard layout"
    },
    "chartWidthSeconds": {
      "type": "number",
      "minimum": 1,
      "description": "Global chart width in seconds for synced timeseries panels. Default: 30"
    },
    "panels": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/PanelConfig"
      },
      "description": "List of panel configurations"
    }
  },
  "additionalProperties": true
}
