{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.synq.io/synq-monitors/draft/config.schema.json",
  "$defs": {
    "AnomalyEngine": {
      "properties": {
        "sensitivity": {
          "type": "string",
          "enum": [
            "PRECISE",
            "BALANCED",
            "RELAXED"
          ]
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "sensitivity"
      ]
    },
    "Defaults": {
      "properties": {
        "severity": {
          "type": "string",
          "enum": [
            "INFO",
            "WARNING",
            "ERROR"
          ]
        },
        "time_partitioning_column": {
          "type": "string"
        },
        "schedule": {
          "$ref": "#/$defs/Schedule"
        },
        "mode": {
          "$ref": "#/$defs/Mode"
        },
        "timezone": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "Duration": {
      "type": "string",
      "pattern": "^([0-9]+([.][0-9]+)?h)?([0-9]+([.][0-9]+)?m)?([0-9]+([.][0-9]+)?s)?([0-9]+([.][0-9]+)?ms)?([0-9]+([.][0-9]+)?us|µs)?([0-9]+([.][0-9]+)?ns)?$",
      "title": "Duration",
      "description": "An amount of time.",
      "examples": [
        "2h",
        "30m",
        "600s",
        "2h30m"
      ]
    },
    "Entity": {
      "properties": {
        "id": {
          "type": "string"
        },
        "time_partitioning_column": {
          "type": "string"
        },
        "tests": {
          "items": {
            "$ref": "#/$defs/Test"
          },
          "type": "array"
        },
        "monitors": {
          "items": {
            "$ref": "#/$defs/Monitor"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "id"
      ]
    },
    "FixedThresholds": {
      "properties": {
        "min": {
          "type": "number"
        },
        "max": {
          "type": "number"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "MetricOption": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "ROW_COUNT",
            "DELAY",
            "VOLUME_CHANGE_DELAY"
          ]
        },
        {
          "properties": {
            "metric": {
              "type": "string",
              "enum": [
                "ROW_COUNT",
                "DELAY",
                "VOLUME_CHANGE_DELAY"
              ]
            },
            "sensitivity": {
              "type": "string",
              "enum": [
                "PRECISE",
                "BALANCED",
                "RELAXED"
              ]
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "metric"
          ]
        }
      ]
    },
    "Mode": {
      "properties": {
        "anomaly_engine": {
          "$ref": "#/$defs/AnomalyEngine"
        },
        "fixed_thresholds": {
          "$ref": "#/$defs/FixedThresholds"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "Monitor": {
      "anyOf": [
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "custom_numeric"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "filter": {
              "type": "string"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "timezone": {
              "type": "string"
            },
            "mode": {
              "$ref": "#/$defs/Mode"
            },
            "segmentation": {
              "$ref": "#/$defs/Segmentation"
            },
            "schedule": {
              "$ref": "#/$defs/Schedule"
            },
            "time_partitioning_column": {
              "type": "string"
            },
            "metric_aggregation": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "metric_aggregation"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "custom_table_stats"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "timezone": {
              "type": "string"
            },
            "mode": {
              "$ref": "#/$defs/Mode"
            },
            "schedule": {
              "$ref": "#/$defs/Schedule"
            },
            "metrics": {
              "items": {
                "$ref": "#/$defs/MetricOption"
              },
              "type": "array"
            },
            "sensitivity": {
              "type": "string",
              "enum": [
                "PRECISE",
                "BALANCED",
                "RELAXED"
              ]
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "field_stats"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "filter": {
              "type": "string"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "timezone": {
              "type": "string"
            },
            "mode": {
              "$ref": "#/$defs/Mode"
            },
            "segmentation": {
              "$ref": "#/$defs/Segmentation"
            },
            "schedule": {
              "$ref": "#/$defs/Schedule"
            },
            "time_partitioning_column": {
              "type": "string"
            },
            "columns": {
              "items": {
                "type": "string"
              },
              "type": "array",
              "minItems": 1
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "columns"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "freshness"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "filter": {
              "type": "string"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "timezone": {
              "type": "string"
            },
            "mode": {
              "$ref": "#/$defs/Mode"
            },
            "segmentation": {
              "$ref": "#/$defs/Segmentation"
            },
            "schedule": {
              "$ref": "#/$defs/Schedule"
            },
            "time_partitioning_column": {
              "type": "string"
            },
            "expression": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "expression"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "table_stats"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "metrics": {
              "items": {
                "$ref": "#/$defs/MetricOption"
              },
              "type": "array",
              "minItems": 1
            },
            "sensitivity": {
              "type": "string",
              "enum": [
                "PRECISE",
                "BALANCED",
                "RELAXED"
              ]
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "metrics"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "volume"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "filter": {
              "type": "string"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "timezone": {
              "type": "string"
            },
            "mode": {
              "$ref": "#/$defs/Mode"
            },
            "segmentation": {
              "$ref": "#/$defs/Segmentation"
            },
            "schedule": {
              "$ref": "#/$defs/Schedule"
            },
            "time_partitioning_column": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type"
          ]
        }
      ],
      "required": [
        "type"
      ]
    },
    "PartitioningInterval": {
      "type": "string",
      "enum": [
        "1h",
        "24h"
      ]
    },
    "RelationshipColumn": {
      "properties": {
        "source": {
          "type": "string"
        },
        "reference": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "source",
        "reference"
      ]
    },
    "RelationshipReference": {
      "properties": {
        "entity": {
          "type": "string"
        },
        "columns": {
          "items": {
            "$ref": "#/$defs/RelationshipColumn"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "entity",
        "columns"
      ]
    },
    "Schedule": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "daily",
            "hourly",
            "ondemand"
          ]
        },
        {
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "daily",
                "hourly"
              ]
            },
            "time_partitioning_shift": {
              "$ref": "#/$defs/Duration"
            },
            "query_delay": {
              "$ref": "#/$defs/Duration"
            },
            "ignore_last": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type"
          ]
        },
        {
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "ondemand"
              ]
            },
            "time_partitioning_interval": {
              "$ref": "#/$defs/PartitioningInterval"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type"
          ]
        }
      ]
    },
    "Segmentation": {
      "properties": {
        "expression": {
          "type": "string"
        },
        "include_values": {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "exclude_values": {
          "items": {
            "type": "string"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "expression"
      ]
    },
    "SimpleSchedule": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "daily",
            "hourly",
            "ondemand"
          ]
        },
        {
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "daily",
                "hourly"
              ]
            },
            "query_delay": {
              "$ref": "#/$defs/Duration"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type"
          ]
        }
      ]
    },
    "StructuredValue": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "string_literal",
                "expression"
              ]
            },
            "value": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "number"
                }
              ]
            }
          },
          "type": "object",
          "required": [
            "type",
            "value"
          ]
        }
      ]
    },
    "Test": {
      "anyOf": [
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "accepted_values"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "column": {
              "type": "string"
            },
            "values": {
              "$ref": "#/$defs/TestValues"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "column",
            "values"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "business_rule"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "sql_expression": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "sql_expression"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "empty"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "columns": {
              "items": {
                "type": "string",
                "minLength": 1
              },
              "type": "array"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "columns"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "freshness"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "time_partition_column": {
              "type": "string"
            },
            "time_window_seconds": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "max_value"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "column": {
              "type": "string"
            },
            "max_value": {
              "$ref": "#/$defs/StructuredValue"
            },
            "strictly": {
              "type": "boolean"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "column",
            "max_value"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "min_max"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "column": {
              "type": "string"
            },
            "min_value": {
              "$ref": "#/$defs/StructuredValue"
            },
            "max_value": {
              "$ref": "#/$defs/StructuredValue"
            },
            "strictly": {
              "type": "boolean"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "column",
            "min_value",
            "max_value"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "min_value"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "column": {
              "type": "string"
            },
            "min_value": {
              "$ref": "#/$defs/StructuredValue"
            },
            "strictly": {
              "type": "boolean"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "column",
            "min_value"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "not_null"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "columns": {
              "items": {
                "type": "string",
                "minLength": 1
              },
              "type": "array"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "columns"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "rejected_values"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "column": {
              "type": "string"
            },
            "values": {
              "$ref": "#/$defs/TestValues"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "column",
            "values"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "relationships"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "time_partition_column": {
              "type": "string"
            },
            "time_window_seconds": {
              "type": "integer"
            },
            "references": {
              "items": {
                "$ref": "#/$defs/RelationshipReference"
              },
              "type": "array"
            },
            "ignore_nulls": {
              "type": "boolean"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "references"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "relative_time"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "column": {
              "type": "string"
            },
            "relative_column": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "column",
            "relative_column"
          ]
        },
        {
          "properties": {
            "id": {
              "type": "string"
            },
            "type": {
              "const": "unique"
            },
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "schedule": {
              "$ref": "#/$defs/SimpleSchedule"
            },
            "severity": {
              "type": "string",
              "enum": [
                "INFO",
                "WARNING",
                "ERROR"
              ]
            },
            "columns": {
              "items": {
                "type": "string",
                "minLength": 1
              },
              "type": "array"
            },
            "time_partition_column": {
              "type": "string"
            },
            "time_window_seconds": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "type": "object",
          "required": [
            "type",
            "columns"
          ]
        }
      ],
      "required": [
        "type"
      ]
    },
    "TestValues": {
      "items": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "number"
          },
          {
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "string_literal",
                  "expression"
                ]
              },
              "value": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "number"
                  }
                ]
              }
            },
            "type": "object",
            "required": [
              "type",
              "value"
            ]
          }
        ]
      },
      "type": "array"
    },
    "YAMLAnomalyEngine": {
      "properties": {
        "sensitivity": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "sensitivity"
      ]
    },
    "YAMLFixedThresholds": {
      "properties": {
        "min": {
          "type": "number"
        },
        "max": {
          "type": "number"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "YAMLMode": {
      "properties": {
        "anomaly_engine": {
          "$ref": "#/$defs/YAMLAnomalyEngine"
        },
        "fixed_thresholds": {
          "$ref": "#/$defs/YAMLFixedThresholds"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "YAMLMonitor": {
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "expression": {
          "type": "string"
        },
        "metric_aggregation": {
          "type": "string"
        },
        "monitored_ids": {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "monitored_id": {
          "type": "string"
        },
        "fields": {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "segmentation": {
          "$ref": "#/$defs/YAMLSegmentation"
        },
        "filter": {
          "type": "string"
        },
        "severity": {
          "type": "string"
        },
        "time_partitioning": {
          "type": "string"
        },
        "mode": {
          "$ref": "#/$defs/YAMLMode"
        },
        "daily": {
          "$ref": "#/$defs/YAMLSchedule"
        },
        "hourly": {
          "$ref": "#/$defs/YAMLSchedule"
        },
        "timezone": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "id",
        "type"
      ]
    },
    "YAMLSchedule": {
      "properties": {
        "time_partitioning_shift": {
          "$ref": "#/$defs/Duration"
        },
        "query_delay": {
          "$ref": "#/$defs/Duration"
        },
        "ignore_last": {
          "type": "integer"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "YAMLSegmentation": {
      "properties": {
        "expression": {
          "type": "string"
        },
        "include_values": {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "exclude_values": {
          "items": {
            "type": "string"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "expression"
      ]
    }
  },
  "anyOf": [
    {
      "properties": {
        "version": {
          "const": "v1beta1"
        },
        "namespace": {
          "type": "string"
        },
        "defaults": {
          "properties": {
            "severity": {
              "type": "string"
            },
            "time_partitioning": {
              "type": "string"
            },
            "daily": {
              "$ref": "#/$defs/YAMLSchedule"
            },
            "hourly": {
              "$ref": "#/$defs/YAMLSchedule"
            },
            "mode": {
              "$ref": "#/$defs/YAMLMode"
            },
            "timezone": {
              "type": "string"
            }
          },
          "additionalProperties": false,
          "type": "object"
        },
        "monitors": {
          "items": {
            "$ref": "#/$defs/YAMLMonitor"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "monitors"
      ]
    },
    {
      "properties": {
        "version": {
          "const": "v1beta2"
        },
        "namespace": {
          "type": "string"
        },
        "defaults": {
          "$ref": "#/$defs/Defaults"
        },
        "entities": {
          "items": {
            "$ref": "#/$defs/Entity"
          },
          "type": "array",
          "minItems": 1
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "entities",
        "version"
      ]
    }
  ],
  "title": "SYNQ: Observability as Code",
  "description": "Configuration file format for synq-monitors data quality monitoring tool",
  "x-status": "draft"
}
