{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://law.arxo.io/schema/evaluation-request.schema.json",
 "title": "EvaluationRequest",
 "description": "The single closed input of evaluate(request). Execution options are permitted only in case.options.",
 "$comment": "SPEC §168.3; DECISION-0111 §2.2",
 "type": "object",
 "additionalProperties": false,
 "required": [
  "schemaVersion",
  "semanticVersion",
  "ir",
  "case",
  "query"
 ],
 "properties": {
  "schemaVersion": {
   "const": "law.core.evaluation-request/0.2"
  },
  "semanticVersion": {
   "type": "string",
   "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))?$",
   "description": "An exact release identity, or a line name resolved through the build's line defaults; registration, build admission and R/I equality are checked before execution.",
   "$comment": "DECISION-0451, amended E-0313"
  },
  "ir": {
   "allOf": [
    {
     "$ref": "legal-ir.schema.json"
    },
    {
     "properties": {
      "schemaVersion": {
       "enum": [
        "law.core.ir/0.2",
        "law.core.ir/0.3",
        "law.core.ir/0.4",
        "law.core.ir/0.5",
        "law.core.ir/0.6"
       ]
      },
      "semanticVersion": {
       "type": "string",
       "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))?$"
      }
     }
    }
   ]
  },
  "case": {
   "$ref": "#/$defs/Case"
  },
  "query": {
   "$ref": "query.schema.json"
  },
  "calendar": {
   "type": "string",
   "description": "Bytes of the pinned calendar resource in UTF-8 JSON; transport, not a case option."
  },
  "externalSnapshots": {
   "type": "array",
   "items": {
    "$ref": "external-snapshot.schema.json"
   }
  },
  "receipt": {
   "$ref": "evaluation.schema.json#/$defs/ExecutionReceipt"
  },
  "editionsAsPresented": {
   "$ref": "evaluation.schema.json#/$defs/LegalTime",
   "description": "The date as of which the set of the program's normative nodes has already been projected by the caller. At this date, the case-date condition on the date of law is not executed; transport only, not included in caseHash, included in the manifest and in the semantic hash.",
   "$comment": "SPEC §31, §92; errata E-0167"
  },
  "layer": {
   "enum": [
    "L0",
    "L1"
   ],
   "description": "Layer of the executing implementation. Transport only: not included in case.options, caseHash, the manifest or the semantic hash. The layered run returns a document byte-identical to the full run, or refuses before any inference with LAYER_EXCEEDED / EVIDENCE_POLICY_LAYER_CONFLICT.",
   "$comment": "SPEC §168.3; LS §2.4; errata E-0251"
  }
 },
 "allOf": [
  {
   "if": {
    "properties": {
     "semanticVersion": {
      "pattern": "^0\\.[23](?:-draft|(?:\\.0)?)$"
     }
    },
    "required": [
     "semanticVersion"
    ]
   },
   "then": {
    "properties": {
     "case": {
      "properties": {
       "context": {
        "properties": {
         "deadlinePolicy": {
          "type": "string",
          "minLength": 1
         }
        }
       },
       "contextProfiles": {
        "additionalProperties": {
         "type": "object",
         "properties": {
          "fields": {
           "type": "object",
           "properties": {
            "deadlinePolicy": {
             "type": "string",
             "minLength": 1
            }
           }
          }
         }
        }
       }
      }
     }
    }
   }
  }
 ],
 "$defs": {
  "Case": {
   "type": "object",
   "additionalProperties": false,
   "required": [
    "assertions",
    "context",
    "options"
   ],
   "properties": {
    "assertions": {
     "type": "array",
     "items": {
      "$ref": "legal-ir.schema.json#/$defs/CaseAssertion"
     }
    },
    "constants": {
     "type": [
      "array",
      "object"
     ]
    },
    "context": {
     "type": "object"
    },
    "entityLabels": {
     "description": "Labels of case entities: StableId to a non-empty array of Legal IR labels. Presentational: outside caseHash, the manifest and resultHash. The shape is checked by the evaluator with verbatim messages, not by this schema, so all implementations refuse with one text.",
     "$comment": "SPEC §168.6, §170; DECISION-0394"
    },
    "contextProfiles": {
     "type": "object"
    },
    "evidence": {
     "type": "array",
     "items": {
      "$ref": "legal-ir.schema.json#/$defs/EvidenceItem"
     }
    },
    "externalData": {
     "type": [
      "array",
      "object"
     ]
    },
    "options": {
     "$ref": "#/$defs/EvaluationOptions"
    },
    "solverProfile": {
     "type": "string"
    },
    "supportEdges": {
     "type": "array",
     "items": {
      "$ref": "legal-ir.schema.json#/$defs/SupportEdge"
     }
    },
    "verifications": {
     "description": "Pinned results of external document-authenticity verification. Case transport: covered by caseHash, not computed by the core.",
     "$comment": "SPEC §78.2.3; DECISION-0126",
     "type": "array",
     "items": {
      "$ref": "#/$defs/EvidenceVerification"
     }
    },
    "sources": {
     "description": "Routes for presenting records from snapshots of other cases: alias, snapshot contentHash, source, and the selected records in `use` order. Written only when the set is non-empty; covered by caseHash.",
     "$comment": "SPEC §168.5; DECISION-0169",
     "type": "array",
     "minItems": 1,
     "items": {
      "$ref": "#/$defs/CaseSource"
     }
    }
   }
  },
  "CaseSource": {
   "type": "object",
   "additionalProperties": false,
   "required": [
    "alias",
    "snapshot",
    "package",
    "case",
    "records"
   ],
   "properties": {
    "alias": {
     "type": "string",
     "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
    },
    "snapshot": {
     "type": "string",
     "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "package": {
     "type": "object",
     "additionalProperties": false,
     "required": [
      "name",
      "version",
      "namespace"
     ],
     "properties": {
      "name": {
       "type": "string"
      },
      "version": {
       "type": "string"
      },
      "namespace": {
       "type": "string"
      }
     }
    },
    "case": {
     "type": "string",
     "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
    },
    "records": {
     "type": "array",
     "minItems": 1,
     "items": {
      "type": "string"
     }
    }
   }
  },
  "EvidenceVerification": {
   "type": "object",
   "additionalProperties": false,
   "required": [
    "id",
    "evidence",
    "documentHash",
    "verifier",
    "outcome",
    "recordedAt"
   ],
   "properties": {
    "id": {
     "type": "string",
     "minLength": 1
    },
    "evidence": {
     "$ref": "legal-ir.schema.json#/$defs/StableId"
    },
    "documentHash": {
     "$ref": "legal-ir.schema.json#/$defs/Digest"
    },
    "verifier": {
     "type": "string",
     "minLength": 1
    },
    "outcome": {
     "type": "string",
     "minLength": 1
    },
    "recordedAt": {
     "$ref": "legal-ir.schema.json#/$defs/InstantString",
     "description": "The moment the verification result became available. Required: a record later than knowledgeTime is not included in the output; there is no implicit Date to Instant conversion.",
     "$comment": "SPEC §78.2.3, §48"
    }
   }
  },
  "FactInput": {
   "type": "object",
   "additionalProperties": false,
   "description": "Host sugar of one fact. Lowered into an assertion. Provenance is optional; a call without it is the legacy fact form. The document and the support edges travel as case.evidence and case.supportEdges, not inside this object. Confidence is carried, not evaluated.",
   "$comment": "SPEC §168.4; DECISION-0360",
   "required": [
    "predicate",
    "args"
   ],
   "properties": {
    "predicate": {
     "type": "string",
     "minLength": 1
    },
    "args": {
     "type": "array"
    },
    "negated": {
     "type": "boolean"
    },
    "package": {
     "type": "string",
     "minLength": 1
    },
    "judgment": {
     "type": "object",
     "additionalProperties": false,
     "required": [
      "authority"
     ],
     "description": "Adjudicated answer. Authority must be the declared organ, or the assertion is rejected.",
     "$comment": "SPEC §47.3.1; E-0089",
     "properties": {
      "authority": {
       "$ref": "legal-ir.schema.json#/$defs/StableId"
      },
      "payload": {
       "$ref": "legal-ir.schema.json#/$defs/Term"
      },
      "request": {
       "$ref": "legal-ir.schema.json#/$defs/StableId"
      }
     }
    },
    "provenance": {
     "type": "object",
     "additionalProperties": false,
     "properties": {
      "origin": {
       "enum": [
        "case_input",
        "source_asserted",
        "external_snapshot",
        "derived",
        "adjudicated",
        "assumed_for_simulation"
       ],
       "description": "The default case-input origin. Extraction is not a new origin.",
       "$comment": "SPEC §73"
      },
      "evidence": {
       "$ref": "legal-ir.schema.json#/$defs/StableId"
      },
      "span": {
       "type": "object",
       "additionalProperties": false,
       "properties": {
        "page": {
         "type": "integer",
         "minimum": 0
        },
        "quote": {
         "type": "string"
        },
        "offset": {
         "type": "integer",
         "minimum": 0
        }
       }
      },
      "extractor": {
       "type": "object",
       "additionalProperties": false,
       "required": [
        "name"
       ],
       "properties": {
        "name": {
         "type": "string",
         "minLength": 1
        },
        "version": {
         "type": "string"
        },
        "confidence": {
         "type": "string",
         "description": "Decimal text. The package EvidencePolicy reads it; the core does not."
        }
       }
      },
      "observedAt": {
       "type": "string"
      },
      "recordedAt": {
       "type": "string"
      }
     }
    }
   }
  },
  "EvaluationOptions": {
   "type": "object",
   "additionalProperties": false,
   "properties": {
    "mode": {
     "enum": [
      "advisory",
      "compliance",
      "regulatory",
      "simulation",
      "audit"
     ]
    },
    "limits": {},
    "on_accepted_conflict": {},
    "selectedInterpretations": {},
    "calendarSnapshot": {},
    "temporalResolutionPolicy": {},
    "manifestId": {},
    "lockfileHash": {},
    "evidenceSnapshotHash": {},
    "jurisdictionProfile": {
     "type": "string",
     "pattern": "^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*)*/[0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z.-]+)?#sha256:[0-9a-f]{64}$",
     "description": "Canon profile in the unified grammar `<id>/<version>#sha256:<64 hex>`. Present only for a computation over a package with a named profile.",
     "$comment": "SPEC §170.1; errata E-0161; DECISION-0170"
    },
    "policies": {}
   }
  }
 }
}
