{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:showpapers:scratch-record:1",
  "title": "Note Record",
  "$comment": "Runtime additionally enforces updatedAt >= createdAt, row ID uniqueness within each note, resolved attachment references and their exact manifest union, UTF-16 scalar boundaries and link consistency, and the 512 KiB payload limit. ID and title live in the manifest. Both ordered saved rows and a nullable rich-text document are preserved; this is not an encrypted native vault or an Android import format.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "recordVersion",
    "template",
    "iconId",
    "createdAt",
    "updatedAt",
    "automaticTitle",
    "items",
    "document"
  ],
  "properties": {
    "recordVersion": {
      "type": "integer",
      "const": 1
    },
    "template": {
      "type": "string",
      "enum": [
        "Domestic",
        "International",
        "Custom"
      ]
    },
    "iconId": {
      "type": "string",
      "enum": [
        "checklist",
        "domestic",
        "international",
        "work",
        "study",
        "family",
        "appointment",
        "folder",
        "paper",
        "passport",
        "identity",
        "receipt",
        "shield"
      ]
    },
    "createdAt": {
      "$ref": "#/$defs/timestamp"
    },
    "updatedAt": {
      "$ref": "#/$defs/timestamp"
    },
    "automaticTitle": {
      "type": "boolean"
    },
    "items": {
      "type": "array",
      "maxItems": 80,
      "items": {
        "$ref": "#/$defs/item"
      }
    },
    "document": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/document"
        }
      ]
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    },
    "mark": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "start",
        "end",
        "style"
      ],
      "properties": {
        "start": {
          "type": "integer",
          "minimum": 0,
          "maximum": 32768
        },
        "end": {
          "type": "integer",
          "minimum": 1,
          "maximum": 32768
        },
        "style": {
          "type": "integer",
          "enum": [
            1,
            2
          ]
        }
      }
    },
    "paperLink": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "start",
        "end",
        "paperId"
      ],
      "properties": {
        "start": {
          "type": "integer",
          "minimum": 0,
          "maximum": 32768
        },
        "end": {
          "type": "integer",
          "minimum": 1,
          "maximum": 32768
        },
        "paperId": {
          "$ref": "#/$defs/id"
        }
      }
    },
    "document": {
      "title": "ShowPapers modern Scratch content v1",
      "$comment": "Runtime additionally enforces UTF-16 length and scalar boundaries, start < end <= text length, nonoverlapping link ranges, in-archive Paper resolution, exact manifest Paper references, byte limits and no unknown fields. Bold/italic marks may overlap and are preserved in order. This content profile does not encode saved checklist items or internal vault metadata.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "noteVersion",
        "text",
        "marks",
        "paperIds",
        "paperLinks"
      ],
      "properties": {
        "noteVersion": {
          "type": "integer",
          "const": 1
        },
        "text": {
          "type": "string",
          "maxLength": 32768,
          "pattern": "^[^\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\ud800-\\udfff]*$",
          "x-showpapers-maxUtf16CodeUnits": 32768,
          "description": "Exact Note text. LF and tab are allowed; carriage returns and other control characters are rejected. Bullet and checkbox state are literal line prefixes."
        },
        "marks": {
          "type": "array",
          "maxItems": 2048,
          "items": {
            "$ref": "#/$defs/mark"
          }
        },
        "paperIds": {
          "type": "array",
          "maxItems": 100,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "paperLinks": {
          "type": "array",
          "maxItems": 640,
          "items": {
            "$ref": "#/$defs/paperLink"
          }
        }
      }
    },
    "label": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "not": {
        "anyOf": [
          {
            "pattern": "^[ \\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]*$"
          },
          {
            "pattern": "[\\u0000-\\u001f\\u007f-\\u009f\\ud800-\\udfff]"
          }
        ]
      },
      "description": "Nonblank saved Note label, at most 160 Unicode scalars. Edge whitespace is preserved; controls and surrogate code points are rejected."
    },
    "timestamp": {
      "type": "string",
      "minLength": 1,
      "maxLength": 19,
      "pattern": "^(?:0|[1-9][0-9]{0,17}|[1-8][0-9]{18}|9[0-1][0-9]{17}|92[0-1][0-9]{16}|922[0-2][0-9]{15}|9223[0-2][0-9]{14}|92233[0-6][0-9]{13}|922337[0-1][0-9]{12}|92233720[0-2][0-9]{10}|922337203[0-5][0-9]{9}|9223372036[0-7][0-9]{8}|92233720368[0-4][0-9]{7}|922337203685[0-3][0-9]{6}|9223372036854[0-6][0-9]{5}|92233720368547[0-6][0-9]{4}|922337203685477[0-4][0-9]{3}|9223372036854775[0-7][0-9]{2}|922337203685477580[0-6]|9223372036854775807)$(?![\\s\\S])",
      "description": "Canonical unsigned ASCII decimal string in 0..9223372036854775807. Preserved exactly; stored values may represent ordering stamps rather than wall-clock dates."
    },
    "item": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "label",
        "checked",
        "checkable",
        "paperIds"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "label": {
          "$ref": "#/$defs/label"
        },
        "checked": {
          "type": "boolean"
        },
        "checkable": {
          "type": "boolean"
        },
        "paperIds": {
          "type": "array",
          "maxItems": 8,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        }
      },
      "description": "One saved row. Retain checked even when checkable is false. Attachments are ordered unique persisted semantic references."
    }
  }
}
