{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "synthetic",
    "package_id",
    "parent_package_id",
    "created_at",
    "subject",
    "reviewer",
    "rubric",
    "rights",
    "outcome",
    "scenarios",
    "artifacts"
  ],
  "properties": {
    "schema_version": {
      "const": "ixo-expert-review-draft-1"
    },
    "synthetic": {
      "type": "boolean"
    },
    "package_id": {
      "type": "string",
      "minLength": 1
    },
    "parent_package_id": {
      "anyOf": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "null"
        }
      ]
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tenant_id",
        "agent_id",
        "review_order_id",
        "agent_version",
        "release_manifest_artifact_id"
      ],
      "properties": {
        "tenant_id": {
          "type": "string",
          "minLength": 1
        },
        "agent_id": {
          "type": "string",
          "minLength": 1
        },
        "review_order_id": {
          "type": "string",
          "minLength": 1
        },
        "agent_version": {
          "type": "string",
          "minLength": 1
        },
        "release_manifest_artifact_id": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "reviewer": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "identity_ref",
        "competence_check_ref",
        "scope",
        "endorsement_ref"
      ],
      "properties": {
        "identity_ref": {
          "type": "string",
          "minLength": 1
        },
        "competence_check_ref": {
          "type": "string",
          "minLength": 1
        },
        "scope": {
          "type": "string",
          "minLength": 1
        },
        "endorsement_ref": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "rubric": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "version",
        "artifact_id"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "artifact_id": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "rights": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "agreement_artifact_id",
        "agent_id",
        "allowed_uses",
        "allowed_processors",
        "model_weight_training",
        "expires_at",
        "retention_days"
      ],
      "properties": {
        "agreement_artifact_id": {
          "type": "string",
          "minLength": 1
        },
        "agent_id": {
          "type": "string",
          "minLength": 1
        },
        "allowed_uses": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "allowed_processors": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "model_weight_training": {
          "type": "boolean"
        },
        "expires_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ]
        },
        "retention_days": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "outcome": {
      "enum": [
        "issues_found",
        "no_issues_observed",
        "inconclusive"
      ]
    },
    "scenarios": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/scenario"
      }
    },
    "artifacts": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/artifact"
      }
    }
  },
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Proposed IXO Expert Reviews package",
  "description": "Application draft, not a canonical IXO protocol schema. Shape validation does not verify authenticity, endorsement, rights, or truth. Signature/receipt bindings are detached to avoid self-referential manifest hashing.",
  "$defs": {
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "path",
        "sha256",
        "media_type"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "path": {
          "type": "string",
          "minLength": 1
        },
        "sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "media_type": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "scenario": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "family_id",
        "user_context",
        "input_artifact_id",
        "trace_artifact_id",
        "preconditions",
        "finding",
        "criteria"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "family_id": {
          "type": "string",
          "minLength": 1
        },
        "user_context": {
          "type": "string",
          "minLength": 1
        },
        "input_artifact_id": {
          "type": "string",
          "minLength": 1
        },
        "trace_artifact_id": {
          "type": "string",
          "minLength": 1
        },
        "preconditions": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "finding": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "id",
            "evidence_locator",
            "observation",
            "severity",
            "rationale",
            "recommended_change"
          ],
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "evidence_locator": {
              "type": "string",
              "minLength": 1
            },
            "observation": {
              "type": "string",
              "minLength": 1
            },
            "severity": {
              "enum": [
                "critical",
                "major",
                "minor"
              ]
            },
            "rationale": {
              "type": "string",
              "minLength": 1
            },
            "recommended_change": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "criteria": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/criterion"
          }
        }
      }
    },
    "criterion": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "expectation",
        "mode",
        "critical",
        "reviewer_approval_ref"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "expectation": {
          "type": "string",
          "minLength": 1
        },
        "mode": {
          "enum": [
            "deterministic",
            "rubric_judge",
            "human"
          ]
        },
        "critical": {
          "type": "boolean"
        },
        "reviewer_approval_ref": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        }
      }
    }
  }
}
