{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.kiket.dev/automation.json",
  "title": "Kiket Automation Recipe",
  "description": "Defines an event-driven automation rule with triggers, conditions, and actions.",
  "type": "object",
  "required": [
    "model_version",
    "recipe"
  ],
  "properties": {
    "model_version": {
      "type": "string",
      "const": "1.0"
    },
    "recipe": {
      "type": "object",
      "required": [
        "key",
        "name"
      ],
      "properties": {
        "key": {
          "type": "string",
          "pattern": "^[a-z0-9_-]+$"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        },
        "enabled": {
          "type": "boolean",
          "default": true
        },
        "requires_approval": {
          "type": "boolean",
          "default": false
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "trigger": {
      "type": "object",
      "required": [
        "event"
      ],
      "properties": {
        "event": {
          "type": "string",
          "minLength": 1
        },
        "from_state": {
          "type": "string"
        },
        "to_state": {
          "type": "string"
        },
        "filter": {
          "type": "object"
        }
      },
      "additionalProperties": false
    },
    "conditions": {
      "type": "object",
      "properties": {
        "match": {
          "type": "string",
          "enum": [
            "all",
            "any"
          ],
          "default": "all"
        },
        "rules": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "field"
            ],
            "properties": {
              "field": {
                "type": "string"
              },
              "operator": {
                "type": "string",
                "enum": [
                  "equals",
                  "not_equals",
                  "contains",
                  "not_contains",
                  "is_empty",
                  "is_not_empty",
                  "greater_than",
                  "less_than",
                  "in",
                  "not_in",
                  "matches"
                ]
              },
              "value": {}
            }
          }
        }
      },
      "additionalProperties": false
    },
    "actions": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "assign_user",
              "update_status",
              "update_priority",
              "add_labels",
              "remove_labels",
              "update_fields",
              "notify",
              "webhook",
              "create_issue",
              "add_comment",
              "ai_generate",
              "extension_action"
            ]
          },
          "config": {
            "type": "object"
          }
        }
      }
    },
    "metadata": {
      "type": "object"
    }
  },
  "additionalProperties": false
}
