{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/akeda-ru/json-schema/akeda-ru-automation-rule-simulation-schema.json",
  "title": "AutomationRuleSimulation",
  "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/AutomationRuleSimulation",
  "type": "object",
  "required": [
    "days",
    "since",
    "events",
    "fired",
    "truncated",
    "max_per_day",
    "records",
    "actions",
    "executed"
  ],
  "properties": {
    "days": {
      "type": "integer"
    },
    "since": {
      "type": "string",
      "format": "date-time"
    },
    "events": {
      "type": "integer",
      "description": "Фактов события за период, видимых вызывающему"
    },
    "fired": {
      "type": "integer",
      "description": "Сколько раз правило сработало бы"
    },
    "truncated": {
      "type": "boolean",
      "description": "Учтены только последние 2000 фактов периода"
    },
    "max_per_day": {
      "type": "integer",
      "description": "Больше всего срабатываний за один день"
    },
    "records": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "key",
          "entity_id",
          "occurred_at"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "entity_id": {
            "type": "string"
          },
          "title": {
            "type": "string",
            "description": "Номер, идентификатор или тема записи"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "path_id": {
            "type": "string",
            "description": "Каким путём пошёл бы факт"
          }
        }
      }
    },
    "paths": {
      "type": "array",
      "description": "У правила с ветками — сколько фактов пошло бы каждым путём",
      "items": {
        "type": "object",
        "required": [
          "id",
          "count"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "count": {
            "type": "integer"
          }
        }
      }
    },
    "actions": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "index",
          "command",
          "label",
          "permission",
          "allowed",
          "connected",
          "count"
        ],
        "properties": {
          "index": {
            "type": "integer"
          },
          "block_id": {
            "type": "string"
          },
          "path_id": {
            "type": "string"
          },
          "command": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "permission": {
            "type": "string"
          },
          "allowed": {
            "type": "boolean"
          },
          "connected": {
            "type": "boolean"
          },
          "count": {
            "type": "integer",
            "description": "Сколько раз действие выполнилось бы; 0 — его заблокировали права или нет исполнителя"
          },
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      }
    },
    "before": {
      "type": "object",
      "required": [
        "enabled",
        "version",
        "fired"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "version": {
          "type": "integer"
        },
        "fired": {
          "type": "integer",
          "description": "Сколько раз сработала бы сохранённая версия; выключенное правило — 0"
        }
      }
    },
    "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: прогон ничего не исполняет"
    }
  }
}