{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "nt-cover-scenario.v0.schema.json",
  "title": "Neverthought cover scenario v0",
  "description": "Declared cover terms and the reliance and consequence records evaluated against them: insured event = F(C, R_C, P, T) and a defined loss. Parties are opaque references, never identities.",
  "$defs": {
    "ref": { "type": "object", "additionalProperties": false, "required": ["proposal_id", "record_time"],
      "properties": { "proposal_id": { "type": "string" }, "record_time": { "type": "string", "format": "date-time" } } },
    "opaque": { "type": "string", "pattern": "^party:ref-[0-9a-z]+$" }
  },
  "type": "object",
  "additionalProperties": false,
  "required": ["scenario_version", "scenario_id", "title", "synthetic", "terms", "readjudications", "reliance", "consequences"],
  "properties": {
    "scenario_version": { "const": "nt-cover-scenario:v0" },
    "scenario_id": { "type": "string" },
    "title": { "type": "string" },
    "synthetic": { "const": true },
    "terms": {
      "type": "object", "additionalProperties": false,
      "required": ["terms_id", "purpose", "failing_effects", "window_end", "loss_definition"],
      "properties": {
        "terms_id": { "type": "string" },
        "purpose": { "type": "string", "minLength": 1 },
        "failing_effects": { "type": "array", "minItems": 1, "items": { "enum": ["PRESERVED", "STRENGTHENED", "WEAKENED", "DEFEATED", "NEW", "UNRESOLVED"] } },
        "window_end": { "type": "string", "format": "date-time" },
        "loss_definition": { "type": "object", "additionalProperties": false, "required": ["min_loss_minor", "currency", "requires_causal_link"],
          "properties": { "min_loss_minor": { "type": "integer", "minimum": 0 }, "currency": { "type": "string", "pattern": "^[A-Z]{3}$" }, "requires_causal_link": { "type": "boolean" } } }
      }
    },
    "readjudications": { "type": "array", "items": { "$ref": "#/$defs/ref" } },
    "reliance": { "type": "array", "items": { "type": "object", "additionalProperties": false,
      "required": ["reliance_id", "relied_on", "relied_by", "purpose", "relied_at"],
      "properties": { "reliance_id": { "type": "string" }, "relied_on": { "$ref": "#/$defs/ref" }, "relied_by": { "$ref": "#/$defs/opaque" },
        "purpose": { "type": "string" }, "relied_at": { "type": "string", "format": "date-time" } } } },
    "consequences": { "type": "array", "items": { "type": "object", "additionalProperties": false,
      "required": ["consequence_id", "reliance_id", "proposal_id", "observed_at", "description", "path", "independent", "loss_status", "supersedes", "loss_minor", "currency", "causal_link"],
      "properties": {
        "consequence_id": { "type": "string" }, "reliance_id": { "type": ["string", "null"] }, "proposal_id": { "type": ["string", "null"] },
        "observed_at": { "type": "string", "format": "date-time" }, "description": { "type": "string" },
        "path": { "description": "Declared consequence path followed, or null when none was found.", "type": ["string", "null"] },
        "independent": { "type": "boolean" },
        "loss_status": { "enum": ["reported", "pending", "disputed", "not_monetary"] },
        "supersedes": { "type": ["string", "null"] },
        "loss_minor": { "type": ["integer", "null"], "minimum": 0 }, "currency": { "type": ["string", "null"] },
        "causal_link": { "oneOf": [ { "type": "null" }, { "type": "object", "additionalProperties": false, "required": ["basis", "attested_by"],
          "properties": { "basis": { "type": "string" }, "attested_by": { "$ref": "#/$defs/opaque" } } } ] } } } }
  }
}
