{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schema.traceoriginal.com/trace-original-agreement-en-schema-v1.2.json",
  "title": "trace:original Agreement Schema v1.2",
  "language": "en",
  "locale": "UK",
  "allOf": [{"$ref": "https://schema.traceoriginal.com/trace-original-en-schema-v1.3.json"}],
  "definitions": {
    "LegalEntity": {
      "type": "object",
      "properties": {
        "Role": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 1 },
        "Name": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 2 },
        "ID" : {
          "oneOf": [{"type": "string"}, {"type": "number"}],
          "position": 3
        },
        "ID Type": {
          "type": "string",
          "enum": ["VAT identification number", "Swedish personal registration number", "Swedish corporate registration number", "Mobile number", "E-mail", "BIC", "LEI", "ZealiD"],
          "position": 4
        },
        "Email" : { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 5 },
        "Phone": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 6 },
        "Address": {
          "type": "object",
          "properties": {
            "Street":  { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 1 },
            "Line 1":  { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 2 },
            "Line 2":  { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 3 },
            "ZIP code":  {
              "oneOf": [{"type": "string"}, {"type": "number"}],
              "position": 4
            },
            "City":  { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 5 },
            "Country": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 6 }
          },
          "additionalProperties": false,
          "position": 7
        },
        "Comment": { "oneOf": [{"type": "string"}, {"type": "number"}] }
      },
      "additionalProperties": false
    },
    "Attachment": {
      "type": "object",
      "properties": {
        "Hash": { "type": "string", "position": 1 },
        "File name": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 2 },
        "Comment": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 3 }
      },
      "required": ["Hash","File name"],
      "additionalProperties": false
    },
    "Hex64": {
      "type": "string",
      "pattern": "^([a-f]|\\d){64}$"
    }
  },
  "properties": {
    "Content": {
      "type": "object",
      "properties": {
        "Version": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 1 },
        "Reference": {
          "oneOf": [{"type": "string"}, {"type": "number"}],
          "position": 2
        },
        "Document type": {
          "type": "string",
          "position": 3
        },
        "Agreement type": {
          "$comment" : "One of the following are preferred to be used since trace:original has matching translations for them: 'Bill of Exchange', 'Business loan', 'Guarantee', 'Promissory Note', 'Generic', 'Mortgage', 'CMR', 'Bill of Lading', 'Agreement', 'Contract', 'Testament', 'Certificate', 'Purchase Order', 'Minutes', 'Invoice', 'Tender', 'Receipt', 'Ticket', 'Power of Attorney', 'Letter of Credit', 'Fusion Trade Innovation'",
          "type": "string",
          "position": 4
        },
        "Agreement parties": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/LegalEntity"
          },
          "minItems": 0,
          "uniqueItems": true,
          "position": 5
        },
        "Agreement terms": { "type": ["object", "string", "array", "number"], "position": 6 },
        "Attachments": {"type": "array",
          "items": {
            "$ref": "#/definitions/Attachment"
          },
          "minItems": 0,
          "uniqueItems": true,
          "position": 7
        },
        "Required signers": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/LegalEntity"
          },
          "minItems": 0,
          "uniqueItems": true,
          "position": 8
        },
        "CustomTerms": { "oneOf": [{"type": "object"}, {"type": "string"}, {"type": "number"}], "position": 9 },
        "Initial Pdf": {
          "type": "object",
          "properties": {
            "File name": {
              "type": "string"
            },
            "Hash": {
              "$ref": "#/definitions/Hex64"
            },
            "Description": {
              "type": "string"
            },
            "Pdf form info": {
              "oneOf": [{"type": "array"}, {"type": "object"}]
            },
            "Pdf form operation": {
              "type": "string"
            }
          },
          "required": ["File name", "Hash"],
          "position": 10
        },
        "Custom data": { "type": ["object", "string", "array"], "position": 11 }
      },
      "minProperties": 1
    },
    "Amendments": {
      "type": "array",
      "items": {
        "properties": {
          "Content": {
            "anyOf": [
              {
                "Agreement parties": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/LegalEntity"
                  },
                  "minItems": 0,
                  "uniqueItems": true,
                  "position": 1
                },
                "Agreement terms": { "type": ["object", "string", "array"], "position": 2 },
                "Attachments": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/Attachment"
                  },
                  "minItems": 0,
                  "uniqueItems": true,
                  "position": 3
                },
                "Required signers": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/LegalEntity"
                  },
                  "minItems": 0,
                  "uniqueItems": true,
                  "position": 4
              },
              "CustomTerms": {"oneOf": [{"type": "object"}, {"type": "string"}, {"type":  "object"}], "position": 5},
              "Comment": {"oneOf": [{"type": "string"}, {"type": "number"}], "position": 6}
              },
              {
                "$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"
              }
            ]
          }
        }
      }
    }
  },
  "minItems": 1
}
