{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.kiket.dev/dashboard.json",
  "title": "Kiket Dashboard Definition",
  "description": "Defines an analytics dashboard with panels, charts, and data bindings.",
  "type": "object",
  "required": [
    "model_version",
    "dashboard"
  ],
  "properties": {
    "model_version": {
      "type": "string",
      "const": "1.0"
    },
    "dashboard": {
      "type": "object",
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9_-]+$"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "widgets": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "chart",
              "table",
              "kpi",
              "metric",
              "bar",
              "line",
              "pie",
              "area",
              "heatmap"
            ]
          },
          "title": {
            "type": "string"
          },
          "query": {
            "type": "string",
            "description": "Reference to a query model"
          },
          "query_config": {
            "type": "object",
            "properties": {
              "model": {
                "type": "string"
              },
              "parameters": {
                "type": "array"
              },
              "filters": {
                "type": "object"
              },
              "select": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "group_by": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "aggregates": {
                "type": "object"
              },
              "order_by": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "visualization": {
            "type": "object"
          },
          "options": {
            "type": "object"
          }
        }
      }
    },
    "alerts": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string"
          },
          "condition": {
            "type": "string"
          },
          "notify_roles": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "query_config": {
            "type": "object"
          }
        }
      }
    },
    "layout": {
      "type": "object",
      "properties": {
        "sections": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "id"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "columns": {
                "type": "integer",
                "minimum": 1,
                "maximum": 4,
                "default": 4
              },
              "cards": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "widget"
                  ],
                  "properties": {
                    "widget": {
                      "type": "string"
                    },
                    "span": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 4
                    },
                    "title": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "default_role": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "refresh_interval": {
      "type": "integer",
      "minimum": 0,
      "description": "Seconds between auto-refresh, 0 to disable"
    }
  },
  "additionalProperties": false
}
