{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://iop.local/schemas/iop-agent-chronos-transfer-state-v1.schema.json",
  "title": "IOP Agent Chronos Transfer State v1",
  "description": "Versioned, sanitized legacy-state transfer input. No host paths or sensitive material are permitted in tracked fixtures.",
  "type": "object",
  "additionalProperties": false,
  "required": ["version", "records"],
  "properties": {
    "version": {
      "type": "integer",
      "const": 1,
      "description": "Schema version. Bump when record shape changes."
    },
    "records": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/record"
      }
    }
  },
  "$defs": {
    "record": {
      "type": "object",
      "additionalProperties": false,
      "required": ["logical_id", "bundle_path", "source_manifest", "category", "source_revision", "digest", "size", "mode", "resumable"],
      "properties": {
        "logical_id": {
          "type": "string",
          "pattern": "^state:[a-z0-9-]+$",
          "description": "Logical state identifier. Original entries must match the immutable ownership manifest; supplemental cache/temp entries are reconciled through the D04 surface addendum."
        },
        "bundle_path": {
          "type": "string",
          "pattern": "^legacy-state/[a-z0-9-]+$",
          "description": "Repository-neutral acceptance-v1 path; never a host filesystem path."
        },
        "source_manifest": {
          "type": "string",
          "enum": ["original", "d04-addendum"],
          "description": "Provenance class used by the effective disposition matrix."
        },
        "category": {
          "type": "string",
          "enum": [
            "config",
            "state",
            "client",
            "log",
            "overlay",
            "cache",
            "temp",
            "quarantine"
          ],
          "description": "Logical state family. 'quarantine' is reserved for broken residual records that must not be resumed."
        },
        "source_revision": {
          "type": "string",
          "pattern": "^[0-9a-f]{40,64}$",
          "description": "IOP commit used as the source-of-truth revision for this transfer."
        },
        "digest": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "SHA-256 digest of the state payload. Synthetic fixtures MUST use a deterministic placeholder."
        },
        "size": {
          "type": "number",
          "minimum": 0,
          "description": "Payload size in bytes. Synthetic fixtures MUST use a deterministic placeholder."
        },
        "mode": {
          "type": "string",
          "const": "read-only",
          "description": "Transfer mode. Valid records are read-only at transfer time."
        },
        "resumable": {
          "type": "boolean",
          "description": "Whether the record may be resumed after import. Broken residuals MUST be false."
        },
        "quarantine_reason": {
          "type": "string",
          "minLength": 1,
          "description": "Required for category='quarantine'. Free-text reason the record was quarantined. Must not contain host paths or sensitive data."
        }
      },
      "allOf": [
        {
          "if": {
            "properties": { "category": { "const": "quarantine" } },
            "required": ["category"]
          },
          "then": {
            "properties": { "resumable": { "const": false } },
            "required": ["quarantine_reason"]
          },
          "else": {
            "properties": { "resumable": { "const": true } },
            "not": { "required": ["quarantine_reason"] }
          }
        }
      ]
    }
  }
}
