{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:roleevidence:decision-record:draft-v0.1",
  "title": "Role Evidence Hiring Decision Record Draft v0.1",
  "description": "Draft record structure for review. This is not an audit standard, certification, or legal safe harbor.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "recordVersion",
    "recordId",
    "previousRecordHash",
    "requirementSetVersion",
    "decisionStage",
    "system",
    "requirements",
    "evidenceBindings",
    "suppressionManifest",
    "review",
    "timestamp"
  ],
  "properties": {
    "recordVersion": {
      "const": "0.1-draft"
    },
    "recordId": {
      "type": "string",
      "minLength": 1
    },
    "previousRecordHash": {
      "type": ["string", "null"],
      "description": "Hash of the prior record in the review sequence when one exists."
    },
    "requirementSetVersion": {
      "type": "string",
      "minLength": 1
    },
    "decisionStage": {
      "type": "string",
      "enum": ["intake", "evidence_review", "submission_review", "client_review", "final_review"]
    },
    "system": {
      "type": "object",
      "additionalProperties": false,
      "required": ["modelId", "modelRevision", "promptVersion", "schemaVersion"],
      "properties": {
        "modelId": { "type": "string", "minLength": 1 },
        "modelRevision": { "type": "string", "minLength": 1 },
        "promptVersion": { "type": "string", "minLength": 1 },
        "schemaVersion": { "type": "string", "minLength": 1 }
      }
    },
    "requirements": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "text", "classification", "reviewStatus", "rationaleStatus"],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "text": { "type": "string", "minLength": 1 },
          "classification": {
            "type": "string",
            "enum": ["essential", "preferred", "unclear"]
          },
          "reviewStatus": {
            "type": "string",
            "enum": ["ready", "needs_review"]
          },
          "rationaleStatus": {
            "const": "requires_recruiter_confirmation"
          }
        }
      }
    },
    "evidenceBindings": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "requirementId",
          "verdict",
          "citations",
          "extractionConfidence",
          "explanation"
        ],
        "properties": {
          "requirementId": { "type": "string", "minLength": 1 },
          "verdict": {
            "type": "string",
            "enum": ["evidenced", "partially_evidenced", "not_evidenced", "needs_review"]
          },
          "citations": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["startOffset", "endOffset", "excerpt"],
              "properties": {
                "startOffset": { "type": "integer", "minimum": 0 },
                "endOffset": { "type": "integer", "minimum": 1 },
                "excerpt": { "type": "string", "minLength": 1 },
                "page": { "type": "integer", "minimum": 1 },
                "lineStart": { "type": "integer", "minimum": 1 },
                "lineEnd": { "type": "integer", "minimum": 1 }
              }
            }
          },
          "extractionConfidence": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "description": "Confidence in extracting the cited evidence, not a score of candidate quality."
          },
          "explanation": { "type": "string", "minLength": 1 }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "verdict": {
                  "enum": ["evidenced", "partially_evidenced"]
                }
              },
              "required": ["verdict"]
            },
            "then": {
              "properties": {
                "citations": { "minItems": 1 }
              }
            }
          },
          {
            "if": {
              "properties": {
                "verdict": { "const": "not_evidenced" }
              },
              "required": ["verdict"]
            },
            "then": {
              "properties": {
                "citations": { "maxItems": 0 }
              }
            }
          }
        ]
      }
    },
    "suppressionManifest": {
      "type": "object",
      "additionalProperties": false,
      "required": ["categories", "totalSuppressed"],
      "properties": {
        "categories": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["category", "count"],
            "properties": {
              "category": { "type": "string", "minLength": 1 },
              "count": { "type": "integer", "minimum": 0 }
            }
          }
        },
        "totalSuppressed": { "type": "integer", "minimum": 0 }
      }
    },
    "review": {
      "type": "object",
      "additionalProperties": false,
      "required": ["reviewer", "overrideApplied"],
      "properties": {
        "reviewer": { "type": "string", "minLength": 1 },
        "overrideApplied": { "type": "boolean" },
        "overrideReason": { "type": ["string", "null"] }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "overrideApplied": { "const": true }
            },
            "required": ["overrideApplied"]
          },
          "then": {
            "required": ["overrideReason"],
            "properties": {
              "overrideReason": { "type": "string", "minLength": 1 }
            }
          }
        }
      ]
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    }
  }
}
