{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schema.traceoriginal.com/trace-original-envelope-en-schema-v1.0.json",
  "title": "trace:original Envelope Schema v1.0",
  "language": "en",
  "locale": "UK",
  "allOf": [{"$ref": "https://schema.traceoriginal.com/trace-original-en-schema-v1.3.json"}],
  "definitions": {
    "TraceOriginalDocument": {
      "type": "object",
      "properties": {
        "TraceOriginalId": { "$ref": "#/definitions/Hex64", "position": 1 },
        "File name": { "type": "string", "position": 2 },
        "Hash": { "$ref": "#/definitions/Hex64", "position": 3 },
        "Version": { "type": "number", "position": 4 }
      },
      "required": ["TraceOriginalId", "Hash", "File name", "Version"],
      "additionalProperties": false
    },
    "AdditionalDocument": {
      "type": "object",
      "properties": {
        "File name": { "type": "string", "position": 1 },
        "Hash": { "type": "string", "position": 2 }
      },
      "required": ["Hash", "File name"],
      "additionalProperties": false
    },
    "Hex64": {
      "type": "string",
      "pattern": "^([a-f]|\\d){64}$"
    }
  },
  "properties": {
    "Content": {
      "type": "object",
      "properties": {
        "Document code": {
          "oneOf": [{"type": "string"}],
          "position": 1
        },
        "Reference": {
          "oneOf": [{"type": "string"}, {"type": "number"}],
          "position": 2
        },
        "Cover message": {
          "type": "string",
          "position": 3
        },
        "Original documents": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/TraceOriginalDocument"
          },
          "minItems": 1,
          "uniqueItems": true,
          "position": 4
        },
        "Copies": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/TraceOriginalDocument"
          },
          "minItems": 0,
          "uniqueItems": true,
          "position": 5
        },
        "Additional documents": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AdditionalDocument"
          },
          "minItems": 0,
          "uniqueItems": true,
          "position": 6
        }
      },
      "minProperties": 1,
      "additionalItems": false
    },
    "Amendments": {
      "type": "array",
      "items": {
        "properties": {
          "Content": {
            "anyOf": [
              {
                "$comment" : "The following data structure describes 'signatureData' that should be used in a call to the /sign endpoint, where a digital signature that matches one of the required signers of the document should be added.",
                "Subject" : {
                  "type": "object",
                  "properties": {
                    "Name" : { "type": "string", "position": 1 },
                    "ID" : {
                      "oneOf": [{"type": "string"}, {"type": "number"}],
                      "position": 2
                    },
                    "ID Type" : { "type": "string", "position": 3 },
                    "Capacity of signatory" : { "type": "string", "position": 4 },
                    "Role" : { "type": "string", "position": 5 },
                    "Organisation" : { "type": "string", "position": 6 },
                    "Comment" : { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 7 }
                  },
                  "required": ["ID", "ID Type"],
                  "additionalItems": false,
                  "position": 1
                },
                "Accepted" : { "type": "boolean", "position": 2 },
                "Method" : { "type": "string", "position": 3 },
                "Format" : { "type": "string", "position": 4 },
                "Time of signature" : { "oneOf": [{"type": "string"}, {"type": "number"}, {"type": "object"}], "position": 5 },
                "Custom signed text" : { "oneOf": [{"type": "string"}, {"type": "number"}, {"type": "object"}], "position": 6 },
                "Signature" : {  "oneOf": [{"type": "string"}, {"type": "number"}, {"type": "object"}], "position": 7 }
              },
              {
                "type": "string"
              }
            ]
          }
        }
      },
      "uniqueItems": true
    }
  },
  "minItems": 1
}
