{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "StageTrace CLI explain response 1.0",
  "$defs": {
    "probe": {
      "type": "object",
      "required": ["stageId", "targetKind", "primPath", "propertyPath", "timeCode", "loadPolicy", "stageRevision"],
      "properties": {
        "stageId": {"type": "string"},
        "targetKind": {"type": "string", "enum": ["prim", "attribute", "relationship", "missing"]},
        "primPath": {"type": "string"},
        "propertyPath": {"type": "string"},
        "timeCode": {"type": "string"},
        "loadPolicy": {"type": "string", "enum": ["all", "none"]},
        "stageRevision": {"type": "integer", "minimum": 0}
      },
      "additionalProperties": false
    },
    "authoredSample": {
      "type": "object",
      "required": ["sourceTimeCode", "stageTimeCode", "value", "valueType"],
      "properties": {
        "sourceTimeCode": {"type": "string"},
        "stageTimeCode": {"type": "string"},
        "value": {"type": "string"},
        "valueType": {"type": "string"}
      },
      "additionalProperties": false
    },
    "opinion": {
      "type": "object",
      "required": ["layer", "path", "value", "valueType", "isWinner", "role", "sourceKind", "timeCode", "arcType", "authoredSamples"],
      "properties": {
        "layer": {"type": "string"},
        "path": {"type": "string"},
        "value": {"type": "string"},
        "valueType": {"type": "string"},
        "isWinner": {"type": "boolean"},
        "role": {
          "type": "string",
          "enum": ["winner", "composingSource", "weaker", "metadataOnly", "valueBlock", "animationBlock"]
        },
        "sourceKind": {
          "type": "string",
          "enum": ["none", "fallback", "authoredDefault", "timeSamples", "valueClips", "spline"]
        },
        "timeCode": {"type": "string"},
        "arcType": {"type": "string"},
        "authoredSamples": {"type": "array", "items": {"$ref": "#/$defs/authoredSample"}}
      },
      "additionalProperties": false
    },
    "trace": {
      "type": "object",
      "required": ["kind", "layer", "path", "detail"],
      "properties": {
        "kind": {"type": "string"},
        "layer": {"type": "string"},
        "path": {"type": "string"},
        "detail": {"type": "string"}
      },
      "additionalProperties": false
    },
    "safeEditRecommendation": {
      "type": "object",
      "required": ["canEdit", "path", "command", "caveat", "action", "reason"],
      "properties": {
        "canEdit": {"type": "boolean"},
        "path": {"type": "string"},
        "command": {"type": "string"},
        "caveat": {"type": "string"},
        "action": {"type": "string", "enum": ["none", "authorSessionOverride"]},
        "reason": {
          "type": "string",
          "enum": [
            "none",
            "supportedAttributeType",
            "unsupportedAttributeType",
            "relationshipNotEditable",
            "primNotEditable",
            "propertyNotExistingAttribute",
            "primNotFound",
            "payloadUnloaded",
            "noStageOpen"
          ]
        }
      },
      "allOf": [
        {
          "if": {"properties": {"action": {"const": "authorSessionOverride"}}, "required": ["action"]},
          "then": {
            "properties": {
              "canEdit": {"const": true},
              "path": {"type": "string", "minLength": 1},
              "command": {"type": "string", "minLength": 1},
              "reason": {"const": "supportedAttributeType"}
            }
          }
        },
        {
          "if": {"properties": {"action": {"const": "none"}}, "required": ["action"]},
          "then": {
            "properties": {
              "canEdit": {"const": false},
              "path": {"const": ""},
              "command": {"const": ""}
            }
          }
        }
      ],
      "additionalProperties": false
    },
    "highlight": {
      "type": "object",
      "required": ["kind", "path", "layer"],
      "properties": {
        "kind": {"type": "string", "enum": ["property", "winningOpinion", "competingOpinion"]},
        "path": {"type": "string"},
        "layer": {"type": "string"}
      },
      "additionalProperties": false
    },
    "warning": {
      "type": "object",
      "required": ["code", "message"],
      "properties": {
        "code": {
          "type": "string",
          "enum": ["valueClips.sourceSiteLimited", "provenance.sourceSiteUnresolved", "payload.unloaded"]
        },
        "message": {"type": "string"}
      },
      "additionalProperties": false
    },
    "truncation": {
      "type": "object",
      "required": ["truncated", "totalItems", "displayedItems"],
      "properties": {
        "truncated": {"type": "boolean"},
        "totalItems": {"type": "number"},
        "displayedItems": {"type": "number"}
      },
      "additionalProperties": false
    },
    "property": {
      "type": "object",
      "required": [
        "probe",
        "propertyPath",
        "primPath",
        "propertyName",
        "timeCode",
        "hasResolvedValue",
        "resolvedValue",
        "valueType",
        "winner",
        "contributors",
        "sourceKind",
        "valueState",
        "availability",
        "reason",
        "competingOpinions",
        "compositionTrace",
        "safeEditRecommendation",
        "sourceEditCaveat",
        "highlightTargets",
        "warnings",
        "truncation"
      ],
      "properties": {
        "probe": {"$ref": "#/$defs/probe"},
        "propertyPath": {"type": "string"},
        "primPath": {"type": "string"},
        "propertyName": {"type": "string"},
        "timeCode": {"type": "string"},
        "hasResolvedValue": {"type": "boolean"},
        "resolvedValue": {"type": "string"},
        "valueType": {"type": "string"},
        "winner": {"$ref": "#/$defs/opinion"},
        "contributors": {"type": "array", "items": {"$ref": "#/$defs/opinion"}},
        "sourceKind": {
          "type": "string",
          "enum": ["none", "fallback", "authoredDefault", "timeSamples", "valueClips", "spline"]
        },
        "valueState": {"type": "string", "enum": ["resolved", "blocked", "missing", "error"]},
        "availability": {"type": "string", "enum": ["available", "missing", "unloadedPayload"]},
        "reason": {"type": "string"},
        "competingOpinions": {"type": "array", "items": {"$ref": "#/$defs/opinion"}},
        "compositionTrace": {"type": "array", "items": {"$ref": "#/$defs/trace"}},
        "safeEditRecommendation": {"$ref": "#/$defs/safeEditRecommendation"},
        "sourceEditCaveat": {"type": "string"},
        "highlightTargets": {"type": "array", "items": {"$ref": "#/$defs/highlight"}},
        "warnings": {"type": "array", "items": {"$ref": "#/$defs/warning"}},
        "truncation": {"$ref": "#/$defs/truncation"}
      },
      "additionalProperties": false
    },
    "prim": {
      "type": "object",
      "required": ["path", "name", "typeName", "childCount", "isActive", "isLoaded", "hasVariants"],
      "properties": {
        "path": {"type": "string"},
        "name": {"type": "string"},
        "typeName": {"type": "string"},
        "childCount": {"type": "number"},
        "isActive": {"type": "boolean"},
        "isLoaded": {"type": "boolean"},
        "hasVariants": {"type": "boolean"}
      },
      "additionalProperties": false
    },
    "compositionArc": {
      "type": "object",
      "required": ["type", "targetLayer", "targetPath", "introducingLayer", "introducingPath", "isImplicit", "isAncestral", "hasSpecs"],
      "properties": {
        "type": {"type": "string"},
        "targetLayer": {"type": "string"},
        "targetPath": {"type": "string"},
        "introducingLayer": {"type": "string"},
        "introducingPath": {"type": "string"},
        "isImplicit": {"type": "boolean"},
        "isAncestral": {"type": "boolean"},
        "hasSpecs": {"type": "boolean"}
      },
      "additionalProperties": false
    },
    "variantSet": {
      "type": "object",
      "required": ["name", "selection", "options"],
      "properties": {
        "name": {"type": "string"},
        "selection": {"type": "string"},
        "options": {"type": "array", "items": {"type": "string"}}
      },
      "additionalProperties": false
    },
    "composition": {
      "type": "object",
      "required": ["primPath", "arcs", "variantSets"],
      "properties": {
        "primPath": {"type": "string"},
        "arcs": {"type": "array", "items": {"$ref": "#/$defs/compositionArc"}},
        "variantSets": {"type": "array", "items": {"$ref": "#/$defs/variantSet"}}
      },
      "additionalProperties": false
    },
    "visibilityAncestor": {
      "type": "object",
      "required": ["path", "visibility", "active"],
      "properties": {
        "path": {"type": "string"},
        "visibility": {"type": "string"},
        "active": {"type": "boolean"}
      },
      "additionalProperties": false
    },
    "visibility": {
      "type": "object",
      "required": ["probe", "primPath", "authoredVisibility", "computedVisibility", "purpose", "active", "loaded", "ancestorChain", "reason", "blockingOpinion", "safeEditRecommendation", "compositionTrace", "highlightTargets", "warnings"],
      "properties": {
        "probe": {"$ref": "#/$defs/probe"},
        "primPath": {"type": "string"},
        "authoredVisibility": {"type": "string"},
        "computedVisibility": {"type": "string"},
        "purpose": {"type": "string"},
        "active": {"type": "boolean"},
        "loaded": {"type": "boolean"},
        "ancestorChain": {"type": "array", "items": {"$ref": "#/$defs/visibilityAncestor"}},
        "reason": {"type": "string"},
        "blockingOpinion": {"$ref": "#/$defs/opinion"},
        "safeEditRecommendation": {"$ref": "#/$defs/safeEditRecommendation"},
        "compositionTrace": {"type": "array", "items": {"$ref": "#/$defs/trace"}},
        "highlightTargets": {"type": "array", "items": {"$ref": "#/$defs/highlight"}},
        "warnings": {"type": "array", "items": {"$ref": "#/$defs/warning"}}
      },
      "additionalProperties": false
    },
    "layer": {
      "type": "object",
      "required": ["index", "identifier", "realPath", "isAnonymous", "isSessionLayer", "isRootLayer", "isMuted"],
      "properties": {
        "index": {"type": "number"},
        "identifier": {"type": "string"},
        "realPath": {"type": "string"},
        "isAnonymous": {"type": "boolean"},
        "isSessionLayer": {"type": "boolean"},
        "isRootLayer": {"type": "boolean"},
        "isMuted": {"type": "boolean"}
      },
      "additionalProperties": false
    },
    "editability": {
      "type": "object",
      "required": ["editableByCurrentEdit", "propertyKind", "reason", "exampleCommand", "supportedTypes"],
      "properties": {
        "editableByCurrentEdit": {"type": "boolean"},
        "propertyKind": {"type": "string"},
        "reason": {"type": "string"},
        "exampleCommand": {"type": "string"},
        "supportedTypes": {"type": "array", "items": {"type": "string"}}
      },
      "additionalProperties": false
    },
    "successData": {
      "type": "object",
      "required": ["probe", "mode", "timeCode", "prim", "property", "composition", "visibility", "layerStack", "editability", "v1EditScopeNote"],
      "properties": {
        "probe": {"$ref": "#/$defs/probe"},
        "mode": {"type": "string", "enum": ["prim", "property"]},
        "timeCode": {"type": "string"},
        "prim": {"$ref": "#/$defs/prim"},
        "property": {"$ref": "#/$defs/property"},
        "composition": {"$ref": "#/$defs/composition"},
        "visibility": {"$ref": "#/$defs/visibility"},
        "layerStack": {"type": "array", "items": {"$ref": "#/$defs/layer"}},
        "editability": {"$ref": "#/$defs/editability"},
        "v1EditScopeNote": {"type": "string"}
      },
      "additionalProperties": false
    }
  },
  "type": "object",
  "required": ["schemaVersion", "command", "status", "data", "errors", "warnings", "timingMs"],
  "properties": {
    "schemaVersion": {"const": "1.0"},
    "command": {"const": "explain"},
    "status": {"type": "string", "enum": ["ok", "error"]},
    "data": {
      "oneOf": [
        {"$ref": "#/$defs/successData"},
        {"type": "object", "properties": {}, "additionalProperties": false}
      ]
    },
    "errors": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["code", "message"],
        "properties": {
          "code": {"type": "string"},
          "message": {"type": "string"}
        },
        "additionalProperties": false
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["code", "message"],
        "properties": {
          "code": {"type": "string"},
          "message": {"type": "string"}
        },
        "additionalProperties": false
      }
    },
    "timingMs": {"type": "number"}
  },
  "allOf": [
    {
      "if": {"properties": {"status": {"const": "ok"}}, "required": ["status"]},
      "then": {
        "properties": {
          "data": {"$ref": "#/$defs/successData"},
          "errors": {"type": "array", "maxItems": 0}
        }
      }
    },
    {
      "if": {"properties": {"status": {"const": "error"}}, "required": ["status"]},
      "then": {
        "properties": {
          "data": {"type": "object", "properties": {}, "additionalProperties": false},
          "errors": {"type": "array", "minItems": 1}
        }
      }
    }
  ],
  "additionalProperties": false
}
