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