{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://smallyunet.github.io/echosvm/schemas/echosvm.evidence.v1.schema.json",
  "title": "EchoSVM deterministic causal evidence",
  "type": "object",
  "required": [
    "schema",
    "caseId",
    "title",
    "verdict",
    "rootCause",
    "propagation",
    "rollbacks",
    "compute",
    "selection"
  ],
  "properties": {
    "schema": { "const": "echosvm.evidence.v1" },
    "caseId": { "type": "string" },
    "title": { "type": "string" },
    "verdict": {
      "type": "object",
      "required": ["status", "summary"],
      "properties": {
        "status": { "enum": ["succeeded", "failed"] },
        "summary": { "type": "string" }
      }
    },
    "rootCause": {
      "type": "object",
      "required": [
        "violationId",
        "frameId",
        "frameLabel",
        "programId",
        "kind",
        "kindLabel",
        "summary",
        "expected",
        "actual",
        "evidence"
      ],
      "properties": {
        "violationId": { "type": "string" },
        "frameId": { "type": "string" },
        "frameLabel": { "type": "string" },
        "programId": { "type": "string" },
        "kind": { "type": "string" },
        "kindLabel": { "type": "string" },
        "account": { "type": ["string", "null"] },
        "summary": { "type": "string" },
        "expected": { "type": "string" },
        "actual": { "type": "string" },
        "evidence": { "type": "array", "items": { "type": "string" } }
      }
    },
    "propagation": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["frameId", "frameLabel", "programId", "depth", "error"],
        "properties": {
          "frameId": { "type": "string" },
          "frameLabel": { "type": "string" },
          "programId": { "type": "string" },
          "depth": { "type": "integer" },
          "error": { "type": "string" }
        }
      }
    },
    "rollbacks": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "account",
          "accountLabel",
          "field",
          "before",
          "tentative",
          "after"
        ],
        "properties": {
          "account": { "type": "string" },
          "accountLabel": { "type": "string" },
          "field": { "type": "string" },
          "before": { "type": "string" },
          "tentative": { "type": "string" },
          "after": { "type": "string" }
        }
      }
    },
    "compute": {
      "type": "object",
      "required": ["budget", "consumed", "remaining", "frames"],
      "properties": {
        "budget": { "type": "integer" },
        "consumed": { "type": "integer" },
        "remaining": { "type": "integer" },
        "frames": { "type": "array" }
      }
    },
    "selection": {
      "type": "object",
      "required": [
        "profile",
        "sourceViolations",
        "selectedViolations",
        "deterministic",
        "rule"
      ],
      "properties": {
        "profile": { "enum": ["failure", "accounts", "cpi", "compute", "full"] },
        "sourceViolations": { "type": "integer" },
        "selectedViolations": { "type": "integer" },
        "deterministic": { "const": true },
        "rule": { "type": "string" }
      }
    }
  }
}
