{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "XDR column relationships",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "relations"
  ],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "version": {
      "const": 1
    },
    "relations": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "title",
          "description",
          "from",
          "to"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "title": {
            "type": "string",
            "minLength": 1
          },
          "description": {
            "type": "string",
            "minLength": 1
          },
          "from": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "table",
              "column"
            ],
            "properties": {
              "table": {
                "type": "string",
                "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
              },
              "column": {
                "type": "string",
                "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
              },
              "timeColumn": {
                "type": "string",
                "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
              },
              "path": {
                "type": "string",
                "description": "Path inside the column: user.id, items[].id, items[0], or [\"special.key\"]. Empty or omitted means the column itself."
              }
            }
          },
          "to": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "table",
              "column"
            ],
            "properties": {
              "table": {
                "type": "string",
                "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
              },
              "column": {
                "type": "string",
                "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
              },
              "timeColumn": {
                "type": "string",
                "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
              },
              "path": {
                "type": "string",
                "description": "Path inside the column: user.id, items[].id, items[0], or [\"special.key\"]. Empty or omitted means the column itself."
              }
            }
          },
          "tags": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "guidance": {
            "type": "string"
          },
          "kql": {
            "type": "string"
          },
          "otherNotes": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["title", "text", "sourceLabel", "sourceUrl", "query"],
              "properties": {
                "title": { "type": "string", "minLength": 1 },
                "text": { "type": "string", "minLength": 1 },
                "sourceLabel": { "type": "string", "minLength": 1 },
                "sourceUrl": { "type": "string", "format": "uri", "pattern": "^https://" },
                "query": { "type": "string", "minLength": 1 },
                "queryLanguage": { "type": "string" }
              }
            }
          }
        }
      }
    }
  }
}
