{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://naroid.com/schemas/dreztek-spreadsheet-v1.schema.json",
  "title": "DrezTek Spreadsheet v1",
  "description": "Portable spreadsheet interchange for Kanso Sheets and Naro. A workbook is one or more sheets; each sheet is a rectangular grid of rows of cells.",
  "type": "object",
  "required": ["version", "kind", "workbook", "sheets"],
  "additionalProperties": false,
  "properties": {
    "version": { "enum": ["1.0"] },
    "kind": { "const": "dreztek-spreadsheet" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "workbook": {
      "type": "object",
      "required": ["title"],
      "additionalProperties": false,
      "properties": {
        "title": { "type": "string", "minLength": 1, "maxLength": 200 },
        "description": { "type": ["string", "null"], "maxLength": 2000 }
      }
    },
    "sheets": {
      "type": "array",
      "minItems": 1,
      "maxItems": 50,
      "items": { "$ref": "#/$defs/sheet" }
    }
  },
  "$defs": {
    "sheet": {
      "type": "object",
      "required": ["title", "rows"],
      "additionalProperties": false,
      "properties": {
        "title": { "type": "string", "minLength": 1, "maxLength": 200 },
        "frozenRows": { "type": "integer", "minimum": 0, "default": 0 },
        "columnWidths": {
          "type": "object",
          "description": "Sparse map of zero-based column index (as a string key) to pixel width.",
          "propertyNames": { "pattern": "^[0-9]+$" },
          "additionalProperties": { "type": "number", "minimum": 20 }
        },
        "rows": {
          "type": "array",
          "maxItems": 2000,
          "items": {
            "type": "array",
            "maxItems": 200,
            "items": { "$ref": "#/$defs/cell" }
          }
        }
      }
    },
    "cell": {
      "description": "A raw scalar (string, number, boolean, or null) or a cell object for formatted cells. A string beginning with '=' is a formula in A1 notation (e.g. '=SUM(B2:B9)').",
      "oneOf": [
        { "type": ["string", "number", "boolean", "null"] },
        {
          "type": "object",
          "required": ["value"],
          "additionalProperties": false,
          "properties": {
            "value": { "type": ["string", "number", "boolean", "null"] },
            "format": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "bold": { "type": "boolean" },
                "italic": { "type": "boolean" },
                "align": { "enum": ["left", "center", "right"] },
                "backgroundColor": { "type": "string", "maxLength": 32 },
                "numberFormat": { "enum": ["default", "currency", "percentage", "decimal"] }
              }
            }
          }
        }
      ]
    }
  }
}
