{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "StageTrace CLI why 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
    },
    "successData": {
      "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
    }
  },
  "type": "object",
  "required": ["schemaVersion", "command", "status", "data", "errors", "warnings", "timingMs"],
  "properties": {
    "schemaVersion": {"const": "1.0"},
    "command": {"const": "why"},
    "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
}
