{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schema.traceoriginal.com/trace-original-agreement-sv-schema-v1.2.json",
  "title": "trace:original Agreement Schema v1.2",
  "language": "sv",
  "locale": "SE",
  "allOf": [{"$ref": "https://schema.traceoriginal.com/trace-original-en-schema-v1.3.json"}],
  "definitions": {
    "JuridiskPerson": {
      "type": "object",
      "properties": {
        "Roll": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 1 },
        "Namn": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 2 },
        "ID" : {
          "oneOf": [{"type": "string"}, {"type": "number"}],
          "position": 3
        },
        "ID Typ": {
          "type": "string",
          "enum": ["VAT identifikationsnummer", "Svenskt personnummer", "Svenskt organisationsnummer", "Mobilnummer", "E-post", "BIC", "LEI", "ZealiD"],
          "position": 4,
          "allOf": [
            {
              "if": {
                "properties": { "ID Typ": { "const": "BIC" } }
              },
              "then": {
                "properties": { "postal_code": { "pattern": "\\w{8}|\\w{11}" } }
              }
            }
          ]
        },
        "Email" : { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 5 },
        "Telefon": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 6 },
        "Adress": {
          "type": "object",
          "properties": {
            "Gata":  { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 1 },
            "Rad 1":  { "oneOf": [{"type": "string"}, {"type": "number"}] , "position": 2 },
            "Rad 2":  { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 3 },
            "Postnummer": {
              "oneOf": [{"type": "string"}, {"type": "number"}],
              "position": 4
            },
            "Stad":  { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 5 },
            "Land": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 6 }
          },
          "additionalProperties": false,
          "position": 7
        },
        "Kommentar": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 8 }
      },
      "additionalProperties": false
    },
    "Bilaga": {
      "type": "object",
      "properties": {
        "Hash": { "type": "string", "position": 1 },
        "Bilagans namn": { "type": "string", "position": 2 },
        "Kommentar": { "type": "string", "position": 3 }
      },
      "required": ["Hash","Bilagans namn"],
      "additionalProperties": false
    },
    "Hex64": {
      "type": "string",
      "pattern": "^([a-f]|\\d){64}$"
    }
  },
  "properties": {
    "Content": {
      "type": "object",
      "properties": {
        "Version": { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 1 },
        "AvtalsID": {
          "oneOf": [{"type": "string"}, {"type": "number"}],
          "position": 2
        },
        "Dokumenttyp": {
          "type": "string",
          "position": 3
        },
        "Avtalstyp": {
          "$comment" : "One of the following are preferred to be used since trace:original has matching translations for them: 'Växel', 'Företagslån', 'Garanti', 'Löpande Skuldebrev', 'Generiskt', 'Bolån', 'CMR', 'Konossement', 'Avtal', 'Kontrakt', 'Testamente', 'Certifikat', 'Inköpsorder', 'Protokoll', 'Faktura', 'Offert', 'Kvitto', 'Biljett', 'Fullmakt', 'Remburs'",
          "type": "string",
          "position": 4
        },
        "Avtalsparter": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/JuridiskPerson"
          },
          "minItems": 0,
          "uniqueItems": true,
          "position": 5
        },
        "Avtalsvillkor": {
          "type": ["object", "string", "array", "number"],
          "position": 6
        },
        "Bilagor": {"type": "array",
          "items": {
            "$ref": "#/definitions/Bilaga"
          },
          "minItems": 0,
          "uniqueItems": true,
          "position": 7
        },
        "Undertecknare": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/JuridiskPerson"
          },
          "minItems": 0,
          "uniqueItems": true,
          "position": 8
        },
        "Allmänna villkor": { "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": [
              {
                "Avtalsparter": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/JuridiskPerson"
                  },
                  "minItems": 0,
                  "uniqueItems": true,
                  "position": 1
                },
                "Avtalsvillkor": {
                  "type": ["object", "string", "array"],
                  "position": 2
                },
                "Bilagor": {"type": "array",
                  "items": {
                    "$ref": "#/definitions/Bilaga"
                  },
                  "minItems": 0,
                  "uniqueItems": true,
                  "position": 3
                },
                "Undertecknare": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/JuridiskPerson"
                  },
                  "minItems": 0,
                  "uniqueItems": true,
                  "position": 4
                },
                "Allmänna villkor": { "oneOf": [{"type": "string"}, {"type": "number"}, {"type":  "object"}], "position": 5 },
                "Anteckning": {"type": "string", "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.",
                "Undertecknare" : {
                  "type": "object",
                  "properties": {
                    "Namn" : { "type": "string", "position": 1 },
                    "ID" : {
                      "oneOf": [{"type": "string"}, {"type": "number"}],
                      "position": 2
                    },
                    "ID Typ" : { "type": "string", "position": 3 },
                    "Signeras i egenskap av" : { "type": "string", "position": 4 },
                    "Roll" : { "type": "string", "position": 5 },
                    "Organisation" : { "type": "string", "position": 6 },
                    "Kommentar" : { "oneOf": [{"type": "string"}, {"type": "number"}], "position": 7 }
                  },
                  "required": ["ID", "ID Typ"],
                  "additionalItems": false,
                  "position": 1
                },
                "Accepterat" : { "type": "boolean", "position": 2 },
                "Metod" : { "type": "string", "position": 3 },
                "Format" : { "type": "string", "position": 4 },
                "Tidpunkt för Signatur" : {  "oneOf": [{"type": "string"}, {"type": "number"}, {"type": "object"}], "position": 5 },
                "Signerad Text" : {  "oneOf": [{"type": "string"}, {"type": "number"}, {"type": "object"}], "position": 6 },
                "Signaturdata" : {  "oneOf": [{"type": "string"}, {"type": "number"}, {"type": "object"}], "position": 7 }
              },
              {
                "type": "string"
              }
            ]
          }
        }
      }
    }
  },
  "minItems": 1
}

