{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "recordType",
    "candidateId",
    "subjectOrganizationId",
    "partnerOrganizationId",
    "currency",
    "amountUnit",
    "perEventCap",
    "aggregateCap",
    "maximumLoss",
    "reserveAmount",
    "maximumCoveredEvents",
    "remedies",
    "residualLiability",
    "acceptedBy"
  ],
  "properties": {
    "schemaVersion": {
      "const": "3.0.0"
    },
    "recordType": {
      "const": "bounded-liability-decision"
    },
    "candidateId": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "subjectOrganizationId": {
      "type": "string",
      "pattern": "^organization:[0-9a-f]{64}$"
    },
    "partnerOrganizationId": {
      "type": "string",
      "pattern": "^organization:[0-9a-f]{64}$"
    },
    "currency": {
      "enum": [
        "USD",
        "USDC"
      ]
    },
    "amountUnit": {
      "enum": [
        "usd-cents",
        "usdc-micro-units"
      ]
    },
    "perEventCap": {
      "type": "string",
      "pattern": "^[1-9][0-9]{0,77}$"
    },
    "aggregateCap": {
      "type": "string",
      "pattern": "^[1-9][0-9]{0,77}$"
    },
    "maximumLoss": {
      "type": "string",
      "pattern": "^[1-9][0-9]{0,77}$"
    },
    "reserveAmount": {
      "type": "string",
      "pattern": "^[1-9][0-9]{0,77}$"
    },
    "maximumCoveredEvents": {
      "type": "integer",
      "minimum": 1,
      "maximum": 1000000
    },
    "remedies": {
      "type": "array",
      "minItems": 1,
      "maxItems": 4,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "remedyType",
          "description",
          "maximumAmount",
          "amountUnit"
        ],
        "properties": {
          "remedyType": {
            "enum": [
              "refund",
              "service-credit",
              "termination-right",
              "damage-claim"
            ]
          },
          "description": {
            "type": "string",
            "minLength": 24,
            "maxLength": 512
          },
          "maximumAmount": {
            "type": "string",
            "pattern": "^[1-9][0-9]{0,77}$"
          },
          "amountUnit": {
            "enum": [
              "usd-cents",
              "usdc-micro-units"
            ]
          }
        }
      }
    },
    "residualLiability": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "allocationBasis",
        "stackingPolicy",
        "remedyTreatment",
        "description",
        "uncappedCategories",
        "categoryCaps"
      ],
      "properties": {
        "allocationBasis": {
          "const": "all-liability-categories-within-maximum-loss"
        },
        "stackingPolicy": {
          "const": "cumulative-within-aggregate-cap"
        },
        "remedyTreatment": {
          "const": "remedies-are-suballocations-not-additional-exposure"
        },
        "description": {
          "type": "string",
          "minLength": 24,
          "maxLength": 1024
        },
        "uncappedCategories": {
          "const": []
        },
        "categoryCaps": {
          "type": "array",
          "minItems": 5,
          "maxItems": 5,
          "uniqueItems": true,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "category",
              "maximumAmount",
              "amountUnit"
            ],
            "properties": {
              "category": {
                "enum": [
                  "general",
                  "fraud",
                  "willful-misconduct",
                  "confidentiality-breach",
                  "data-protection-breach"
                ]
              },
              "maximumAmount": {
                "type": "string",
                "pattern": "^[1-9][0-9]{0,77}$"
              },
              "amountUnit": {
                "enum": [
                  "usd-cents",
                  "usdc-micro-units"
                ]
              }
            }
          }
        }
      }
    },
    "acceptedBy": {
      "type": "array",
      "minItems": 2,
      "maxItems": 2,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "identityId",
          "organizationId",
          "roleId",
          "keyType",
          "publicKeySha256",
          "authorityEvidenceId",
          "signedPayloadSha256",
          "signatureBase64"
        ],
        "properties": {
          "identityId": {
            "type": "string",
            "pattern": "^identity:[0-9a-f]{64}$"
          },
          "organizationId": {
            "type": "string",
            "pattern": "^organization:[0-9a-f]{64}$"
          },
          "roleId": {
            "enum": [
              "authorized-signatory",
              "partner-authorized-signatory"
            ]
          },
          "keyType": {
            "const": "Ed25519"
          },
          "publicKeySha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "authorityEvidenceId": {
            "type": "string",
            "pattern": "^[A-Z0-9-]+$"
          },
          "signedPayloadSha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "signatureBase64": {
            "type": "string",
            "minLength": 88,
            "maxLength": 88
          }
        }
      }
    }
  }
}
