{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://notestop.app/notestop-import.schema.json",
  "title": "NoteStop import file, format version 1",
  "description": "The JSON of a .notestopjson (or .json) file, and of pages.json inside a .notestop zip, made outside NoteStop. Guide: https://notestop.app/ai.md. A rule this schema can't express: every table row has the same number of cells.",
  "type": "object",
  "required": ["format", "formatVersion", "roots"],
  "additionalProperties": false,
  "properties": {
    "format": { "const": "NoteStop" },
    "formatVersion": { "const": 1 },
    "exportedAt": { "$ref": "#/$defs/time" },
    "roots": {
      "description": "The pages to import. None may share a name with a page already where they're imported.",
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/page" }
    }
  },
  "$defs": {
    "time": {
      "description": "Milliseconds since 1970-01-01 UTC. Optional everywhere: NoteStop uses the import's time.",
      "type": "integer",
      "minimum": 0
    },
    "page": {
      "type": "object",
      "required": ["name"],
      "additionalProperties": false,
      "properties": {
        "name": { "description": "One line, not blank, with no tabs.", "$ref": "#/$defs/name" },
        "notes": {
          "type": "array",
          "items": { "$ref": "#/$defs/section" },
          "contains": { "$ref": "#/$defs/subpagesSection" },
          "minContains": 0,
          "maxContains": 1
        },
        "children": { "type": "array", "items": { "$ref": "#/$defs/page" } },
        "sortBy": {
          "description": "Only manual keeps the order of children in the file.",
          "enum": ["manual", "name", "dateCreated", "dateModified"]
        },
        "sortsDescending": { "type": "boolean" },
        "showsCheckbox": { "type": "boolean" },
        "isCompleted": { "type": "boolean" },
        "dueOn": { "description": "yyyymmdd", "type": "integer", "minimum": 10000101, "maximum": 99991231 },
        "newSubpageShowsCheckbox": { "type": "boolean" },
        "keepsCompletedInPlace": { "type": "boolean" },
        "showsAsGroup": { "type": "boolean" },
        "listImageSize": { "enum": ["default", "small", "medium", "large"] },
        "createdAt": { "$ref": "#/$defs/time" },
        "modifiedAt": { "$ref": "#/$defs/time" },
        "editedAt": { "$ref": "#/$defs/time" }
      }
    },
    "section": {
      "oneOf": [
        { "$ref": "#/$defs/textSection" },
        { "$ref": "#/$defs/tableSection" },
        { "$ref": "#/$defs/subpagesSection" },
        { "$ref": "#/$defs/imageSection" },
        { "$ref": "#/$defs/fileSection" }
      ]
    },
    "textSection": {
      "type": "object",
      "required": ["type", "text"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "text" },
        "text": { "$ref": "#/$defs/noteText" }
      }
    },
    "tableSection": {
      "type": "object",
      "required": ["type", "table"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "table" },
        "table": { "$ref": "#/$defs/noteTable" }
      }
    },
    "subpagesSection": {
      "description": "Where the page's subpages show among its sections. Without it, they show above the notes.",
      "type": "object",
      "required": ["type"],
      "additionalProperties": false,
      "properties": { "type": { "const": "subpages" } }
    },
    "imageSection": {
      "description": "In a .notestop zip only: the picture is media/<media>.",
      "type": "object",
      "required": ["type", "image"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "image" },
        "image": {
          "type": "object",
          "required": ["media"],
          "additionalProperties": false,
          "properties": {
            "media": {
              "description": "The picture's file name in media: a name, a dot and its format.",
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,128}\\.(jpg|jpeg|png|heic|webp|gif|avif)$"
            }
          }
        }
      }
    },
    "fileSection": {
      "description": "In a .notestop zip only: the file is media/<media>.",
      "type": "object",
      "required": ["type", "file"],
      "additionalProperties": false,
      "properties": {
        "type": { "const": "file" },
        "file": {
          "type": "object",
          "required": ["media", "name"],
          "additionalProperties": false,
          "properties": {
            "media": {
              "description": "The file's name in media: a name, a dot and its extension, which says what kind of file it is.",
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,128}\\.[a-z0-9]{1,16}$"
            },
            "name": { "description": "The name shown, with its extension.", "$ref": "#/$defs/line", "maxLength": 255 }
          }
        }
      }
    },
    "noteText": {
      "type": "object",
      "required": ["version", "blocks"],
      "additionalProperties": false,
      "properties": {
        "version": { "const": 1 },
        "blocks": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/block" } }
      }
    },
    "block": {
      "oneOf": [
        { "$ref": "#/$defs/paragraph" },
        { "$ref": "#/$defs/heading" },
        { "$ref": "#/$defs/list" }
      ]
    },
    "paragraph": {
      "description": "{} is an empty line.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "type": { "const": "paragraph" },
        "runs": { "$ref": "#/$defs/runs" },
        "indent": { "$ref": "#/$defs/indent" },
        "align": { "$ref": "#/$defs/align" },
        "spaceAfter": { "type": "boolean" }
      }
    },
    "heading": {
      "description": "Empty only inside a note: a note can't end with an empty heading.",
      "type": "object",
      "required": ["type"],
      "additionalProperties": false,
      "properties": {
        "type": { "enum": ["h1", "h2"] },
        "runs": { "$ref": "#/$defs/runs" },
        "indent": { "$ref": "#/$defs/indent" },
        "align": { "$ref": "#/$defs/align" },
        "spaceAfter": { "type": "boolean" }
      }
    },
    "list": {
      "type": "object",
      "required": ["type", "items"],
      "additionalProperties": false,
      "properties": {
        "type": { "enum": ["bulletList", "numberedList"] },
        "items": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/listItem" } }
      }
    },
    "listItem": {
      "description": "indent 1 is the second level, 2 the third.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "runs": { "$ref": "#/$defs/runs" },
        "indent": { "$ref": "#/$defs/indent" },
        "align": { "$ref": "#/$defs/align" },
        "spaceAfter": { "type": "boolean" }
      }
    },
    "indent": { "enum": [0, 1, 2] },
    "align": { "enum": ["start", "center"] },
    "runs": {
      "description": "Leave runs out of an empty paragraph rather than writing []. Merge neighbouring runs with the same formatting.",
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/run" }
    },
    "run": {
      "type": "object",
      "required": ["text"],
      "additionalProperties": false,
      "properties": {
        "text": {
          "description": "Not empty. \\n is a line break within the paragraph. No tab or other control character, U+2028 or U+2029.",
          "type": "string",
          "minLength": 1,
          "pattern": "^[^\\u0000-\\u0009\\u000B-\\u001F\\u007F-\\u009F\\u2028\\u2029]+$"
        },
        "bold": {
          "description": "Leave it out for the line's own: bold in a heading (as the reader's theme says), not bold elsewhere. false matters only in a heading.",
          "type": "boolean"
        },
        "color": {
          "description": "Leave it out for the line's own: accent in a heading, plain elsewhere. accent is the reader's theme color; plain the normal text color.",
          "enum": ["accent", "plain", "red", "pink", "blue", "green", "orange", "yellow", "purple", "gray"]
        },
        "link": { "type": "string", "pattern": "^(https?://[^\\s\\\\]+|mailto:[^\\s\\\\/]+|tel:[^\\s\\\\/]+)$" }
      }
    },
    "noteTable": {
      "type": "object",
      "required": ["version", "rows"],
      "additionalProperties": false,
      "properties": {
        "version": { "const": 1 },
        "title": { "$ref": "#/$defs/line" },
        "hasHeaderRow": { "type": "boolean" },
        "rows": {
          "description": "Every row has the same number of cells.",
          "type": "array",
          "minItems": 1,
          "items": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/cell" } }
        }
      }
    },
    "cell": {
      "description": "{} for an empty cell. Plain text only.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "runs": {
          "type": "array",
          "minItems": 1,
          "maxItems": 1,
          "items": {
            "type": "object",
            "required": ["text"],
            "additionalProperties": false,
            "properties": { "text": { "$ref": "#/$defs/line" } }
          }
        }
      }
    },
    "name": {
      "description": "A page's name: one line, with at least one character that isn't a space, and no tab or other control character.",
      "type": "string",
      "pattern": "^[^\\u0000-\\u001F\\u007F-\\u009F\\u2028\\u2029]*[^\\s\\u0000-\\u001F\\u007F-\\u009F\\u2028\\u2029][^\\u0000-\\u001F\\u007F-\\u009F\\u2028\\u2029]*$"
    },
    "line": {
      "description": "One line of text, not empty: no line break, tab or other control character.",
      "type": "string",
      "minLength": 1,
      "pattern": "^[^\\u0000-\\u001F\\u007F-\\u009F\\u2028\\u2029]+$"
    }
  }
}
