{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://petrophysics.io/agents/schemas/scene-v1.json",
  "title": "Petrophysics.io plot scene v1",
  "description": "Dataset-bound settings. Runtime also validates data identity, original units, numerical domains and cross-references.",
  "type": "object",
  "properties": {
    "schemaVersion": {
      "const": "petrophysics.scene/v1"
    },
    "tool": {
      "enum": [
        "crossplot",
        "log-viewer"
      ]
    },
    "dataset": {
      "type": "object",
      "properties": {
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "rowCount": {
          "type": "integer",
          "minimum": 1,
          "maximum": 250000
        },
        "filename": {
          "type": "string"
        }
      },
      "required": [
        "sha256",
        "rowCount"
      ],
      "additionalProperties": false
    },
    "config": {
      "type": "object"
    }
  },
  "required": [
    "schemaVersion",
    "tool",
    "dataset",
    "config"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "tool": {
            "const": "crossplot"
          }
        }
      },
      "then": {
        "properties": {
          "config": {
            "$ref": "#/$defs/crossplot"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "tool": {
            "const": "log-viewer"
          }
        }
      },
      "then": {
        "properties": {
          "config": {
            "$ref": "#/$defs/logView"
          }
        }
      }
    }
  ],
  "$defs": {
    "curve": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "minimum": 0
        },
        "mnemonic": {
          "type": "string"
        },
        "unit": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "mnemonic",
        "unit"
      ],
      "additionalProperties": false
    },
    "baseline": {
      "type": "object",
      "properties": {
        "value": {
          "type": "number"
        },
        "enabled": {
          "type": "boolean"
        },
        "leftColour": {
          "type": "string",
          "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "rightColour": {
          "type": "string",
          "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "opacity": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        }
      },
      "required": [
        "value",
        "enabled",
        "leftColour",
        "rightColour",
        "opacity"
      ],
      "additionalProperties": false
    },
    "pair": {
      "type": "object",
      "properties": {
        "a": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "b": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "enabled": {
          "type": "boolean"
        },
        "leftColour": {
          "type": "string",
          "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "rightColour": {
          "type": "string",
          "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "opacity": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        }
      },
      "required": [
        "a",
        "b",
        "enabled",
        "leftColour",
        "rightColour",
        "opacity"
      ],
      "additionalProperties": false
    },
    "axis": {
      "type": "object",
      "properties": {
        "curve": {
          "$ref": "#/$defs/curve"
        },
        "type": {
          "enum": [
            "linear",
            "log"
          ]
        },
        "min": {
          "type": [
            "number",
            "null"
          ]
        },
        "max": {
          "type": [
            "number",
            "null"
          ]
        }
      },
      "required": [
        "curve",
        "type",
        "min",
        "max"
      ],
      "additionalProperties": false
    },
    "points": {
      "type": "object",
      "properties": {
        "shape": {
          "enum": [
            "square",
            "circle",
            "triangle",
            "diamond",
            "plus",
            "cross"
          ]
        },
        "size": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 1,
          "maximum": 20
        },
        "colour": {
          "type": "string",
          "pattern": "^#[0-9a-fA-F]{6}$"
        }
      },
      "required": [
        "shape",
        "size",
        "colour"
      ],
      "additionalProperties": false
    },
    "colouring": {
      "type": "object",
      "properties": {
        "curve": {
          "anyOf": [
            {
              "$ref": "#/$defs/curve"
            },
            {
              "type": "null"
            }
          ]
        },
        "palette": {
          "enum": [
            "viridis",
            "plasma",
            "ocean",
            "warm",
            "blueRed",
            "greyscale"
          ]
        },
        "reverse": {
          "type": "boolean"
        },
        "min": {
          "type": [
            "number",
            "null"
          ]
        },
        "max": {
          "type": [
            "number",
            "null"
          ]
        }
      },
      "required": [
        "curve",
        "palette",
        "reverse",
        "min",
        "max"
      ],
      "additionalProperties": false
    },
    "filter": {
      "type": "object",
      "properties": {
        "curve": {
          "$ref": "#/$defs/curve"
        },
        "conditions": {
          "type": "array",
          "minItems": 1,
          "maxItems": 2,
          "items": {
            "type": "object",
            "properties": {
              "operator": {
                "enum": [
                  "gt",
                  "gte",
                  "lt",
                  "lte",
                  "eq",
                  "neq"
                ]
              },
              "value": {
                "type": "number"
              }
            },
            "required": [
              "operator",
              "value"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "curve",
        "conditions"
      ],
      "additionalProperties": false
    },
    "selection": {
      "type": "object",
      "properties": {
        "rows": {
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": 0
          },
          "uniqueItems": true,
          "maxItems": 250000
        },
        "colour": {
          "type": "string",
          "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "interaction": {
          "enum": [
            "zoom",
            "select"
          ]
        },
        "action": {
          "enum": [
            "replace",
            "add",
            "remove"
          ]
        }
      },
      "required": [
        "rows",
        "colour",
        "interaction",
        "action"
      ],
      "additionalProperties": false
    },
    "regression": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "type": {
          "enum": [
            "linear",
            "polynomial2",
            "polynomial3",
            "polynomial4",
            "power",
            "exponential"
          ]
        },
        "width": {
          "type": "number",
          "minimum": 1,
          "maximum": 20
        }
      },
      "required": [
        "enabled",
        "type",
        "width"
      ],
      "additionalProperties": false
    },
    "crossplot": {
      "type": "object",
      "properties": {
        "x": {
          "$ref": "#/$defs/axis"
        },
        "y": {
          "$ref": "#/$defs/axis"
        },
        "view": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "properties": {
                "xmin": {
                  "type": "number"
                },
                "xmax": {
                  "type": "number"
                },
                "ymin": {
                  "type": "number"
                },
                "ymax": {
                  "type": "number"
                }
              },
              "required": [
                "xmin",
                "xmax",
                "ymin",
                "ymax"
              ],
              "additionalProperties": false
            }
          ]
        },
        "points": {
          "$ref": "#/$defs/points"
        },
        "colouring": {
          "$ref": "#/$defs/colouring"
        },
        "filter": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "$ref": "#/$defs/filter"
            }
          ]
        },
        "selection": {
          "$ref": "#/$defs/selection"
        },
        "regression": {
          "$ref": "#/$defs/regression"
        }
      },
      "required": [
        "x",
        "y",
        "view",
        "points",
        "colouring",
        "filter",
        "selection",
        "regression"
      ],
      "additionalProperties": false
    },
    "display": {
      "type": "object",
      "properties": {
        "curve": {
          "$ref": "#/$defs/curve"
        },
        "min": {
          "type": "number"
        },
        "max": {
          "type": "number"
        },
        "type": {
          "enum": [
            "linear",
            "log"
          ]
        },
        "colour": {
          "type": "string",
          "pattern": "^#[0-9a-fA-F]{6}$"
        },
        "style": {
          "enum": [
            "solid",
            "dash",
            "dot",
            "dashdot",
            "longdash"
          ]
        },
        "width": {
          "type": "number",
          "minimum": 0.5,
          "maximum": 10
        },
        "baselineFill": {
          "$ref": "#/$defs/baseline"
        }
      },
      "required": [
        "curve",
        "min",
        "max",
        "type",
        "colour",
        "style",
        "width",
        "baselineFill"
      ],
      "additionalProperties": false
    },
    "logView": {
      "type": "object",
      "properties": {
        "depth": {
          "type": "object",
          "properties": {
            "curve": {
              "$ref": "#/$defs/curve"
            },
            "top": {
              "type": "number"
            },
            "bottom": {
              "type": "number"
            }
          },
          "required": [
            "curve",
            "top",
            "bottom"
          ],
          "additionalProperties": false
        },
        "tracks": {
          "type": "array",
          "minItems": 4,
          "maxItems": 4,
          "items": {
            "type": "object",
            "properties": {
              "curves": {
                "type": "array",
                "maxItems": 256,
                "items": {
                  "$ref": "#/$defs/display"
                }
              },
              "pairFill": {
                "anyOf": [
                  {
                    "type": "null"
                  },
                  {
                    "$ref": "#/$defs/pair"
                  }
                ]
              }
            },
            "required": [
              "curves",
              "pairFill"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "depth",
        "tracks"
      ],
      "additionalProperties": false
    }
  }
}
