{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openeik.org/schemas/0.3/drawings/review.schema.json",
  "$comment": "OpenEik 0.2: folded by tools/fold-schemas.mjs from the proposal drawings, which 0.2 makes a rule (decision D5). Written by hand from the text, not generated.",
  "title": "Review",
  "description": "A review round on one revision, as structured data: drawings/reviews/<review>.json (Part XIV, 13). The revision reviewed by its digests: the SHA-256 of drawing.svg (linked) or of the unlinked drawing's asset, and the hash of revision.json, as reviewed. A host keeps reviews and their working state; at the close the authoring tool saves the review into the building. Seen ticks, read receipts and each person's progress are the host's, and stay out.",
  "type": "object",
  "properties": {
    "format": {
      "const": "openeik-drawing-review/0.1"
    },
    "id": {
      "description": "Unique without coordination across hosts and forks, such as a ULID; never a host's sequence number; the file's name.",
      "$ref": "defs.schema.json#/$defs/id"
    },
    "drawing": {
      "$ref": "defs.schema.json#/$defs/number"
    },
    "sequence": {
      "type": "integer",
      "minimum": 1
    },
    "revision": {
      "$ref": "defs.schema.json#/$defs/revisionCode"
    },
    "svg": {
      "description": "A linked drawing's: the SHA-256 of drawing.svg as reviewed.",
      "$ref": "defs.schema.json#/$defs/hash"
    },
    "asset": {
      "description": "An unlinked drawing's: the SHA-256 of its asset as reviewed.",
      "$ref": "defs.schema.json#/$defs/hash"
    },
    "record": {
      "description": "The hash of revision.json as reviewed.",
      "$ref": "defs.schema.json#/$defs/hash"
    },
    "compared": {
      "description": "The revision the round compared it with.",
      "type": "object",
      "properties": {
        "sequence": {
          "type": "integer",
          "minimum": 1
        },
        "revision": {
          "$ref": "defs.schema.json#/$defs/revisionCode"
        },
        "record": {
          "$ref": "defs.schema.json#/$defs/hash"
        }
      },
      "required": [
        "sequence",
        "revision",
        "record"
      ],
      "x-eik-closed": true
    },
    "profile": {
      "description": "The drawing profile, and the status or purpose code the round reviewed for.",
      "type": "object",
      "properties": {
        "id": {
          "$ref": "defs.schema.json#/$defs/profileId"
        },
        "code": {
          "$ref": "defs.schema.json#/$defs/code"
        },
        "purpose": {
          "$ref": "defs.schema.json#/$defs/code"
        }
      },
      "required": [
        "id"
      ],
      "x-eik-closed": true
    },
    "opened": {
      "$ref": "#/$defs/act"
    },
    "due": {
      "$ref": "defs.schema.json#/$defs/date"
    },
    "closed": {
      "description": "Absent while open. A closed review is frozen (XIV.13.4, rule 5).",
      "$ref": "#/$defs/act"
    },
    "reviewers": {
      "type": "array",
      "maxItems": 1000,
      "items": {
        "$ref": "#/$defs/reviewer"
      }
    },
    "items": {
      "type": "array",
      "maxItems": 100000,
      "items": {
        "$ref": "#/$defs/item"
      }
    }
  },
  "required": [
    "format",
    "id",
    "drawing",
    "sequence",
    "revision",
    "record",
    "profile",
    "opened",
    "reviewers",
    "items"
  ],
  "oneOf": [
    {
      "required": [
        "svg"
      ]
    },
    {
      "required": [
        "asset"
      ]
    }
  ],
  "allOf": [
    {
      "if": {
        "required": [
          "closed"
        ]
      },
      "then": {
        "properties": {
          "items": {
            "items": {
              "required": [
                "anchorState"
              ]
            }
          }
        }
      }
    }
  ],
  "x-eik-closed": true,
  "$defs": {
    "act": {
      "type": "object",
      "properties": {
        "by": {
          "$ref": "defs.schema.json#/$defs/person"
        },
        "at": {
          "$ref": "defs.schema.json#/$defs/time"
        }
      },
      "required": [
        "by",
        "at"
      ],
      "x-eik-closed": true
    },
    "reviewer": {
      "description": "A reviewer, the role in which it reviews (a plain value), and its decision: a code of the profile's decisions (decision A or B).",
      "type": "object",
      "properties": {
        "person": {
          "$ref": "defs.schema.json#/$defs/person"
        },
        "role": {
          "$ref": "defs.schema.json#/$defs/role"
        },
        "decision": {
          "type": "object",
          "properties": {
            "code": {
              "$ref": "defs.schema.json#/$defs/code"
            },
            "at": {
              "$ref": "defs.schema.json#/$defs/time"
            }
          },
          "required": [
            "code",
            "at"
          ],
          "x-eik-closed": true
        }
      },
      "required": [
        "person",
        "role"
      ],
      "x-eik-closed": true
    },
    "author": {
      "description": "A person, or an agent acting for a person: an agent's item counts for nothing until a person accepts it.",
      "type": "object",
      "properties": {
        "person": {
          "$ref": "defs.schema.json#/$defs/person"
        },
        "agent": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1,
              "maxLength": 120
            },
            "version": {
              "type": "string",
              "minLength": 1,
              "maxLength": 80
            }
          },
          "required": [
            "name",
            "version"
          ],
          "x-eik-closed": true
        },
        "actingFor": {
          "$ref": "defs.schema.json#/$defs/person"
        },
        "acceptedBy": {
          "$ref": "defs.schema.json#/$defs/person"
        },
        "acceptedAt": {
          "$ref": "defs.schema.json#/$defs/time"
        }
      },
      "oneOf": [
        {
          "required": [
            "person"
          ]
        },
        {
          "required": [
            "agent",
            "actingFor"
          ]
        }
      ],
      "dependentRequired": {
        "acceptedBy": [
          "acceptedAt"
        ],
        "acceptedAt": [
          "acceptedBy"
        ]
      },
      "x-eik-closed": true
    },
    "anchor": {
      "description": "An anchor, tried in order: an element the revision draws (its data-eik-id), a named feature, the viewport, and a position [s, t] in the feature's frame.",
      "type": "object",
      "properties": {
        "element": {
          "type": "string",
          "minLength": 1,
          "x-eik-ref": "element"
        },
        "feature": {
          "$ref": "defs.schema.json#/$defs/feature"
        },
        "viewport": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "position": {
          "$ref": "defs.schema.json#/$defs/point"
        }
      },
      "required": [
        "element",
        "viewport"
      ],
      "x-eik-closed": true
    },
    "item": {
      "type": "object",
      "properties": {
        "id": {
          "description": "Unique in the review.",
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "kind": {
          "type": "string",
          "enum": [
            "comment",
            "cloud",
            "arrow",
            "text",
            "measure",
            "highlight"
          ]
        },
        "author": {
          "$ref": "#/$defs/author"
        },
        "at": {
          "description": "When it was made.",
          "$ref": "defs.schema.json#/$defs/time"
        },
        "text": {
          "type": "string",
          "maxLength": 4000
        },
        "replies": {
          "type": "array",
          "maxItems": 10000,
          "items": {
            "type": "object",
            "properties": {
              "author": {
                "$ref": "#/$defs/author"
              },
              "at": {
                "$ref": "defs.schema.json#/$defs/time"
              },
              "text": {
                "type": "string",
                "maxLength": 4000
              }
            },
            "required": [
              "author",
              "at",
              "text"
            ],
            "x-eik-closed": true
          }
        },
        "state": {
          "description": "A code of the profile's reviewStates.",
          "$ref": "defs.schema.json#/$defs/code"
        },
        "history": {
          "description": "Its states, oldest first.",
          "type": "array",
          "maxItems": 10000,
          "items": {
            "type": "object",
            "properties": {
              "state": {
                "$ref": "defs.schema.json#/$defs/code"
              },
              "by": {
                "$ref": "defs.schema.json#/$defs/person"
              },
              "at": {
                "$ref": "defs.schema.json#/$defs/time"
              }
            },
            "required": [
              "state",
              "by",
              "at"
            ],
            "x-eik-closed": true
          }
        },
        "anchors": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "$ref": "#/$defs/anchor"
          }
        },
        "sheet": {
          "description": "The fallback, in mm of paper from the sheet's top-left; page, from 1, for an unlinked drawing's PDF of several pages.",
          "type": "object",
          "properties": {
            "x": {
              "type": "number"
            },
            "y": {
              "type": "number"
            },
            "page": {
              "type": "integer",
              "minimum": 1
            }
          },
          "required": [
            "x",
            "y"
          ],
          "x-eik-closed": true
        },
        "shape": {
          "description": "In paper mm: a cloud's, an arrow's, a highlight's or a measure's geometry, or the frame of a text's or a comment's words, as a text box has one; a measure's value is derived from its points and the viewport's scale. form says how its points are drawn (XIV.13.2; open question 61).",
          "type": "object",
          "properties": {
            "points": {
              "type": "array",
              "minItems": 1,
              "maxItems": 10000,
              "items": {
                "$ref": "defs.schema.json#/$defs/point"
              }
            },
            "closed": {
              "type": "boolean"
            },
            "form": {
              "$ref": "defs.schema.json#/$defs/shapeForm"
            }
          },
          "required": [
            "points"
          ],
          "x-eik-closed": true
        },
        "anchorState": {
          "description": "As at the close; required when the review is closed.",
          "type": "string",
          "enum": [
            "attached",
            "moved",
            "elementOnly",
            "orphaned"
          ]
        },
        "change": {
          "description": "The change item of the revision it is about.",
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        },
        "carriedFrom": {
          "description": "The item of an earlier round it carries forward.",
          "type": "object",
          "properties": {
            "review": {
              "$ref": "defs.schema.json#/$defs/id"
            },
            "item": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            }
          },
          "required": [
            "review",
            "item"
          ],
          "x-eik-closed": true
        },
        "bcf": {
          "description": "The GUID of its BCF topic, for round trips.",
          "type": "string",
          "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
        },
        "attachments": {
          "description": "Files kept as assets by digest (photos, for example): personal data, kept in every version that holds them.",
          "type": "array",
          "maxItems": 100,
          "items": {
            "type": "object",
            "properties": {
              "asset": {
                "$ref": "defs.schema.json#/$defs/asset"
              },
              "mediaType": {
                "$ref": "defs.schema.json#/$defs/mediaType"
              }
            },
            "required": [
              "asset",
              "mediaType"
            ],
            "x-eik-closed": true
          }
        }
      },
      "required": [
        "id",
        "kind",
        "author",
        "at",
        "state",
        "anchors",
        "sheet"
      ],
      "x-eik-closed": true
    }
  }
}
