{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://finance.entelekron.org/schemas/counterparty-risk-register.schema.json",
  "title": "EnteleKRON Counterparty Risk Register",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "schemaVersion", "controlPlaneId", "registryId", "status", "asOf", "defaultDecision", "counterparties", "currentGrossExposureUsd", "currentUnsecuredExposureUsd", "portfolioLimits", "requiredRiskDimensions", "authority", "notice"],
  "properties": {
    "$schema": { "const": "https://finance.entelekron.org/schemas/counterparty-risk-register.schema.json" },
    "schemaVersion": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "controlPlaneId": { "const": "tvk-group:entelekron-financial-infrastructure" },
    "registryId": { "type": "string", "pattern": "^entelekron-counterparty-risk-v[0-9]+$" },
    "status": { "enum": ["no-approved-counterparties", "controlled-production", "suspended"] },
    "asOf": { "type": "string", "format": "date-time" },
    "defaultDecision": { "const": "deny" },
    "counterparties": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["counterpartyId", "legalName", "country", "regulatedStatus", "approvedProducts", "grossLimitUsd", "unsecuredLimitUsd", "currentGrossExposureUsd", "currentUnsecuredExposureUsd", "riskRating", "reviewedAt", "expiresAt", "decision", "evidenceUrls", "independentApprovals"],
        "properties": {
          "counterpartyId": { "type": "string", "minLength": 1 },
          "legalName": { "type": "string", "minLength": 1 },
          "country": { "type": "string", "pattern": "^[A-Z]{2}$" },
          "regulatedStatus": { "type": "string", "minLength": 1 },
          "approvedProducts": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
          "grossLimitUsd": { "$ref": "#/$defs/money" },
          "unsecuredLimitUsd": { "$ref": "#/$defs/money" },
          "currentGrossExposureUsd": { "$ref": "#/$defs/money" },
          "currentUnsecuredExposureUsd": { "$ref": "#/$defs/money" },
          "riskRating": { "type": "string", "minLength": 1 },
          "reviewedAt": { "type": "string", "format": "date-time" },
          "expiresAt": { "type": "string", "format": "date-time" },
          "decision": { "enum": ["approved", "denied", "suspended"] },
          "evidenceUrls": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "format": "uri" } },
          "independentApprovals": { "type": "array", "minItems": 2, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } }
        }
      }
    },
    "currentGrossExposureUsd": { "$ref": "#/$defs/money" },
    "currentUnsecuredExposureUsd": { "$ref": "#/$defs/money" },
    "portfolioLimits": {
      "type": "object",
      "additionalProperties": false,
      "required": ["approved", "maximumGrossExposureUsd", "maximumUnsecuredExposureUsd", "maximumSingleCounterpartyExposureUsd", "maximumCountryConcentrationUsd"],
      "properties": {
        "approved": { "type": "boolean" },
        "maximumGrossExposureUsd": { "$ref": "#/$defs/money" },
        "maximumUnsecuredExposureUsd": { "$ref": "#/$defs/money" },
        "maximumSingleCounterpartyExposureUsd": { "$ref": "#/$defs/money" },
        "maximumCountryConcentrationUsd": { "$ref": "#/$defs/money" }
      }
    },
    "requiredRiskDimensions": { "type": "array", "minItems": 10, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } },
    "authority": {
      "type": "object",
      "additionalProperties": false,
      "required": ["aiCanApproveCounterparty", "aiCanIncreaseLimit", "aiCanWaiveExpiredReview", "singleOperatorCanApproveAndFundExposure"],
      "properties": {
        "aiCanApproveCounterparty": { "const": false },
        "aiCanIncreaseLimit": { "const": false },
        "aiCanWaiveExpiredReview": { "const": false },
        "singleOperatorCanApproveAndFundExposure": { "const": false }
      }
    },
    "notice": { "type": "string", "minLength": 1 }
  },
  "$defs": { "money": { "type": "string", "pattern": "^[0-9]+\\.[0-9]{2}$" } }
}
