{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://re3val.com/schema/ew-registry.schema.json",
  "title": "Re3val registry",
  "description": "Registry snapshot v0.4.0. Immutable bulk view of separately stored record versions and a versioned definition; never append in place. Each public record has a payload hash and is bound to a signed release manifest. Current state is projected from canonical events and both time axes. Semantic validator checks vocabulary, source references and within-snapshot lineage; cross-release history and signatures require the release verifier. v0.4.0: records are dated statements warranted as of verified_at; registries carry an update intent, never a service level, stale rule or review date.",
  "type": "object",
  "required": [
    "schema_version",
    "definition",
    "records",
    "agent_authority"
  ],
  "properties": {
    "schema_version": {
      "const": "0.4.0"
    },
    "definition": {
      "$ref": "#/$defs/registry_definition"
    },
    "records": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/registry_record"
      }
    },
    "sources": {
      "type": "array",
      "items": {
        "$ref": "https://re3val.com/schema/ew-article.schema.json#/$defs/source"
      }
    },
    "content_hash": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "signature": {
      "anyOf": [
        {
          "$ref": "https://re3val.com/schema/ew-article.schema.json#/$defs/signature"
        },
        {
          "type": "null"
        }
      ]
    },
    "agent_authority": {
      "const": "none"
    }
  },
  "$defs": {
    "registry_definition": {
      "type": "object",
      "required": [
        "registry_id",
        "name",
        "version",
        "owner",
        "population",
        "status_vocabulary",
        "update_intent",
        "completeness_target",
        "retirement_path",
        "landscape"
      ],
      "properties": {
        "registry_id": {
          "type": "string",
          "pattern": "^ewreg-[a-z0-9-]+$"
        },
        "name": {
          "type": "string"
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "owner": {
          "type": [
            "string",
            "null"
          ],
          "description": "Null only pre-launch; a registry MUST NOT go live unowned."
        },
        "population": {
          "type": "string",
          "description": "Declared, auditable population; completeness is measured against this statement."
        },
        "jurisdictions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "status_vocabulary": {
          "type": "array",
          "minItems": 2,
          "items": {
            "type": "object",
            "required": [
              "status",
              "meaning"
            ],
            "properties": {
              "status": {
                "type": "string"
              },
              "meaning": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "update_intent": {
          "enum": [
            "none",
            "discretionary",
            "observed"
          ],
          "description": "none: published once, never updated. discretionary: updated when the editor chooses. observed: cited sources are re-fetched on observation_schedule and source changes are published as status observations; updates remain discretionary. No value creates an obligation to update (ew-workflows.md §0.2)."
        },
        "observation_schedule": {
          "type": [
            "string",
            "null"
          ],
          "description": "Declared re-fetch cadence when update_intent is observed; a measurement schedule, not a service level."
        },
        "completeness_target": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "retirement_path": {
          "type": "string"
        },
        "landscape": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "infrastructure",
              "stance"
            ],
            "properties": {
              "infrastructure": {
                "type": "string"
              },
              "stance": {
                "enum": [
                  "consume",
                  "link",
                  "validate",
                  "augment",
                  "fill_gap"
                ]
              },
              "note": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "maintenance_budget_note": {
          "type": [
            "string",
            "null"
          ],
          "description": "Cost note for observation and correction capacity; no maintenance obligation is implied."
        }
      },
      "additionalProperties": false
    },
    "registry_record": {
      "type": "object",
      "required": [
        "fact_id",
        "record_id",
        "entity",
        "statement",
        "status",
        "valid_from",
        "observed_at",
        "verified_at",
        "verification_level",
        "epistemic_status",
        "publication_state",
        "oversight",
        "evidence_grade",
        "source_ids",
        "agent_authority",
        "supersedes",
        "valid_until",
        "content_hash"
      ],
      "properties": {
        "fact_id": {
          "type": "string",
          "pattern": "^ewf-[a-z0-9-]+$",
          "description": "STABLE identity of the fact across all its versions — what an agent cites when it means 'this fact, whatever its current state'. Never changes on supersession."
        },
        "record_id": {
          "type": "string",
          "pattern": "^ewr-[a-z0-9-]+-v[0-9]+$",
          "description": "IMMUTABLE identity of this version of the fact. A new state means a new record_id; supersedes chains versions of the same fact_id."
        },
        "entity": {
          "type": "object",
          "required": [
            "name",
            "entity_type"
          ],
          "properties": {
            "name": {
              "type": "string"
            },
            "entity_type": {
              "type": "string"
            },
            "wikidata_qid": {
              "type": [
                "string",
                "null"
              ]
            },
            "native_id": {
              "type": [
                "string",
                "null"
              ]
            },
            "entity_note": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          "additionalProperties": false
        },
        "statement": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "description": "MUST be a status from the registry definition's status_vocabulary."
        },
        "valid_from": {
          "type": "string",
          "format": "date-time"
        },
        "valid_until": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "effective_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "observed_at": {
          "type": "string",
          "format": "date-time"
        },
        "verified_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "The moment this version's statement is warranted for; it claims nothing about any later moment. Required on publication."
        },
        "published_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "supersedes": {
          "type": [
            "string",
            "null"
          ],
          "description": "record_id of the prior version of the same fact_id."
        },
        "jurisdiction": {
          "type": [
            "string",
            "null"
          ]
        },
        "verification_level": {
          "$ref": "https://re3val.com/schema/ew-article.schema.json#/$defs/verification_level"
        },
        "epistemic_status": {
          "$ref": "https://re3val.com/schema/ew-article.schema.json#/$defs/epistemic_status"
        },
        "publication_state": {
          "enum": [
            "draft",
            "published",
            "corrected",
            "retracted"
          ]
        },
        "oversight": {
          "$ref": "https://re3val.com/schema/ew-article.schema.json#/$defs/oversight"
        },
        "evidence_grade": {
          "$ref": "https://re3val.com/schema/ew-article.schema.json#/$defs/evidence_grade"
        },
        "source_ids": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "claim_ids": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Global-form claim IDs (article_id#Cn) backing or citing this record."
        },
        "change_observed_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "When the change this version records was observed, if it was observed by source monitoring. A measurement for honest lag reporting, not a service-level clock."
        },
        "note": {
          "type": [
            "string",
            "null"
          ]
        },
        "agent_authority": {
          "const": "none"
        },
        "content_hash": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "publication_state": {
                "enum": [
                  "published",
                  "corrected",
                  "retracted"
                ]
              }
            }
          },
          "then": {
            "required": [
              "published_at",
              "content_hash",
              "verified_at"
            ],
            "properties": {
              "published_at": {
                "type": "string",
                "format": "date-time"
              },
              "content_hash": {
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$"
              },
              "verification_level": {
                "enum": [
                  "link_verified",
                  "corroborated"
                ]
              },
              "verified_at": {
                "type": "string",
                "format": "date-time"
              },
              "oversight": {
                "properties": {
                  "verification_mode": {
                    "enum": [
                      "machine_verified",
                      "machine_verified_human_reviewed"
                    ]
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "verification_level": {
                "const": "unverified_pilot"
              }
            }
          },
          "then": {
            "properties": {
              "publication_state": {
                "const": "draft"
              },
              "evidence_grade": {
                "enum": [
                  "D",
                  "E"
                ]
              }
            }
          }
        }
      ],
      "additionalProperties": false
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "records": {
            "contains": {
              "properties": {
                "publication_state": {
                  "enum": [
                    "published",
                    "corrected",
                    "retracted"
                  ]
                }
              },
              "required": [
                "publication_state"
              ]
            }
          }
        }
      },
      "then": {
        "required": [
          "content_hash",
          "signature",
          "sources"
        ],
        "properties": {
          "content_hash": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          },
          "signature": {
            "$ref": "https://re3val.com/schema/ew-article.schema.json#/$defs/signature"
          },
          "definition": {
            "properties": {
              "owner": {
                "type": "string",
                "minLength": 1
              },
              "maintenance_budget_note": {
                "type": "string",
                "minLength": 1
              },
              "landscape": {
                "minItems": 1
              }
            },
            "required": [
              "maintenance_budget_note"
            ]
          }
        }
      }
    }
  ],
  "additionalProperties": false
}
