{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uwmd.org/schemas/property-cash-flow-plan.schema.json",
  "title": "property-cash-flow-plan",
  "description": "RFC 0045 / Protocol VIII.9.6. Shape validation; coverage, signs, dates, source verification and cross-field agreement require semantic checks.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "basis",
    "tax_basis",
    "currency_code",
    "day_count",
    "acquisition_date",
    "disposition_date",
    "lease_up",
    "supplemental",
    "assertions",
    "coverage"
  ],
  "properties": {
    "basis": {
      "const": "unlevered"
    },
    "tax_basis": {
      "const": "pre_tax"
    },
    "currency_code": {
      "type": "string",
      "pattern": "^[A-Z]{3}$"
    },
    "day_count": {
      "enum": [
        "actual/365f",
        "actual/360",
        "30/360us"
      ]
    },
    "acquisition_date": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
      "format": "date"
    },
    "disposition_date": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
      "format": "date"
    },
    "disposition_period_rule": {
      "type": "string",
      "enum": ["within_final_period", "allow_exclusive_end"],
      "description": "RFC 0063. Optional final-period admission rule; omission preserves legacy behavior. No default is materialized."
    },
    "lease_up": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_variant",
        "currency_code",
        "cash_dates"
      ],
      "properties": {
        "source_variant": {
          "type": "string",
          "minLength": 1
        },
        "currency_code": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "cash_dates": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "period",
              "date"
            ],
            "properties": {
              "period": {
                "type": "string",
                "pattern": "^\\d{4}-(Q[1-4]|0[1-9]|1[0-2])$"
              },
              "date": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                "format": "date"
              }
            }
          }
        }
      }
    },
    "supplemental": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_variant",
        "currency_code"
      ],
      "properties": {
        "source_variant": {
          "type": "string",
          "minLength": 1
        },
        "currency_code": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        }
      }
    },
    "assertions": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "cash_amounts_only",
        "no_financing_or_investor_tax",
        "no_overlapping_economic_amounts",
        "reserve_spending_excluded",
        "gross_sale_excludes_reserve_release",
        "no_terminal_restricted_reserve",
        "hold_only_and_exit_settled"
      ],
      "properties": {
        "cash_amounts_only": {
          "const": true
        },
        "no_financing_or_investor_tax": {
          "const": true
        },
        "no_overlapping_economic_amounts": {
          "const": true
        },
        "reserve_spending_excluded": {
          "const": true
        },
        "gross_sale_excludes_reserve_release": {
          "const": true
        },
        "no_terminal_restricted_reserve": {
          "const": true
        },
        "hold_only_and_exit_settled": {
          "const": true
        }
      }
    },
    "coverage": {
      "type": "array",
      "minItems": 1,
      "items": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "slot",
              "category",
              "rows"
            ],
            "properties": {
              "slot": {
                "type": "string",
                "pattern": "^(acquisition|disposition|\\d{4}-(Q[1-4]|0[1-9]|1[0-2]))$"
              },
              "category": {
                "enum": [
                  "rent",
                  "concessions",
                  "ti_lc",
                  "other_income",
                  "operating_expenses",
                  "other_capex",
                  "reserve_net",
                  "purchase_price",
                  "transaction_costs",
                  "gross_sale"
                ]
              },
              "rows": {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "uniqueItems": true
              }
            }
          },
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "slot",
              "category",
              "zero"
            ],
            "properties": {
              "slot": {
                "type": "string",
                "pattern": "^(acquisition|disposition|\\d{4}-(Q[1-4]|0[1-9]|1[0-2]))$"
              },
              "category": {
                "enum": [
                  "rent",
                  "concessions",
                  "ti_lc",
                  "other_income",
                  "operating_expenses",
                  "other_capex",
                  "reserve_net",
                  "purchase_price",
                  "transaction_costs",
                  "gross_sale"
                ]
              },
              "zero": {
                "type": "string",
                "pattern": "\\S"
              }
            }
          }
        ]
      }
    },
    "sale_deductions": {
      "description": "RFC 0052. Optional. When present it must name every row covering (disposition, transaction_costs); completeness, cell membership and the reserved-name refusal are semantic checks.",
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "row",
          "name"
        ],
        "properties": {
          "row": {
            "type": "integer",
            "minimum": 0
          },
          "name": {
            "enum": [
              "broker_commission",
              "transfer_tax",
              "title_and_escrow",
              "legal_and_closing",
              "seller_credits",
              "survey_and_diligence",
              "other",
              "prepayment_penalty",
              "defeasance",
              "loan_payoff"
            ]
          },
          "label": {
            "description": "Required when name is other; refused otherwise.",
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "net_sale_proceeds": {
      "description": "RFC 0052. Optional. A stated figure verified against gross sale less exit costs at the currency quantum; never derived.",
      "type": "number"
    }
  }
}
