{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "TIDAS Data Types Overview",
  "type": "object",
  "properties": {
    "CASNumber": { "$ref": "#/$defs/CASNumber" },
    "FT": { "$ref": "#/$defs/FT" },
    "StringMultiLang": { "$ref": "#/$defs/StringMultiLang" },
    "Int1": { "$ref": "#/$defs/Int1" },
    "Int5": { "$ref": "#/$defs/Int5" },
    "Int6": { "$ref": "#/$defs/Int6" },
    "LevelType": { "$ref": "#/$defs/LevelType" },
    "Perc": { "$ref": "#/$defs/Perc" },
    "MatR": { "$ref": "#/$defs/MatR" },
    "MatV": { "$ref": "#/$defs/MatV" },
    "Real": { "$ref": "#/$defs/Real" },
    "ST": { "$ref": "#/$defs/ST" },
    "String": { "$ref": "#/$defs/String" },
    "STMultiLang": { "$ref": "#/$defs/STMultiLang" },
    "FTMultiLang": { "$ref": "#/$defs/FTMultiLang" },
    "GlobalReferenceType": { "$ref": "#/$defs/GlobalReferenceType" },
    "GIS": { "$ref": "#/$defs/GIS" },
    "UUID": { "$ref": "#/$defs/UUID" },
    "Year": { "$ref": "#/$defs/Year" },
    "dateTime": { "$ref": "#/$defs/dateTime" }
  },
  "$defs": {
    "CASNumber": {
      "description": "CAS Number, leading zeros are requried.",
      "type": "string",
      "pattern": "^[0-9]{2,7}-[0-9]{2}-[0-9]$"
    },
    "FT": {
      "type": "string",
      "description": "Free text with an unlimited length."
    },
    "StringMultiLang": {
      "description": "Multi-language string with a maximum length of 500 characters",
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "@xml:lang": {
                "type": "string"
              },
              "#text": {
                "type": "string",
                "maxLength": 500
              }
            },
            "required": [
              "@xml:lang",
              "#text"
            ]
          },
          "uniqueItems": true
        },
        {
          "type": "object",
          "properties": {
            "@xml:lang": {
              "type": "string"
            },
            "#text": {
              "type": "string",
              "maxLength": 500
            }
          },
          "required": [
            "@xml:lang",
            "#text"
          ]
        }
      ]
    },
    "Int1": {
      "description": "1-digit integer number",
      "type": "string",
      "minimum": 0,
      "maximum": 9
    },
    "Int5": {
      "description": "5-digit integer number",
      "type": "string",
      "minimum": 0,
      "maximum": 99999
    }, 
    "Int6": {
      "description": "6-digit integer number",
      "type": "string",
      "minimum": 0,
      "maximum": 999999
    },
    "LevelType": {
      "description": "1-digit integer number, must be equal to or greater than 0",
      "$ref": "#/$defs/Int1"
    },
    "Perc": {
      "description": "percentage amount",
      "type": "string",
      "pattern": "^0\\.\\d+$"
    },
    "MatR": {
      "description": "Mathematical rule",
      "type": "string"
    },
    "MatV": { 
      "description": "Mathematical variable or parameter",
      "type": "string"
    },
    "Real": {
      "description": "38-digit real number",
      "type": "string",
      "pattern": "[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([Ee][+-]?\\d+)?$"
    },
    "ST": {
      "description": "Short text with a maximum length of 1000 characters",
      "type": "string",
      "maxLength": 1000
    },
    "String": {
      "description": "String with a maximum length of 500 characters. Must have a minimum length of 1.",
      "type": "string",
      "maxLength": 500,
      "minLength": 1
    },
    "STMultiLang": {
      "description": "Multi-lang short text with a maximum length of 1000 characters.",
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "@xml:lang": {
                "type": "string"
              },
              "#text": {
                "type": "string",
                "maxLength": 1000
              }
            },
            "required": [
              "@xml:lang",
              "#text"
            ]
          },
          "uniqueItems": true
        },
        {
          "type": "object",
          "properties": {
            "@xml:lang": {
              "type": "string"
            },
            "#text": {
              "type": "string",
              "maxLength": 1000
            }
          },
          "required": [
            "@xml:lang",
            "#text"
          ]
        }
      ]
    },
    "FTMultiLang": {
      "description": "Multi-lang free text with an unlimited length.",
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "@xml:lang": {
                "type": "string"
              },
              "#text": {
                "type": "string"
              }
            },
            "required": [
              "@xml:lang",
              "#text"
            ]
          },
          "uniqueItems": true
        },
        {
          "type": "object",
          "properties": {
            "@xml:lang": {
              "type": "string"
            },
            "#text": {
              "type": "string"
            }
          },
          "required": [
            "@xml:lang",
            "#text"
          ]
        }
      ]
    },
    "GlobalReferenceType": {
      "description": "Represents a reference to another dataset or file. Either refObjectId and version, or uri, or both have to be specified.",
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "@type": {
              "type": "string"
            },
            "@refObjectId": {
              "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}$"
            },
            "@version": {
              "type": "string"
            },
            "@uri": {
              "type": "string"
            },
            "common:shortDescription": {
              "$ref": "#/$defs/STMultiLang"
            }
          },
          "required": [
            "@type",
            "@refObjectId",
            "@uri",
            "@version",
            "common:shortDescription"
          ]
        },
        {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "@type": {
                "type": "string"
              },
              "@refObjectId": {
                "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}$"
              },
              "@version": {
                "type": "string"
              },
              "@uri": {
                "type": "string"
              },
              "common:shortDescription": {
                "$ref": "#/$defs/STMultiLang"
              }
            },
            "required": [
              "@type",
              "@refObjectId",
              "@uri",
              "@version",
              "common:shortDescription"
            ]
          }
        }
      ]
    },
    "GIS": {
      "description": "Global geographical reference in Latitude and LongitudeExamples: \"+42.42;-180\", \"0;0\", \"13.22 ; -3\"",
      "type": "string",
      "pattern": "^\\s*[+-]?((90(\\.0+)?)|([0-8]?\\d(\\.\\d+)?))\\s*;\\s*[+-]?((180(\\.0+)?)|((1[0-7]\\d|[0-9]?\\d)(\\.\\d+)?))\\s*$"
    },
    "UUID": {
      "description": "Unique Universal Identifier, 16-byte hex number",
      "type": "string",
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    },
    "Year": {
      "description": "4-digit year",
      "type": "integer",
      "minimum": 1000,
      "maximum": 9999
    },
    "dateTime": {
      "description": "Date and time format acc. to ISO 8601",
      "type": "string",
      "format": "date-time"
    }
  }
}