{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.kiket.dev/query.json",
  "title": "Kiket Query Definition",
  "description": "Defines an analytical query for dashboards and reports.",
  "type": "object",
  "required": [
    "model_version",
    "query"
  ],
  "properties": {
    "model_version": {
      "type": "string",
      "const": "1.0"
    },
    "query": {
      "type": "object",
      "required": [
        "id",
        "model"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9_-]+$"
        },
        "name": {
          "type": "string"
        },
        "model": {
          "type": "string",
          "minLength": 1,
          "description": "Data source model/table name"
        },
        "description": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "select": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "filters": {
      "type": "object"
    },
    "parameters": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "type": "string"
          },
          {
            "type": "object",
            "required": [
              "name"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "enum": [
                  "string",
                  "integer",
                  "float",
                  "boolean",
                  "datetime"
                ],
                "default": "string"
              },
              "required": {
                "type": "boolean",
                "default": false
              },
              "description": {
                "type": "string"
              },
              "default": {}
            }
          }
        ]
      }
    },
    "group_by": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "aggregates": {
      "type": "object"
    },
    "order_by": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "limit": {
      "type": "integer",
      "minimum": 1
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "additionalProperties": false
}
