{
  "type": "object",
  "properties": {
    "format": {
      "const": "maozhizhi.chart"
    },
    "version": {
      "const": 6
    },
    "name": {
      "type": "string",
      "maxLength": 160,
      "minLength": 1
    },
    "note": {
      "type": "string",
      "maxLength": 5000
    },
    "sourceImageBase64": {
      "type": "string",
      "maxLength": 32000000
    },
    "blocks": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/block"
      },
      "minItems": 1,
      "maxItems": 12
    },
    "sections": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/section"
      },
      "minItems": 1,
      "maxItems": 100
    },
    "rules": {
      "type": "object",
      "properties": {
        "frontView": {
          "type": "boolean"
        },
        "firstRowRightSide": {
          "type": "boolean"
        },
        "firstRowRightToLeft": {
          "type": "boolean"
        },
        "circular": {
          "type": "boolean"
        }
      },
      "required": [
        "frontView",
        "firstRowRightSide",
        "firstRowRightToLeft"
      ],
      "additionalProperties": false
    },
    "castOnStitches": {
      "type": "integer",
      "minimum": 1,
      "maximum": 2000
    },
    "firstRowIsCastOn": {
      "type": "boolean"
    },
    "finishingNote": {
      "type": "string",
      "maxLength": 5000
    }
  },
  "required": [
    "format",
    "version",
    "name",
    "note",
    "blocks",
    "sections",
    "rules"
  ],
  "additionalProperties": false,
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://maozhizhi.com/import/reference/schema.json",
  "title": "MaoZhiZhi Chart v6",
  "$comment": "Authoring schema. Omit optional fields rather than null. App additionally enforces equal block widths, matching rows/techniqueCells, valid symbol snapshots and source corners, section references and total <=20000. Native decoder is authoritative.",
  "$defs": {
    "block": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "maxLength": 160
        },
        "firstPrintedRow": {
          "type": "integer",
          "minimum": 0,
          "maximum": 10000
        },
        "rows": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[KPU.OMNLRDETSABCFGH]{1,240}$"
          },
          "minItems": 1,
          "maxItems": 400
        },
        "sourceImageBase64": {
          "type": "string",
          "maxLength": 32000000
        },
        "correctedImageBase64": {
          "type": "string",
          "maxLength": 32000000
        },
        "sourceRowCorners": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "x": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "y": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                }
              },
              "required": [
                "x",
                "y"
              ],
              "additionalProperties": false
            },
            "minItems": 4,
            "maxItems": 4
          },
          "minItems": 1,
          "maxItems": 400
        },
        "techniqueCells": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/$defs/cell"
            },
            "minItems": 1,
            "maxItems": 240
          },
          "minItems": 1,
          "maxItems": 400
        },
        "rowPlans": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/rowPlan"
          },
          "minItems": 1,
          "maxItems": 400
        },
        "sourceColumns": {
          "type": "integer",
          "minimum": 1,
          "maximum": 240
        },
        "sourceColumnMap": {
          "type": "array",
          "items": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 0,
                "maximum": 239
              },
              {
                "type": "null"
              }
            ]
          },
          "minItems": 1,
          "maxItems": 240
        }
      },
      "required": [
        "name",
        "firstPrintedRow",
        "rows"
      ],
      "additionalProperties": false
    },
    "section": {
      "type": "object",
      "properties": {
        "block": {
          "type": "integer",
          "minimum": 0,
          "maximum": 11
        },
        "firstRow": {
          "type": "integer",
          "minimum": 1,
          "maximum": 400
        },
        "lastRow": {
          "type": "integer",
          "minimum": 1,
          "maximum": 400
        },
        "repeats": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100
        },
        "restartStitches": {
          "type": "integer",
          "minimum": 1,
          "maximum": 2000
        },
        "startNote": {
          "type": "string",
          "maxLength": 2000
        }
      },
      "required": [
        "block",
        "firstRow",
        "lastRow",
        "repeats"
      ],
      "additionalProperties": false
    },
    "cell": {
      "type": "object",
      "properties": {
        "stitch": {
          "enum": [
            "noStitch",
            "knit",
            "purl",
            "unknown",
            "yarnOver",
            "makeLeft",
            "makePurl",
            "makeRight",
            "slipFront",
            "leftDecrease",
            "rightDecrease",
            "rightPurlDecrease",
            "leftPurlDecrease",
            "cableFront6",
            "cableBack6",
            "cableFront4",
            "cableBack2",
            "cableFront5",
            "cableBack5"
          ]
        },
        "detected": {
          "enum": [
            "noStitch",
            "knit",
            "purl",
            "unknown",
            "yarnOver",
            "makeLeft",
            "makePurl",
            "makeRight",
            "slipFront",
            "leftDecrease",
            "rightDecrease",
            "rightPurlDecrease",
            "leftPurlDecrease",
            "cableFront6",
            "cableBack6",
            "cableFront4",
            "cableBack2",
            "cableFront5",
            "cableBack5"
          ]
        },
        "reviewed": {
          "type": "boolean"
        },
        "symbol": {
          "$ref": "#/$defs/symbol"
        },
        "yarnColor": {
          "type": "string",
          "pattern": "^[0-9A-Fa-f]{6}$"
        },
        "backYarnColor": {
          "type": "string",
          "pattern": "^[0-9A-Fa-f]{6}$"
        },
        "yarnName": {
          "type": "string",
          "maxLength": 80
        },
        "sourceMark": {
          "enum": [
            "vertical",
            "blank"
          ]
        }
      },
      "required": [
        "stitch",
        "detected",
        "reviewed"
      ],
      "additionalProperties": false
    },
    "symbol": {
      "type": "object",
      "properties": {
        "zh": {
          "type": "string",
          "maxLength": 2000
        },
        "en": {
          "type": "string",
          "maxLength": 2000
        },
        "detailZh": {
          "type": "string",
          "maxLength": 2000
        },
        "detailEn": {
          "type": "string",
          "maxLength": 2000
        },
        "japanese": {
          "type": "string",
          "maxLength": 2000
        },
        "id": {
          "type": "string",
          "maxLength": 80,
          "minLength": 1
        },
        "abbr": {
          "type": "string",
          "maxLength": 24
        },
        "family": {
          "type": "string",
          "maxLength": 5000
        },
        "glyph": {
          "type": "string",
          "maxLength": 5000
        },
        "consumed": {
          "type": "integer",
          "minimum": 0,
          "maximum": 48
        },
        "produced": {
          "type": "integer",
          "minimum": 0,
          "maximum": 48
        },
        "span": {
          "type": "integer",
          "minimum": 1,
          "maximum": 24
        },
        "inverse": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 80
            },
            {
              "type": "null"
            }
          ]
        },
        "requiresInstruction": {
          "type": "boolean"
        }
      },
      "required": [
        "id",
        "zh",
        "en",
        "abbr",
        "family",
        "consumed",
        "produced",
        "span",
        "glyph",
        "japanese",
        "detailZh",
        "detailEn"
      ],
      "additionalProperties": false
    },
    "rowPlan": {
      "type": "object",
      "properties": {
        "printedRow": {
          "type": "integer",
          "minimum": 0,
          "maximum": 20000
        },
        "pass": {
          "type": "string",
          "maxLength": 80
        },
        "rightSide": {
          "type": "boolean"
        },
        "rightToLeft": {
          "type": "boolean"
        },
        "heldBefore": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2000
        },
        "heldAfter": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2000
        },
        "note": {
          "type": "string",
          "maxLength": 4000
        }
      },
      "required": [],
      "additionalProperties": false
    }
  }
}