{
  "$defs": {
    "Collateral": {
      "description": "Collateral securing the debt.",
      "properties": {
        "asset_ref": {
          "$ref": "#/$defs/PathRef",
          "description": "PathRef into the pledged asset (FixedAsset / CashPosition)."
        },
        "kind": {
          "type": "string"
        },
        "value": {
          "$ref": "#/$defs/MonetaryAmount"
        }
      },
      "required": [
        "kind",
        "asset_ref",
        "value"
      ],
      "type": "object"
    },
    "DebtInstrument": {
      "description": "Debt instrument kind.",
      "oneOf": [
        {
          "enum": [
            "term_loan",
            "revolver",
            "venture_debt",
            "shareholder_loan",
            "founder_loan",
            "factoring",
            "mezzanine",
            "bond",
            "other"
          ],
          "type": "string"
        },
        {
          "const": "sba",
          "description": "US Small Business Administration loan.",
          "type": "string"
        },
        {
          "const": "kfw",
          "description": "DE KfW programme loan.",
          "type": "string"
        },
        {
          "const": "exist",
          "description": "DE EXIST start-up grant (often debt-flavoured when repayable).",
          "type": "string"
        },
        {
          "const": "convertible_loan_debt_phase",
          "description": "Debt phase of a convertible (pre-conversion).",
          "type": "string"
        }
      ]
    },
    "DebtPaymentFrequency": {
      "description": "Amortisation pattern.",
      "oneOf": [
        {
          "enum": [
            "monthly",
            "quarterly",
            "semi_annual",
            "annual",
            "bullet"
          ],
          "type": "string"
        },
        {
          "const": "amortising_french",
          "description": "French (interest+principal level payment).",
          "type": "string"
        },
        {
          "const": "amortising_german",
          "description": "German (level principal, decreasing interest).",
          "type": "string"
        }
      ]
    },
    "DebtStatus": {
      "description": "Debt lifecycle status.",
      "enum": [
        "committed_not_drawn",
        "outstanding",
        "in_default",
        "repaid",
        "restructured",
        "forgiven"
      ],
      "type": "string"
    },
    "Ifrs9DebtClass": {
      "description": "IFRS 9 financial-instrument classification.",
      "enum": [
        "amortised_cost",
        "fvtoci",
        "fvtpl"
      ],
      "type": "string"
    },
    "InterestRate": {
      "description": "Fixed or floating rate.",
      "properties": {
        "base": {
          "description": "Base rate (e.g. 0.04 = 4%). For floating rates, this is the\nindex reference rate; for fixed, the contractual rate.",
          "format": "double",
          "type": "number"
        },
        "index": {
          "anyOf": [
            {
              "$ref": "#/$defs/RateIndex"
            },
            {
              "type": "null"
            }
          ]
        },
        "spread_bps": {
          "format": "int32",
          "type": [
            "integer",
            "null"
          ]
        },
        "type": {
          "$ref": "#/$defs/InterestRateKind"
        }
      },
      "required": [
        "base",
        "type"
      ],
      "type": "object"
    },
    "InterestRateKind": {
      "description": "Fixed vs floating discriminator.",
      "enum": [
        "fixed",
        "floating"
      ],
      "type": "string"
    },
    "IsoCountry": {
      "description": "ISO 3166-1 alpha-2 country code.",
      "pattern": "^[A-Z]{2}$",
      "type": "string"
    },
    "IsoCurrency": {
      "description": "ISO 4217 currency code.",
      "pattern": "^[A-Z]{3}$",
      "type": "string"
    },
    "IsoDate": {
      "description": "ISO 8601 date (YYYY-MM-DD).",
      "format": "date",
      "type": "string"
    },
    "MonetaryAmount": {
      "description": "A monetary value with currency.",
      "properties": {
        "amount": {
          "format": "double",
          "type": "number"
        },
        "currency": {
          "$ref": "#/$defs/IsoCurrency"
        }
      },
      "required": [
        "amount",
        "currency"
      ],
      "type": "object"
    },
    "PathRef": {
      "description": "Path-based cross-reference relative to .corpospec/ root.\nPattern: `^[a-z0-9_-]+(/[a-z0-9_.-]+)+$`",
      "pattern": "^[a-z0-9_-]+(/[a-z0-9_.-]+)+$",
      "type": "string"
    },
    "PaymentSchedule": {
      "description": "Payment schedule.",
      "properties": {
        "frequency": {
          "$ref": "#/$defs/DebtPaymentFrequency"
        },
        "payments": {
          "items": {
            "$ref": "#/$defs/ScheduledPayment"
          },
          "type": "array"
        }
      },
      "required": [
        "frequency",
        "payments"
      ],
      "type": "object"
    },
    "PrepaymentTerms": {
      "description": "Prepayment terms.",
      "properties": {
        "allowed": {
          "type": "boolean"
        },
        "lockout_period_months": {
          "format": "int32",
          "type": [
            "integer",
            "null"
          ]
        },
        "penalty_bps": {
          "format": "int32",
          "type": [
            "integer",
            "null"
          ]
        }
      },
      "required": [
        "allowed"
      ],
      "type": "object"
    },
    "RateIndex": {
      "description": "Floating-rate index reference.",
      "properties": {
        "name": {
          "description": "E.g. `\"€STR\"`, `\"SOFR\"`, `\"SONIA\"`, `\"EURIBOR-3M\"`.",
          "type": "string"
        },
        "spread_bps": {
          "description": "Spread over the index in basis points.",
          "format": "int32",
          "type": "integer"
        }
      },
      "required": [
        "name",
        "spread_bps"
      ],
      "type": "object"
    },
    "ScheduledPayment": {
      "description": "One scheduled payment.",
      "properties": {
        "due_date": {
          "$ref": "#/$defs/IsoDate"
        },
        "interest": {
          "format": "double",
          "type": "number"
        },
        "paid_date": {
          "anyOf": [
            {
              "$ref": "#/$defs/IsoDate"
            },
            {
              "type": "null"
            }
          ]
        },
        "principal": {
          "format": "double",
          "type": "number"
        }
      },
      "required": [
        "due_date",
        "principal",
        "interest"
      ],
      "type": "object"
    },
    "Subordination": {
      "description": "Subordination terms.",
      "properties": {
        "rank": {
          "$ref": "#/$defs/SubordinationRank"
        },
        "subordinated_to": {
          "description": "PathRefs into senior debt instruments this is subordinated to.",
          "items": {
            "$ref": "#/$defs/PathRef"
          },
          "type": "array"
        }
      },
      "required": [
        "rank"
      ],
      "type": "object"
    },
    "SubordinationRank": {
      "description": "Subordination rank.",
      "enum": [
        "senior",
        "junior",
        "mezzanine",
        "equity"
      ],
      "type": "string"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/debt.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Debt instrument record per BDR 0068 §5.",
  "properties": {
    "agreement_ref": {
      "$ref": "#/$defs/PathRef",
      "description": "PathRef into `legal/contracts/<slug>` for the loan agreement."
    },
    "collateral": {
      "anyOf": [
        {
          "$ref": "#/$defs/Collateral"
        },
        {
          "type": "null"
        }
      ]
    },
    "convertible_doc_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef into BDR 0067 ConvertibleInstrumentDocument when this\ndebt is the debt-phase of a convertible."
    },
    "covenants": {
      "description": "PathRefs into covenant records.",
      "items": {
        "$ref": "#/$defs/PathRef"
      },
      "type": "array"
    },
    "currency": {
      "$ref": "#/$defs/IsoCurrency"
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "governing_law": {
      "$ref": "#/$defs/IsoCountry"
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "ifrs9_classification": {
      "anyOf": [
        {
          "$ref": "#/$defs/Ifrs9DebtClass"
        },
        {
          "type": "null"
        }
      ]
    },
    "instrument_type": {
      "$ref": "#/$defs/DebtInstrument"
    },
    "interest_rate": {
      "$ref": "#/$defs/InterestRate"
    },
    "lender": {
      "$ref": "#/$defs/PathRef"
    },
    "maturity_date": {
      "$ref": "#/$defs/IsoDate"
    },
    "name": {
      "type": "string"
    },
    "origination_date": {
      "$ref": "#/$defs/IsoDate"
    },
    "outstanding": {
      "$ref": "#/$defs/MonetaryAmount"
    },
    "payment_schedule": {
      "$ref": "#/$defs/PaymentSchedule"
    },
    "prepayment_terms": {
      "anyOf": [
        {
          "$ref": "#/$defs/PrepaymentTerms"
        },
        {
          "type": "null"
        }
      ]
    },
    "principal": {
      "$ref": "#/$defs/MonetaryAmount"
    },
    "status": {
      "$ref": "#/$defs/DebtStatus"
    },
    "subordination": {
      "anyOf": [
        {
          "$ref": "#/$defs/Subordination"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "entity",
    "name",
    "instrument_type",
    "principal",
    "outstanding",
    "currency",
    "lender",
    "origination_date",
    "maturity_date",
    "interest_rate",
    "payment_schedule",
    "governing_law",
    "agreement_ref",
    "status"
  ],
  "title": "Debt",
  "type": "object",
  "x-corpospec-pillar": "financials"
}