{
  "$defs": {
    "CashFlowCategory": {
      "description": "Cash-flow categorisation per BDR 0068 §2.",
      "oneOf": [
        {
          "enum": [
            "customer_collections",
            "investor_proceeds",
            "debt_drawdown",
            "grant_receipt",
            "interest_income",
            "asset_sale",
            "payroll",
            "vendor_payment",
            "saas_subscription",
            "rent",
            "professional_services_fees",
            "tax_payment",
            "loan_repayment",
            "fx_revaluation",
            "intercompany_transfer",
            "dividend_paid",
            "share_repurchase",
            "insurance_premium",
            "marketing",
            "travel"
          ],
          "type": "string"
        },
        {
          "const": "custom",
          "description": "Free-text fall-through. Adopters can add a custom string for\nniche categories.",
          "type": "string"
        }
      ]
    },
    "CashFlowLine": {
      "description": "One forecasted cash-flow line within a period.",
      "properties": {
        "amount": {
          "format": "double",
          "type": "number"
        },
        "category": {
          "$ref": "#/$defs/CashFlowCategory"
        },
        "confidence": {
          "$ref": "#/$defs/Confidence"
        },
        "custom_label": {
          "description": "Custom category label when `category: Custom`.",
          "type": [
            "string",
            "null"
          ]
        },
        "driver_ref": {
          "anyOf": [
            {
              "$ref": "#/$defs/PathRef"
            },
            {
              "type": "null"
            }
          ],
          "description": "PathRef into the driver record (assumption, invoice, contract,\npayroll run)."
        }
      },
      "required": [
        "category",
        "amount",
        "confidence"
      ],
      "type": "object"
    },
    "Confidence": {
      "description": "Driver / assumption confidence.",
      "oneOf": [
        {
          "const": "high",
          "description": "Already invoiced / committed / contracted.",
          "type": "string"
        },
        {
          "const": "medium",
          "description": "Likely; based on pipeline / signed LOI.",
          "type": "string"
        },
        {
          "const": "low",
          "description": "Speculative.",
          "type": "string"
        }
      ]
    },
    "ConfidenceBand": {
      "description": "Confidence band on the forecast envelope (e.g. 80% confidence).",
      "properties": {
        "high_pct": {
          "format": "double",
          "type": "number"
        },
        "low_pct": {
          "format": "double",
          "type": "number"
        }
      },
      "required": [
        "low_pct",
        "high_pct"
      ],
      "type": "object"
    },
    "ForecastAssumption": {
      "description": "One named driver / assumption underlying the forecast.",
      "properties": {
        "description": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "source_ref": {
          "anyOf": [
            {
              "$ref": "#/$defs/PathRef"
            },
            {
              "type": "null"
            }
          ],
          "description": "PathRef into the source supporting the assumption (signed\ncontract, hiring plan, OKR)."
        },
        "value": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "description",
        "value"
      ],
      "type": "object"
    },
    "ForecastHorizon": {
      "description": "Forecast horizon.",
      "oneOf": [
        {
          "enum": [
            "monthly",
            "quarterly",
            "annual"
          ],
          "type": "string"
        },
        {
          "const": "thirteen_week",
          "description": "AFP-standard 13-week rolling treasury forecast.",
          "type": "string"
        }
      ]
    },
    "ForecastPeriod": {
      "description": "One period cell within the forecast horizon.",
      "properties": {
        "closing_cash": {
          "format": "double",
          "type": "number"
        },
        "date": {
          "$ref": "#/$defs/IsoDate"
        },
        "inflows": {
          "items": {
            "$ref": "#/$defs/CashFlowLine"
          },
          "type": "array"
        },
        "opening_cash": {
          "format": "double",
          "type": "number"
        },
        "outflows": {
          "items": {
            "$ref": "#/$defs/CashFlowLine"
          },
          "type": "array"
        },
        "restricted_carve_outs": {
          "description": "Cash earmarked / restricted in this period (escrow / tax-reserve\nflow-through).",
          "format": "double",
          "type": [
            "number",
            "null"
          ]
        }
      },
      "required": [
        "date",
        "opening_cash",
        "inflows",
        "outflows",
        "closing_cash"
      ],
      "type": "object"
    },
    "ForecastScenario": {
      "description": "Forecast scenario (base / downside / upside / custom).",
      "properties": {
        "drivers": {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "name": {
          "type": "string"
        },
        "probability": {
          "format": "double",
          "type": "number"
        }
      },
      "required": [
        "name",
        "probability",
        "drivers"
      ],
      "type": "object"
    },
    "Granularity": {
      "description": "Granularity of period cells within the forecast.",
      "enum": [
        "daily",
        "weekly",
        "monthly"
      ],
      "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"
    },
    "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"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/cash-forecast.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Cash forecast record per BDR 0068 §2.",
  "properties": {
    "as_of": {
      "$ref": "#/$defs/IsoDate"
    },
    "assumptions": {
      "items": {
        "$ref": "#/$defs/ForecastAssumption"
      },
      "type": "array"
    },
    "confidence_interval": {
      "anyOf": [
        {
          "$ref": "#/$defs/ConfidenceBand"
        },
        {
          "type": "null"
        }
      ]
    },
    "content_hash": {
      "type": "string"
    },
    "currency": {
      "$ref": "#/$defs/IsoCurrency"
    },
    "entity": {
      "$ref": "#/$defs/PathRef"
    },
    "granularity": {
      "$ref": "#/$defs/Granularity"
    },
    "horizon": {
      "$ref": "#/$defs/ForecastHorizon"
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "minimum_cash_breach_date": {
      "anyOf": [
        {
          "$ref": "#/$defs/IsoDate"
        },
        {
          "type": "null"
        }
      ]
    },
    "periods": {
      "items": {
        "$ref": "#/$defs/ForecastPeriod"
      },
      "type": "array"
    },
    "runway_months": {
      "format": "double",
      "type": [
        "number",
        "null"
      ]
    },
    "scenarios": {
      "items": {
        "$ref": "#/$defs/ForecastScenario"
      },
      "type": "array"
    },
    "source_position_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef into the CashPosition that anchored the forecast."
    },
    "superseded_by": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef into the successor forecast (forecasts are versioned)."
    }
  },
  "required": [
    "id",
    "entity",
    "horizon",
    "as_of",
    "currency",
    "granularity",
    "periods",
    "assumptions",
    "content_hash"
  ],
  "title": "CashForecast",
  "type": "object",
  "x-corpospec-pillar": "financials"
}