{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://finance.entelekron.org/schemas/enteletreasury-book-registry.schema.json",
  "title": "EnteleTREASURY Book Registry",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "schemaVersion", "controlPlaneId", "canonicalAssetId", "registryId", "status", "asOf", "consolidatedVisibilityAllowed", "consolidatedOwnershipAllowed", "productionLedgerEndpoint", "books", "crossBookTransfers", "authority", "notice"],
  "properties": {
    "$schema": { "const": "https://finance.entelekron.org/schemas/enteletreasury-book-registry.schema.json" },
    "schemaVersion": { "$ref": "#/$defs/semver" },
    "controlPlaneId": { "const": "tvk-group:entelekron-financial-infrastructure" },
    "canonicalAssetId": { "const": "tvk-group:tvkusd" },
    "registryId": { "type": "string", "pattern": "^enteletreasury-books-[a-z0-9-]+-v[0-9]+$" },
    "status": { "enum": ["prelaunch-locked", "controlled-production", "suspended"] },
    "asOf": { "type": "string", "format": "date-time" },
    "consolidatedVisibilityAllowed": { "type": "boolean" },
    "consolidatedOwnershipAllowed": { "const": false },
    "productionLedgerEndpoint": { "type": ["string", "null"], "format": "uri" },
    "books": {
      "type": "array",
      "minItems": 6,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["bookId", "legalOwner", "administrator", "reportingStatus", "reportedBalanceUsd", "balanceSource", "valueMovementEnabled", "permittedPurposes", "prohibitedPurposes"],
        "properties": {
          "bookId": { "type": "string", "minLength": 1 },
          "legalOwner": { "type": ["string", "null"] },
          "administrator": { "type": ["string", "null"] },
          "reportingStatus": { "enum": ["pre-issuance-zero", "not-connected", "active", "suspended"] },
          "reportedBalanceUsd": { "anyOf": [{ "$ref": "#/$defs/money" }, { "type": "null" }] },
          "balanceSource": { "type": ["string", "null"] },
          "valueMovementEnabled": { "type": "boolean" },
          "permittedPurposes": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
          "prohibitedPurposes": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } }
        }
      }
    },
    "crossBookTransfers": {
      "type": "object",
      "additionalProperties": false,
      "required": ["enabled", "requireDocumentedLegalPurpose", "requireExactDebitAndCreditEntries", "requireIndependentApprovals", "requireOwnershipAndEntitlementChecks", "requireTamperEvidentEvidence", "silentNettingPermitted"],
      "properties": {
        "enabled": { "type": "boolean" },
        "requireDocumentedLegalPurpose": { "const": true },
        "requireExactDebitAndCreditEntries": { "const": true },
        "requireIndependentApprovals": { "const": true },
        "requireOwnershipAndEntitlementChecks": { "const": true },
        "requireTamperEvidentEvidence": { "const": true },
        "silentNettingPermitted": { "const": false }
      }
    },
    "authority": {
      "type": "object",
      "additionalProperties": false,
      "required": ["aiCanMoveValue", "aiCanChangeBookOwnership", "singleOperatorCanTransferAcrossBooks", "softwareCanInferLegalOwnership"],
      "properties": {
        "aiCanMoveValue": { "const": false },
        "aiCanChangeBookOwnership": { "const": false },
        "singleOperatorCanTransferAcrossBooks": { "const": false },
        "softwareCanInferLegalOwnership": { "const": false }
      }
    },
    "notice": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "semver": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "money": { "type": "string", "pattern": "^[0-9]+\\.[0-9]{2}$" }
  }
}
