{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/anomalyarmor-ai/json-schema/anomalyarmor-ai-metric-definition-create-schema.json",
  "title": "MetricDefinitionCreate",
  "description": "Request schema for creating a metric definition.\n\nTECH-689: Includes percentile_value for PERCENTILE metric type.\nNote: asset_id is extracted from the URL path, not the request body.",
  "x-generated": "2026-11-01",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/docs.anomalyarmor.ai-openapi.json#/components/schemas/MetricDefinitionCreate",
  "properties": {
    "table_path": {
      "type": "string",
      "maxLength": 500,
      "title": "Table Path",
      "description": "Fully qualified table path"
    },
    "column_name": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 255
        },
        {
          "type": "null"
        }
      ],
      "title": "Column Name",
      "description": "Column name (NULL for table-level metrics)"
    },
    "time_column": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 255
        },
        {
          "type": "null"
        }
      ],
      "title": "Time Column",
      "description": "Column containing timestamp/date for time-windowed queries. When set, metric queries filter by this column using capture_interval bounds."
    },
    "metric_type": {
      "$ref": "#/$defs/MetricType",
      "description": "Type of metric to track"
    },
    "capture_interval": {
      "type": "string",
      "maxLength": 100,
      "title": "Capture Interval",
      "description": "Capture interval (hourly, daily, weekly, or cron)"
    },
    "group_by_columns": {
      "anyOf": [
        {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "title": "Group By Columns",
      "description": "Optional dimensional grouping columns"
    },
    "sensitivity": {
      "type": "integer",
      "maximum": 5.0,
      "minimum": 1.0,
      "title": "Sensitivity",
      "description": "Stddev multiplier for anomaly detection (1-5)",
      "default": 3
    },
    "percentile_value": {
      "anyOf": [
        {
          "type": "number",
          "maximum": 1.0,
          "minimum": 0.0
        },
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Percentile Value",
      "description": "For PERCENTILE metric type: the percentile to track (0.0-1.0)"
    },
    "operating_period_mode": {
      "type": "string",
      "enum": [
        "off",
        "auto",
        "schedule"
      ],
      "title": "Operating Period Mode",
      "description": "Operating-period awareness (TECH-984): 'off' pools all history, 'schedule' segments by operating_schedule_id, 'auto' learns a calendar from history",
      "default": "off"
    },
    "operating_schedule_id": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ],
      "title": "Operating Schedule Id",
      "description": "Public UUID of the operating schedule (required for 'schedule' mode)"
    }
  },
  "type": "object",
  "required": [
    "table_path",
    "metric_type",
    "capture_interval"
  ],
  "$defs": {
    "MetricType": {
      "type": "string",
      "enum": [
        "distinct_count",
        "null_percentage",
        "mean",
        "sum",
        "min",
        "max",
        "duplicate_count",
        "duplicate_percent",
        "percentile"
      ],
      "title": "MetricType",
      "description": "Types of metrics that can be tracked.\n\nStatistical metrics compute aggregate values over time with ML-based anomaly detection."
    }
  }
}