{
  "type": "object",
  "properties": {
    "schema_version": {
      "const": "1.0.0"
    },
    "task_class": {
      "enum": [
        "orientation",
        "calculation",
        "source_check",
        "shadow_action",
        "write_action",
        "refuse"
      ]
    },
    "object": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "boundary": {
          "type": "string",
          "minLength": 1
        },
        "period": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "boundary",
        "period"
      ],
      "additionalProperties": false
    },
    "claim_layer": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "text": {
            "type": "string",
            "minLength": 1
          },
          "layer": {
            "enum": [
              "invariant",
              "practice",
              "hypothesis_xpower",
              "unknown"
            ]
          },
          "source": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "id",
          "text",
          "layer",
          "source"
        ],
        "additionalProperties": false
      }
    },
    "numbers": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "value": {
            "type": "number"
          },
          "unit": {
            "type": "string",
            "minLength": 1
          },
          "source": {
            "type": "string",
            "minLength": 1
          },
          "date": {
            "type": "string",
            "minLength": 1
          },
          "applies_to_this_object": {
            "enum": [
              "yes",
              "no",
              "unknown"
            ]
          },
          "kind": {
            "enum": [
              "measured",
              "derived",
              "synthetic",
              "assumed"
            ]
          },
          "formula": {
            "type": "string",
            "minLength": 1
          },
          "input_ids": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "required": [
          "id",
          "value",
          "unit",
          "source",
          "date",
          "applies_to_this_object",
          "kind"
        ],
        "additionalProperties": false
      }
    },
    "balance_check": {
      "type": "object",
      "properties": {
        "status": {
          "enum": [
            "passed",
            "failed",
            "not_enough_data",
            "not_applicable"
          ]
        },
        "reason": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "status",
        "reason"
      ],
      "additionalProperties": false
    },
    "double_count_check": {
      "type": "object",
      "properties": {
        "status": {
          "enum": [
            "passed",
            "failed",
            "not_enough_data",
            "not_applicable"
          ]
        },
        "resource_ledger": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "resource": {
                "type": "string",
                "minLength": 1
              },
              "interval": {
                "type": "string",
                "minLength": 1
              },
              "baseline": {
                "type": "string",
                "minLength": 1
              },
              "right": {
                "type": "string",
                "minLength": 1
              },
              "beneficiary": {
                "type": "string",
                "minLength": 1
              },
              "obligation": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "resource",
              "interval",
              "baseline",
              "right",
              "beneficiary",
              "obligation"
            ],
            "additionalProperties": false
          }
        },
        "reason": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "status",
        "resource_ledger",
        "reason"
      ],
      "additionalProperties": false
    },
    "not_claimed": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "stop_conditions": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "action_mode": {
      "type": "object",
      "properties": {
        "mode": {
          "enum": [
            "none",
            "read_only",
            "shadow",
            "limited_write"
          ]
        },
        "authorization": {
          "type": "string",
          "minLength": 1
        },
        "register_map": {
          "type": "string",
          "minLength": 1
        },
        "allowlist": {
          "type": "string",
          "minLength": 1
        },
        "range": {
          "type": "string",
          "minLength": 1
        },
        "expected": {
          "type": "string",
          "minLength": 1
        },
        "timeout": {
          "type": "string",
          "minLength": 1
        },
        "readback": {
          "type": "string",
          "minLength": 1
        },
        "rollback": {
          "type": "string",
          "minLength": 1
        },
        "log": {
          "type": "string",
          "minLength": 1
        },
        "manual_exit": {
          "type": "string",
          "minLength": 1
        },
        "connection_loss": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "mode",
        "authorization"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "mode": {
                "const": "limited_write"
              }
            },
            "required": [
              "mode"
            ]
          },
          "then": {
            "required": [
              "register_map",
              "allowlist",
              "range",
              "expected",
              "timeout",
              "readback",
              "rollback",
              "log",
              "manual_exit",
              "connection_loss"
            ]
          }
        }
      ]
    },
    "three_questions": {
      "type": "object",
      "properties": {
        "physical_change": {
          "type": "string",
          "minLength": 1
        },
        "beneficiary_and_payer": {
          "type": "string",
          "minLength": 1
        },
        "verification_data": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "physical_change",
        "beneficiary_and_payer",
        "verification_data"
      ],
      "additionalProperties": false
    },
    "model_version": {
      "type": "object",
      "properties": {
        "charter": {
          "type": "string",
          "minLength": 1
        },
        "module": {
          "type": "string",
          "minLength": 1
        },
        "calculation": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "charter",
        "module",
        "calculation"
      ],
      "additionalProperties": false
    },
    "confidence": {
      "type": "object",
      "properties": {
        "level": {
          "enum": [
            "low",
            "medium",
            "high"
          ]
        },
        "reason": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "level",
        "reason"
      ],
      "additionalProperties": false
    },
    "human_summary": {
      "type": "string",
      "minLength": 1
    },
    "verifier": {
      "type": "object",
      "properties": {
        "status": {
          "enum": [
            "not_reviewed",
            "returned",
            "passed"
          ]
        },
        "evidence": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "findings": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "required": [
        "status",
        "evidence",
        "findings"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "schema_version",
    "task_class",
    "object",
    "claim_layer",
    "numbers",
    "balance_check",
    "double_count_check",
    "not_claimed",
    "stop_conditions",
    "action_mode",
    "three_questions",
    "model_version",
    "confidence",
    "human_summary",
    "verifier"
  ],
  "additionalProperties": false,
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://x5power.com/Academy/dont-panic/self-check/response.schema.json",
  "title": "Структура ответа агента Академии XPower",
  "description": "Проверка структуры; смысл, источники, физика и полномочия требуют независимой проверки.",
  "allOf": [
    {
      "if": {
        "properties": {
          "task_class": {
            "const": "write_action"
          }
        }
      },
      "then": {
        "properties": {
          "action_mode": {
            "properties": {
              "mode": {
                "const": "limited_write"
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "task_class": {
            "const": "shadow_action"
          }
        }
      },
      "then": {
        "properties": {
          "action_mode": {
            "properties": {
              "mode": {
                "const": "shadow"
              }
            }
          }
        }
      }
    }
  ]
}