{
  "$id": "https://schemas.fermihdi.io/hd/select_query.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "FermiHDI HD Select Query Schema",
  "type": "object",
  "properties": {
    "query_id": {
      "description": "Query ID; uint32",
      "type": "integer"
    },
    "query_qos": {
      "description": "Query priority / QoS weight (1–255). Sets the Storage Node NVMe read-QD weighting and WFQ admission ordering for this query's batches; higher weights receive proportionally more read budget when queries compete. 0/absent/invalid defaults to 1 (lowest priority, equal weight). When omitted, the node's default_query_qos admin configuration applies.",
      "type": "integer",
      "minimum": 0,
      "maximum": 255,
      "default": 1
    },
    "batch_ids": {
      "description": "Bytearray hex; batch ids are not strings or integers, they are 64 byte bytearrays even if their origin was a string or integer",
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 128,
        "maxLength": 128
      }
    },
    "sub_queries": {
      "description": "Select query",
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "equality_mask": {
            "description": "A hex bytearray used as a mask for equality matches",
            "type": "string"
          },
          "equality_match": {
            "description": "A hex bytearray used for matching in equality matches",
            "type": "string"
          },
          "not_equality_mask": {
            "description": "A hex bytearray used as a mask for not-equality matches",
            "type": "string"
          },
          "not_equality_match": {
            "description": "A hex bytearray used for matching in not-equality matches",
            "type": "string"
          },
          "greater_mask": {
            "description": "A hex bytearray used as a mask for greater matches",
            "type": "string"
          },
          "greater_match": {
            "description": "A hex bytearray used for matching in greater matches",
            "type": "string"
          },
          "less_mask": {
            "description": "A hex bytearray used as a mask for less matches",
            "type": "string"
          },
          "less_match": {
            "description": "A hex bytearray used for matching in less matches",
            "type": "string"
          },
          "groups": {
            "description": "Matching groups",
            "type": "array",
            "minItems": 0,
            "items": {
              "type": "object",
              "properties": {
                "type": {
                  "description": "Select type",
                  "type": "string",
                  "enum": [
                    "equality",
                    "not_equality",
                    "greater",
                    "less"
                  ]
                },
                "signed": {
                  "description": "If integers, is it signed; 0 = unsigned, 1 = signed",
                  "type": "integer"
                },
                "starting_index": {
                  "description": "index (inclusive) uint32 datatype",
                  "type": "integer"
                },
                "ending_index": {
                  "description": "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) uint32 datatype",
                  "type": "integer"
                }
              },
              "required": [
                "type",
                "signed",
                "starting_index",
                "ending_index"
              ]
            }
          }
        },
        "required": [
          "equality_mask",
          "equality_match",
          "not_equality_mask",
          "not_equality_match",
          "greater_mask",
          "greater_match",
          "less_mask",
          "less_match",
          "groups"
        ]
      }
    },
    "target": {
      "description": "Where selected records should be sent",
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "ip_address_string": {
            "description": "IP address of the target in dot notation",
            "type": "string"
          },
          "ip_address_integer": {
            "description": "IP address of the target in integer format",
            "type": "integer"
          },
          "url": {
            "description": "URL of the target",
            "type": "string"
          },
          "port_number": {
            "description": "The TCP port number of the target",
            "type": "integer"
          }
        },
        "oneOf": [
          {
            "required": [
              "ip_address_string",
              "port_number"
            ]
          },
          {
            "required": [
              "ip_address_integer",
              "port_number"
            ]
          },
          {
            "required": [
              "url",
              "port_number"
            ]
          }
        ]
      }
    },
    "force_verify": {
      "description": "When true (default), the Storage Node re-verifies the batch chain hash before filtering and streaming results. When false, hash re-verification is skipped for maximum read throughput — the SYCL/GPU filter is still applied. Can be overridden by the node's default_query_verify admin configuration.",
      "type": "boolean",
      "default": true
    }
  },
  "required": [
    "query_id",
    "batch_ids",
    "sub_queries",
    "target"
  ]
}