{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uwmd.org/schemas/debt-rate-hedge.schema.json",
  "title": "debt-rate-hedge",
  "description": "RFC 0081 G1 / Format \u00c2\u00a74.7. instrument and strike_rate required; the terms group is all-or-none. premium may be stated without terms. HDG-06\u00e2\u20ac\u201c10 and replacement funding evaluate only with the terms group. HDG-02 refuses reserved instruments; HDG-03 rate type is semantic. A member stated as null is not stated: replacement_funding: null requires no terms group.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "instrument",
    "strike_rate"
  ],
  "properties": {
    "instrument": {
      "enum": [
        "rate_cap"
      ]
    },
    "notional": {
      "description": "What the cap is written on. A loan larger than this is partly unhedged.",
      "type": "number",
      "minimum": 0
    },
    "strike_rate": {
      "description": "A fraction, not a percent. 0.035 is 3.5%.",
      "type": "number",
      "exclusiveMinimum": 0,
      "exclusiveMaximum": 1
    },
    "index": {
      "description": "The rate_index vocabulary minus `fixed`, which a cap is not struck against.",
      "enum": [
        "sofr",
        "prime",
        "treasury_5yr",
        "treasury_10yr"
      ]
    },
    "effective_date": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
      "format": "date"
    },
    "expiration_date": {
      "description": "Strictly after effective_date (HDG-01).",
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
      "format": "date"
    },
    "premium": {
      "description": "Upfront cash paid. null means genuinely none. Never priced from a curve.",
      "type": [
        "number",
        "null"
      ],
      "minimum": 0
    },
    "post_expiration_assumption": {
      "description": "What happens in the month after the cap expires. No default: unstated is the answer that hides the cliff.",
      "enum": [
        "replace",
        "unhedged",
        "loan_matures_first"
      ]
    },
    "counterparty": {
      "description": "Author narrative. Nothing is inferred from it.",
      "type": [
        "string",
        "null"
      ]
    },
    "replacement_funding": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode"
          ],
          "properties": {
            "mode": {
              "const": "escrow"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode",
            "cash_flow_ref"
          ],
          "properties": {
            "mode": {
              "const": "outright"
            },
            "cash_flow_ref": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "variant",
                "row_index",
                "binding_digest"
              ],
              "properties": {
                "variant": {
                  "type": "string",
                  "minLength": 1
                },
                "row_index": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "binding_digest": {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                }
              }
            }
          }
        }
      ],
      "description": "RFC 0120: binding verification preserves applicable existing CF findings for the exact selected physical cash-flow source alongside HDG/ESC/CUR; unrelated or superseded sources are excluded."
    }
  },
  "allOf": [
    {
      "if": {
        "required": [
          "replacement_funding"
        ],
        "properties": {
          "replacement_funding": {
            "type": "object"
          }
        }
      },
      "then": {
        "properties": {
          "post_expiration_assumption": {
            "const": "replace"
          }
        },
        "required": [
          "post_expiration_assumption"
        ]
      }
    }
  ],
  "dependentRequired": {
    "notional": [
      "index",
      "effective_date",
      "expiration_date",
      "post_expiration_assumption"
    ],
    "index": [
      "notional",
      "effective_date",
      "expiration_date",
      "post_expiration_assumption"
    ],
    "effective_date": [
      "notional",
      "index",
      "expiration_date",
      "post_expiration_assumption"
    ],
    "expiration_date": [
      "notional",
      "index",
      "effective_date",
      "post_expiration_assumption"
    ],
    "post_expiration_assumption": [
      "notional",
      "index",
      "effective_date",
      "expiration_date"
    ]
  },
  "dependentSchemas": {
    "replacement_funding": {
      "if": {
        "properties": {
          "replacement_funding": {
            "type": "null"
          }
        }
      },
      "else": {
        "required": [
          "notional",
          "index",
          "effective_date",
          "expiration_date",
          "post_expiration_assumption"
        ]
      }
    }
  }
}
