{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/kitlangton/cellshot/schemas/frame-v1.schema.json",
  "title": "cellshot structured terminal frame v1",
  "type": "object",
  "required": ["version", "cols", "rows", "foreground", "background", "cursor", "cells"],
  "additionalProperties": false,
  "properties": {
    "version": { "const": 1 },
    "cols": { "$ref": "#/$defs/dimension" },
    "rows": { "$ref": "#/$defs/dimension" },
    "foreground": { "$ref": "#/$defs/color" },
    "background": { "$ref": "#/$defs/color" },
    "cursor": {
      "oneOf": [
        { "type": "null" },
        { "$ref": "#/$defs/cursor" }
      ]
    },
    "cells": {
      "type": "array",
      "items": { "$ref": "#/$defs/cell" }
    }
  },
  "$defs": {
    "dimension": { "type": "integer", "minimum": 0, "maximum": 65535 },
    "channel": { "type": "integer", "minimum": 0, "maximum": 255 },
    "color": {
      "type": "object",
      "required": ["r", "g", "b"],
      "additionalProperties": false,
      "properties": {
        "r": { "$ref": "#/$defs/channel" },
        "g": { "$ref": "#/$defs/channel" },
        "b": { "$ref": "#/$defs/channel" }
      }
    },
    "attributes": {
      "type": "object",
      "required": ["bold", "italic", "faint", "invisible", "strikethrough", "overline", "underline"],
      "additionalProperties": false,
      "properties": {
        "bold": { "type": "boolean" },
        "italic": { "type": "boolean" },
        "faint": { "type": "boolean" },
        "invisible": { "type": "boolean" },
        "strikethrough": { "type": "boolean" },
        "overline": { "type": "boolean" },
        "underline": {
          "oneOf": [
            { "type": "null" },
            { "enum": ["single"] }
          ]
        }
      }
    },
    "cursor": {
      "type": "object",
      "required": ["x", "y", "color", "blinking"],
      "additionalProperties": false,
      "properties": {
        "x": { "$ref": "#/$defs/dimension" },
        "y": { "$ref": "#/$defs/dimension" },
        "color": { "$ref": "#/$defs/color" },
        "blinking": { "type": "boolean" }
      }
    },
    "cell": {
      "type": "object",
      "required": ["x", "y", "text", "width", "foreground", "background", "attributes"],
      "additionalProperties": false,
      "properties": {
        "x": { "$ref": "#/$defs/dimension" },
        "y": { "$ref": "#/$defs/dimension" },
        "text": { "type": "string" },
        "width": { "type": "integer", "minimum": 1, "maximum": 2 },
        "foreground": { "$ref": "#/$defs/color" },
        "background": { "$ref": "#/$defs/color" },
        "attributes": { "$ref": "#/$defs/attributes" }
      }
    }
  }
}
