{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/akeda-ru/json-schema/akeda-ru-automation-rule-test-result-schema.json",
  "title": "AutomationRuleTestResult",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/akeda-ru-automation-api-openapi.yml#/components/schemas/AutomationRuleTestResult",
  "type": "object",
  "required": [
    "executor_user_id",
    "when",
    "condition",
    "matched",
    "actions",
    "executed"
  ],
  "properties": {
    "sample": {
      "type": [
        "object",
        "null"
      ],
      "required": [
        "key",
        "event_type",
        "entity",
        "entity_id",
        "occurred_at",
        "payload",
        "source"
      ],
      "properties": {
        "key": {
          "type": "string"
        },
        "event_type": {
          "type": "string"
        },
        "entity": {
          "type": "string"
        },
        "entity_id": {
          "type": "string"
        },
        "title": {
          "type": "string",
          "description": "Номер, идентификатор или тема записи"
        },
        "occurred_at": {
          "type": "string",
          "format": "date-time"
        },
        "payload": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "source": {
          "type": "string",
          "enum": [
            "outbox",
            "direct",
            "payload"
          ]
        }
      }
    },
    "executor_user_id": {
      "type": "integer",
      "format": "int64"
    },
    "when": {
      "type": "object",
      "required": [
        "ok",
        "event_label",
        "values"
      ],
      "properties": {
        "ok": {
          "type": "boolean"
        },
        "event_label": {
          "type": "string"
        },
        "values": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "key",
              "label",
              "value"
            ],
            "properties": {
              "key": {
                "type": "string"
              },
              "label": {
                "type": "string"
              },
              "value": {
                "type": "string"
              }
            }
          }
        },
        "code": {
          "type": "string",
          "description": "no_sample — фактов события за 30 дней нет"
        },
        "message": {
          "type": "string"
        }
      }
    },
    "condition": {
      "type": "object",
      "required": [
        "ok",
        "empty",
        "expression",
        "clauses"
      ],
      "properties": {
        "ok": {
          "type": "boolean"
        },
        "empty": {
          "type": "boolean"
        },
        "expression": {
          "type": "boolean"
        },
        "clauses": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "index",
              "field",
              "field_label",
              "op",
              "op_label",
              "actual",
              "present",
              "ok"
            ],
            "properties": {
              "index": {
                "type": "integer"
              },
              "field": {
                "type": "string"
              },
              "field_label": {
                "type": "string"
              },
              "op": {
                "type": "string"
              },
              "op_label": {
                "type": "string"
              },
              "expected": {
                "type": "string"
              },
              "expected_to": {
                "type": "string"
              },
              "of": {
                "type": "string"
              },
              "of_label": {
                "type": "string"
              },
              "of_actual": {
                "type": "string"
              },
              "group": {
                "type": "integer"
              },
              "actual": {
                "type": "string"
              },
              "present": {
                "type": "boolean"
              },
              "ok": {
                "type": "boolean"
              }
            }
          }
        },
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      }
    },
    "matched": {
      "type": "boolean"
    },
    "path_id": {
      "type": "string",
      "description": "Какой путь выбран бы на этой записи: yes, id «Если ещё», else; пусто — ни один"
    },
    "branches": {
      "type": "array",
      "description": "Итог условия каждого «Если ещё» по порядку",
      "items": {
        "type": "object",
        "required": [
          "id",
          "condition"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "condition": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    },
    "actions": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "index",
          "command",
          "label",
          "permission",
          "allowed",
          "connected",
          "status",
          "inputs"
        ],
        "properties": {
          "index": {
            "type": "integer"
          },
          "block_id": {
            "type": "string"
          },
          "path_id": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "wait"
            ],
            "description": "Пауза «Подождать»; у действия поля нет"
          },
          "command": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "permission": {
            "type": "string"
          },
          "allowed": {
            "type": "boolean"
          },
          "connected": {
            "type": "boolean"
          },
          "status": {
            "type": "string",
            "enum": [
              "would_run",
              "not_reached",
              "blocked"
            ]
          },
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "inputs": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "key",
                "label",
                "template",
                "value"
              ],
              "properties": {
                "key": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                },
                "template": {
                  "type": "string"
                },
                "value": {
                  "type": "string"
                },
                "missing": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    },
    "problem": {
      "$ref": "#/$defs/AutomationRuleProblem"
    },
    "selection": {
      "type": "object",
      "description": "Отбор записей правила по расписанию (ERP-1939): сколько записей отобрал бы модуль-владелец сегодня под проверяющим, сколько прошли бы «если», пример",
      "required": [
        "key",
        "label",
        "count",
        "matched",
        "truncated",
        "limit",
        "sample"
      ],
      "properties": {
        "key": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "count": {
          "type": "integer"
        },
        "matched": {
          "type": "integer",
          "description": "Сколько записей прошли бы условие и пути"
        },
        "truncated": {
          "type": "boolean",
          "description": "Записей больше limit — за запуск возьмутся первые"
        },
        "limit": {
          "type": "integer"
        },
        "code": {
          "type": "string",
          "description": "Почему отбор не прочитан (automation.reason.<код>)"
        },
        "message": {
          "type": "string"
        },
        "sample": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "entity_id",
              "title",
              "matched",
              "fields"
            ],
            "properties": {
              "entity_id": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "matched": {
                "type": "boolean"
              },
              "fields": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "executed": {
      "type": "boolean",
      "description": "Всегда false: проверка ничего не делает"
    }
  },
  "$defs": {
    "AutomationRuleProblem": {
      "type": "object",
      "required": [
        "field",
        "code",
        "message"
      ],
      "properties": {
        "field": {
          "type": "string",
          "description": "Путь в документе правила: event_type, conditions[1].op, actions[0].inputs.title"
        },
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "hint": {
          "type": "string"
        },
        "params": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "allowed": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    }
  }
}