{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openeik.org/schemas/0.1/proposed/drawings/revision.schema.json",
  "$comment": "Proposed for OpenEik 0.2: Part XIV, drawings. Written by hand from the outline of Part XIV, not generated: tools/generate-schemas.mjs keeps this folder and lists none of it in index.json. In 0.1 the file is a kept file; a validator holds it to this schema only when asked for the proposal (@openeik/tools: proposals [\"drawings\"]).",
  "title": "Revision record",
  "description": "What an issued revision is, drawings/issued/<drawing>/revision.json (Part XIV, 8, proposed for 0.2): its sequence, which is its identity, the revision code shown, its state and status, its derivation (equal to the SVG's) and the SVG's digest, or for an unlinked drawing its file, an asset; the changes since the revision it supersedes, and whether clouds mark them. An unlinked revision has file and no svg, derivation or read set (XIV.8.5, rule 11, which a validator checks in code).",
  "type": "object",
  "properties": {
    "format": {
      "const": "openeik-drawing-revision/0.1"
    },
    "drawing": {
      "$ref": "defs.schema.json#/$defs/number"
    },
    "sequence": {
      "description": "The revision's place in the drawing's series; its identity.",
      "type": "integer",
      "minimum": 1
    },
    "revision": {
      "$ref": "defs.schema.json#/$defs/revisionCode"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "date": {
      "description": "The date of issue.",
      "$ref": "defs.schema.json#/$defs/date"
    },
    "state": {
      "$ref": "defs.schema.json#/$defs/state"
    },
    "sharedFor": {
      "$ref": "defs.schema.json#/$defs/sharedFor"
    },
    "status": {
      "$ref": "defs.schema.json#/$defs/status"
    },
    "kind": {
      "description": "Absent, linked.",
      "type": "string",
      "enum": [
        "linked",
        "unlinked"
      ]
    },
    "derivation": {
      "$ref": "derivation.schema.json"
    },
    "svg": {
      "type": "object",
      "properties": {
        "file": {
          "const": "drawing.svg"
        },
        "sha256": {
          "$ref": "defs.schema.json#/$defs/hash"
        },
        "bytes": {
          "type": "integer",
          "minimum": 0,
          "maximum": 67108864
        }
      },
      "required": [
        "file",
        "sha256",
        "bytes"
      ],
      "x-eik-closed": true
    },
    "file": {
      "description": "An unlinked drawing's file: an asset (XIV.8.3).",
      "type": "object",
      "properties": {
        "asset": {
          "$ref": "defs.schema.json#/$defs/asset"
        },
        "sha256": {
          "$ref": "defs.schema.json#/$defs/hash"
        },
        "bytes": {
          "type": "integer",
          "minimum": 0
        },
        "mediaType": {
          "$ref": "defs.schema.json#/$defs/mediaType"
        }
      },
      "required": [
        "asset",
        "sha256",
        "bytes",
        "mediaType"
      ],
      "x-eik-closed": true
    },
    "changes": {
      "description": "What changed since the revision it supersedes (XIV.10.1), recorded whether or not clouds are drawn.",
      "type": "array",
      "maxItems": 10000,
      "items": {
        "$ref": "#/$defs/change"
      }
    },
    "clouds": {
      "description": "The choice made for this update (XIV.10.2).",
      "type": "string",
      "enum": [
        "on",
        "off",
        "throughout"
      ]
    },
    "supersedes": {
      "description": "The revision it replaces: its sequence, code, revision record's hash and SVG's digest. Absent exactly when sequence is 1 (XIV.8.5, rule 6, which a validator checks in code).",
      "type": "object",
      "properties": {
        "sequence": {
          "type": "integer",
          "minimum": 1
        },
        "revision": {
          "$ref": "defs.schema.json#/$defs/revisionCode"
        },
        "record": {
          "$ref": "defs.schema.json#/$defs/hash"
        },
        "svg": {
          "$ref": "defs.schema.json#/$defs/hash"
        }
      },
      "required": [
        "sequence",
        "revision",
        "record"
      ],
      "x-eik-closed": true
    },
    "by": {
      "description": "Who issued it.",
      "$ref": "defs.schema.json#/$defs/person"
    }
  },
  "required": [
    "format",
    "drawing",
    "sequence",
    "revision",
    "title",
    "date",
    "state",
    "status",
    "clouds"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "state": {
            "const": "shared"
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "required": [
          "sharedFor"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "unlinked"
          }
        },
        "required": [
          "kind"
        ]
      },
      "else": {
        "required": [
          "derivation",
          "svg"
        ]
      }
    }
  ],
  "x-eik-closed": true,
  "$defs": {
    "change": {
      "description": "A change item: its id, unique in the revision; what the revision table and the change memo show; who wrote it (person, an agent drafting from the records' diff, or derived from a template); the elements whose drawing it describes, and the viewports where (or sheet).",
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "what": {
          "type": "string",
          "minLength": 1,
          "maxLength": 400
        },
        "by": {
          "type": "string",
          "enum": [
            "person",
            "agent",
            "derived"
          ]
        },
        "elements": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "x-eik-ref": "element"
          }
        },
        "viewports": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "required": [
        "id",
        "what",
        "by"
      ],
      "x-eik-closed": true
    }
  }
}
