{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.fermihdi.io/hd/dataset_schema.json",
  "title": "FermiHDI HD Dataset Schema",
  "description": "The JSON Schema description for a dataset held in a FermiHDI HD system",
  "type": "object",
  "properties": {
    "version": {
      "description": "The version of the dataset schema",
      "type": "integer"
    },
    "datasets": {
      "description": "An Array of dataset descriptions",
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "description": "A UID unique identifier for the dataset",
            "type": "string"
          },
          "name": {
            "description": "The name of the dataset",
            "type": "string"
          },
          "purpose": {
            "description": "The purpose of the field",
            "type": "string"
          },
          "record_len": {
            "description": "Records are stored as a concatenated byte array, the fields are the number of bytes in a record",
            "type": "integer"
          },
          "dataset_type": {
            "description": "The type of the dataset",
            "type": "string",
            "enum": [
              "time_series",
              "other"
            ]
          },
          "batch_id_field": {
            "description": "Optional - Defines a field used for hashing (batch_id) that should be used on ingest; Note: unless this field is spcifed in the fields section it will not be included in resulting record.",
            "type": "object",
            "properties": {
              "name": {
                "description": "The name of the field in the dataset that should be used as the batch_id; Note: unless also included belowthis field will not be included in the record",
                "type": "string"
              },
              "round_batch_id_field": {
                "description": "If true, rounds the extracted batch ID to the time index interval.",
                "type": "boolean"
              },
              "field_type": {
                "description": "Var type",
                "type": "string",
                "enum": [
                  "string",
                  "integer",
                  "float",
                  "double",
                  "boolean"
                ]
              }
            },
            "required": [
              "name",
              "field_type"
            ]
          },
          "time_index_field": {
            "description": "The name of the field in the dataset that is a timestamp used for indexing the records",
            "type": "integer"
          },
          "time_index_interval": {
            "description": "The number of time_index_interval_unit increments per batch bucket. For example: interval=60 with unit='seconds' creates 60-second batches; interval=60000 with unit='milliseconds' also creates 60-second batches. When batch_id_field is used in a time_series dataset, the field value is expected to be in time_index_interval_unit units.",
            "type": "integer"
          },
          "time_index_interval_unit": {
            "description": "The unit for both the time_index_interval count and the epoch value encoded in the batch_id. Defaults to 'seconds' for backward compatibility. Example: unit='milliseconds' with interval=60000 creates 60-second batches, with the batch_id epoch stored as a millisecond-precision Unix timestamp.",
            "type": "string",
            "enum": [
              "seconds",
              "milliseconds",
              "nanoseconds",
              "minutes"
            ],
            "default": "seconds"
          },
          "compressed_time_fields": {
            "description": "An Array of time fields in the dataset which are time compressed; Note: time compression is based on the use of a unix timestamp at second level accuracy and that the time fields are deltas from that batch_id.",
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "description": "Time field name",
                  "type": "string"
                },
                "time_compression": {
                  "description": "If there is time compression, what is the level - This assumes that the batch_id id a Unix Timestamp at second level accuracy and that the time fields are deltas from that batch_id.",
                  "type": "string",
                  "enum": [
                    "none",
                    "minutes",
                    "seconds",
                    "milliseconds",
                    "nanoseconds"
                  ]
                }
              },
              "required": [
                "name"
              ]
            }
          },
          "storage_query_targets": {
            "description": "An Array of HD storage cluster controller IP addresses or gateways",
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "address": {
                  "description": "The IP address or gateway of the HD storage cluster controller",
                  "type": "string"
                },
                "port": {
                  "description": "The port number of the HD storage cluster controller",
                  "type": "integer"
                },
                "description": {
                  "description": "Description of the storage cluster controller",
                  "type": "string"
                }
              },
              "required": [
                "address",
                "port"
              ]
            },
            "minItems": 1
          },
          "fields": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "description": "Field name",
                  "type": "string"
                },
                "type": {
                  "description": "The type variable of the field",
                  "type": "string",
                  "enum": [
                    "uint8",
                    "int8",
                    "uint16",
                    "int16",
                    "uint32",
                    "int32",
                    "uint64",
                    "int64",
                    "uint128",
                    "int128",
                    "uint256",
                    "int256",
                    "float",
                    "double",
                    "boolean",
                    "string"
                  ]
                },
                "purpose": {
                  "description": "The purpose of the field",
                  "type": "string"
                },
                "first_byte_position": {
                  "description": "The first index (inclusive) in a record bytearray used by this field's data",
                  "type": "integer"
                },
                "last_byte_position": {
                  "description": "The last index (exclusive - Up to but not including: eg. a ending index of 4 and starting index of 0 would result in the indexes 0, 1, 2, and 3 being used) in a record bytearray used by this field's data",
                  "type": "integer"
                }
              },
              "required": [
                "name",
                "type",
                "first_byte_position",
                "last_byte_position"
              ]
            },
            "minItems": 1
          }
        }
      },
      "minItems": 1
    }
  },
  "required": [
    "datasets"
  ]
}
