{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Secure Autonomous evidence object, schema v0.4",
  "type": "object",
  "required": ["schema_version", "id", "title", "family", "context", "actor_status", "provenance_tier", "status", "outcome", "fields", "controls", "sources", "corrections", "created", "last_reviewed"],
  "properties": {
    "schema_version": {"const": "0.4"},
    "id": {"type": "string", "pattern": "^REG-[0-9]{4}$"},
    "title": {"type": "string", "minLength": 10},
    "batch": {"type": "string"},
    "family": {"enum": ["physical", "software", "transaction", "bridge", "boundary"]},
    "context": {
      "type": "object",
      "required": ["domain", "autonomy_level", "actor_type", "actors", "mandate_context", "jurisdiction"],
      "properties": {
        "domain": {"type": "string"},
        "autonomy_level": {"enum": ["assists", "supervised", "alone", "coordinating"]},
        "actor_type": {"type": "string"},
        "actors": {"type": "object", "properties": {"count": {"type": ["integer", "null"]}, "text": {"type": "string"}, "roles": {"type": "array", "items": {"enum": ["defender", "adversary", "supervisor"]}}}},
        "mandate_context": {"enum": ["production", "test", "demonstration", "adversarial"]},
        "jurisdiction": {"type": "array", "items": {"type": "string"}}
      }
    },
    "actor_status": {"enum": ["confirmed", "alleged", "unverified", "none_found", "vendor_attributed"]},
    "provenance_tier": {"enum": ["public_regulatory", "disclosure_corroborated", "disclosure_uncorroborated", "affected_party", "single_source", "contributed", "derived"]},
    "status": {"enum": ["confirmed", "provisional", "pending"]},
    "outcome": {
      "type": "object",
      "required": ["state", "as_of"],
      "properties": {
        "state": {"enum": ["harm", "averted_by_control", "averted_by_disclosure", "blocked", "pending"]},
        "severity": {"type": "string"}, "affected_parties": {"type": "array"}, "cost": {"type": "string"},
        "regime_consequence": {"type": "string"}, "as_of": {"type": "string", "minLength": 4}
      }
    },
    "fields": {
      "type": "array", "minItems": 5,
      "items": {
        "type": "object",
        "required": ["layer", "value", "assertion_type", "source_ids", "confidence"],
        "properties": {
          "layer": {"enum": ["Mandate", "Actor", "Inputs", "Decision", "Envelope", "Action", "Outcome", "Evidence", "Recovery"]},
          "facet": {"type": ["string", "null"]},
          "value": {"type": "string", "minLength": 1},
          "assertion_type": {"enum": ["fact", "assertion", "interpretation", "inference"]},
          "source_ids": {"type": "array", "minItems": 1, "items": {"type": "string"}},
          "confidence": {"enum": ["high", "medium", "low"]},
          "disputed": {"type": "boolean"}
        }
      }
    },
    "inference": {"type": "object", "properties": {"value": {"type": ["string", "null"]}, "signed_by": {"type": ["string", "null"]}, "signed_on": {"type": ["string", "null"]}}},
    "controls": {
      "type": "object", "required": ["failed", "succeeded", "absent"],
      "properties": {
        "failed": {"$ref": "#/$defs/controlList"}, "succeeded": {"$ref": "#/$defs/controlList"}, "absent": {"$ref": "#/$defs/controlList"}
      }
    },
    "applicable_rules": {"type": "array", "items": {"type": "string"}},
    "unmapped": {"type": "array", "items": {"type": "string"}},
    "named_parties": {"type": "array", "items": {"type": "object", "required": ["name", "right_of_reply"], "properties": {"name": {"type": "string"}, "right_of_reply": {"type": "object", "properties": {"offered": {"type": ["string", "null"]}, "response": {"type": ["string", "null"]}}}}}},
    "sources": {
      "type": "object",
      "additionalProperties": {"type": "object", "required": ["title", "type", "tier"], "properties": {
        "title": {"type": "string"},
        "type": {"enum": ["regulator", "court", "standards_body", "company", "researcher", "reproduction", "public_record", "press_pointer", "self_report", "police_via_press"]},
        "url": {"type": ["string", "null"]}, "date": {"type": ["string", "null"]}, "tier": {"type": "string"}, "interest": {"type": ["string", "null"]}
      }}
    },
    "corrections": {"type": "array", "items": {"type": "object", "required": ["date", "field", "old", "new", "reason"]}},
    "created": {"type": "string"}, "last_reviewed": {"type": "string"}, "reviewed_by": {"type": ["string", "null"]}
  },
  "$defs": {
    "controlList": {"type": "array", "items": {"type": "object", "properties": {"id": {"type": ["string", "null"], "pattern": "^C-[A-Z][0-9]$"}, "note": {"type": "string"}, "candidate": {"type": "string"}}}}
  }
}
