{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://smallyunet.github.io/echosvm/schemas/echosvm.case.v1.schema.json",
  "title": "EchoSVM captured execution case",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "caseId", "title", "execution", "frames", "violations"],
  "properties": {
    "schema": { "const": "echosvm.case.v1" },
    "caseId": { "type": "string", "minLength": 1 },
    "title": { "type": "string", "minLength": 1 },
    "description": { "type": "string" },
    "execution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "computeBudget", "computeConsumed"],
      "properties": {
        "status": { "const": "failed" },
        "computeBudget": { "type": "integer", "minimum": 0 },
        "computeConsumed": { "type": "integer", "minimum": 0 },
        "runtime": {
          "type": "object",
          "additionalProperties": false,
          "required": ["engine"],
          "properties": {
            "engine": { "type": "string" },
            "version": { "type": "string" },
            "featureSet": { "type": "string" }
          }
        }
      }
    },
    "frames": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "depth",
          "sequence",
          "programId",
          "label",
          "status",
          "computeUnits"
        ],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "parentId": { "type": ["string", "null"] },
          "depth": { "type": "integer", "minimum": 0 },
          "sequence": { "type": "integer", "minimum": 0 },
          "programId": { "type": "string", "minLength": 1 },
          "label": { "type": "string", "minLength": 1 },
          "status": { "enum": ["succeeded", "failed"] },
          "computeUnits": { "type": "integer", "minimum": 0 },
          "error": { "type": ["string", "null"] }
        }
      }
    },
    "accounts": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["address", "label", "signer", "writable", "owner"],
        "properties": {
          "address": { "type": "string", "minLength": 1 },
          "label": { "type": "string", "minLength": 1 },
          "signer": { "type": "boolean" },
          "writable": { "type": "boolean" },
          "owner": { "type": "string", "minLength": 1 },
          "changes": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["field", "before", "tentative", "after"],
              "properties": {
                "field": { "type": "string", "minLength": 1 },
                "before": { "type": "string" },
                "tentative": { "type": "string" },
                "after": { "type": "string" }
              }
            }
          }
        }
      }
    },
    "violations": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "frameId",
          "sequence",
          "kind",
          "summary",
          "expected",
          "actual"
        ],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "frameId": { "type": "string", "minLength": 1 },
          "sequence": { "type": "integer", "minimum": 0 },
          "kind": {
            "enum": [
              "signer-privilege",
              "writable-privilege",
              "pda-derivation",
              "account-owner",
              "account-data",
              "borrow-conflict",
              "compute-budget",
              "program-error"
            ]
          },
          "account": { "type": ["string", "null"] },
          "summary": { "type": "string", "minLength": 1 },
          "expected": { "type": "string" },
          "actual": { "type": "string" },
          "evidence": {
            "type": "array",
            "items": { "type": "string" }
          }
        }
      }
    }
  }
}
