{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://varexis.tech/schemas/index-record-v1.json",
  "title": "VAREXIS INDEX Evidence Record v1",
  "description": "Corpus record. Record lifecycle state is separate from query-time reliance. No numeric master score exists.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "record_id",
    "record_state",
    "origin",
    "subject",
    "claim",
    "capability",
    "workload",
    "environment",
    "evidence_strength",
    "correctness",
    "economics",
    "negative_evidence",
    "evidence_pack_ids",
    "revalidation",
    "timestamps"
  ],
  "properties": {
    "record_id": {
      "type": "string",
      "minLength": 1
    },
    "record_state": {
      "type": "string",
      "enum": [
        "DISCOVERED",
        "SOURCE_BOUND",
        "VALIDATED",
        "INDEXED",
        "CHALLENGED",
        "SUPERSEDED",
        "WITHDRAWN"
      ]
    },
    "origin": {
      "$ref": "#/$defs/origin"
    },
    "subject": {
      "$ref": "#/$defs/subject"
    },
    "claim": {
      "$ref": "#/$defs/claim"
    },
    "capability": {
      "type": "string",
      "minLength": 1
    },
    "workload": {
      "$ref": "#/$defs/workload"
    },
    "environment": {
      "$ref": "#/$defs/environment"
    },
    "evidence_strength": {
      "$ref": "#/$defs/evidenceStrength"
    },
    "correctness": {
      "$ref": "#/$defs/evidenceDimension"
    },
    "economics": {
      "$ref": "#/$defs/evidenceDimension"
    },
    "negative_evidence": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/negativeEvidence"
      }
    },
    "evidence_pack_ids": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "revalidation": {
      "$ref": "#/$defs/revalidation"
    },
    "timestamps": {
      "$ref": "#/$defs/timestamps"
    }
  },
  "$defs": {
    "missingness": {
      "type": "string",
      "enum": [
        "OBSERVED",
        "REPORTED",
        "DERIVED",
        "NOT_REPORTED",
        "NOT_APPLICABLE"
      ]
    },
    "basis": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "uniqueItems": true
    },
    "datum": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "value",
        "basis"
      ],
      "properties": {
        "status": {
          "$ref": "#/$defs/missingness"
        },
        "value": {
          "type": [
            "string",
            "number",
            "integer",
            "boolean",
            "null"
          ]
        },
        "basis": {
          "$ref": "#/$defs/basis"
        }
      }
    },
    "origin": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_class",
        "source_ref",
        "custody"
      ],
      "properties": {
        "source_class": {
          "type": "string",
          "enum": [
            "VAREXIS_ISAMBARD_EVIDENCE",
            "DEFINED_BOT_HARNESS",
            "EXTERNAL_PRIMARY_RESEARCH",
            "EXTERNAL_TECHNICAL_REPORT",
            "PARTNER_CUSTOMER_EVIDENCE",
            "INDEPENDENT_REPLICATION"
          ]
        },
        "source_ref": {
          "type": "string",
          "minLength": 1
        },
        "custody": {
          "type": "string",
          "enum": [
            "FIRST_PARTY",
            "THIRD_PARTY",
            "MIXED"
          ]
        }
      }
    },
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "version"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "$ref": "#/$defs/datum"
        }
      }
    },
    "claim": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "claim_id",
        "text",
        "claim_type"
      ],
      "properties": {
        "claim_id": {
          "type": "string",
          "minLength": 1
        },
        "text": {
          "type": "string",
          "minLength": 1
        },
        "claim_type": {
          "type": "string",
          "enum": [
            "CORRECTNESS",
            "ECONOMICS",
            "SAFETY",
            "CAPABILITY",
            "BOUNDARY",
            "OTHER"
          ]
        }
      }
    },
    "volume": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "unit"
      ],
      "properties": {
        "value": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "unit": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "workload": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "stream_type",
        "volume",
        "required_events"
      ],
      "properties": {
        "stream_type": {
          "type": "string",
          "minLength": 1
        },
        "volume": {
          "anyOf": [
            {
              "$ref": "#/$defs/volume"
            },
            {
              "type": "null"
            }
          ]
        },
        "required_events": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        }
      }
    },
    "environment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "hardware_class",
        "software_version",
        "input_distribution",
        "input_contract",
        "dependencies"
      ],
      "properties": {
        "hardware_class": {
          "$ref": "#/$defs/datum"
        },
        "software_version": {
          "$ref": "#/$defs/datum"
        },
        "input_distribution": {
          "$ref": "#/$defs/datum"
        },
        "input_contract": {
          "$ref": "#/$defs/datum"
        },
        "dependencies": {
          "$ref": "#/$defs/datum"
        }
      }
    },
    "evidenceVectorMember": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "value",
        "basis"
      ],
      "properties": {
        "status": {
          "$ref": "#/$defs/missingness"
        },
        "value": {
          "type": [
            "string",
            "null"
          ]
        },
        "basis": {
          "$ref": "#/$defs/basis"
        }
      }
    },
    "queryTimeVectorMember": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "query_time_only",
        "status",
        "value",
        "basis"
      ],
      "properties": {
        "query_time_only": {
          "const": true
        },
        "status": {
          "const": "NOT_APPLICABLE"
        },
        "value": {
          "type": "null"
        },
        "basis": {
          "type": "array",
          "maxItems": 0
        }
      }
    },
    "evidenceStrength": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "origin",
        "source_integrity",
        "independence",
        "replication",
        "holdout_status",
        "freshness",
        "conflict_state",
        "environment_match",
        "workload_match"
      ],
      "properties": {
        "origin": {
          "$ref": "#/$defs/evidenceVectorMember"
        },
        "source_integrity": {
          "$ref": "#/$defs/evidenceVectorMember"
        },
        "independence": {
          "$ref": "#/$defs/evidenceVectorMember"
        },
        "replication": {
          "$ref": "#/$defs/evidenceVectorMember"
        },
        "holdout_status": {
          "$ref": "#/$defs/evidenceVectorMember"
        },
        "freshness": {
          "$ref": "#/$defs/evidenceVectorMember"
        },
        "conflict_state": {
          "$ref": "#/$defs/evidenceVectorMember"
        },
        "environment_match": {
          "$ref": "#/$defs/queryTimeVectorMember"
        },
        "workload_match": {
          "$ref": "#/$defs/queryTimeVectorMember"
        }
      }
    },
    "metric": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "status",
        "value",
        "unit",
        "basis"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "$ref": "#/$defs/missingness"
        },
        "value": {
          "type": [
            "number",
            "integer",
            "string",
            "boolean",
            "null"
          ]
        },
        "unit": {
          "type": [
            "string",
            "null"
          ]
        },
        "basis": {
          "$ref": "#/$defs/basis"
        }
      }
    },
    "evidenceDimension": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "summary",
        "metrics",
        "basis"
      ],
      "properties": {
        "status": {
          "$ref": "#/$defs/missingness"
        },
        "summary": {
          "type": [
            "string",
            "null"
          ]
        },
        "metrics": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/metric"
          }
        },
        "basis": {
          "$ref": "#/$defs/basis"
        }
      }
    },
    "negativeEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "summary",
        "basis"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "MISSED_REQUIRED_EVENT",
            "SAFETY_FAILURE",
            "ABORT",
            "SAFE_REFUSAL",
            "ECONOMIC_FAILURE",
            "CONFLICTING_EVIDENCE",
            "REVALIDATION_REQUIRED",
            "SUCCESS_EVIDENCE"
          ]
        },
        "summary": {
          "type": "string",
          "minLength": 1
        },
        "basis": {
          "$ref": "#/$defs/basis"
        }
      }
    },
    "revalidation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "required",
        "triggers"
      ],
      "properties": {
        "required": {
          "type": "boolean"
        },
        "triggers": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "hardware_class_changed",
              "software_version_changed",
              "workload_distribution_changed",
              "input_contract_changed",
              "dependency_changed",
              "new_conflicting_evidence"
            ]
          },
          "uniqueItems": true
        }
      }
    },
    "timestamps": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "observed_at",
        "indexed_at",
        "reviewed_at",
        "expires_at"
      ],
      "properties": {
        "observed_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "indexed_at": {
          "type": "string",
          "format": "date-time"
        },
        "reviewed_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "expires_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      }
    }
  }
}
