{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uwmd.org/schemas/property-cash-flow-assembly.schema.json",
  "title": "property-cash-flow-assembly",
  "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": [
    "source_envelope_digest",
    "plan",
    "coverage",
    "series",
    "bindings",
    "cells",
    "source_verification",
    "net_sale_proceeds"
  ],
  "properties": {
    "source_envelope_digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "plan": {
      "description": "The plan the assembler was given, copied verbatim. Referenced rather than restated so the two shapes cannot drift.",
      "$ref": "https://uwmd.org/schemas/property-cash-flow-plan.schema.json"
    },
    "coverage": {
      "const": "declared_complete"
    },
    "series": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "label",
        "day_count",
        "series"
      ],
      "properties": {
        "label": {
          "const": "Unlevered pre-tax property cash flow"
        },
        "day_count": {
          "enum": [
            "actual/365f",
            "actual/360",
            "30/360us"
          ]
        },
        "series": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "date",
              "amount",
              "kind",
              "label"
            ],
            "properties": {
              "date": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
                "format": "date"
              },
              "amount": {
                "type": "number"
              },
              "kind": {
                "const": "other"
              },
              "label": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        }
      }
    },
    "bindings": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "output_row_index",
          "source_section",
          "source_variant",
          "source_path",
          "date",
          "amount",
          "cells"
        ],
        "properties": {
          "output_row_index": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "source_section": {
            "enum": [
              "lease_up_schedule",
              "cash_flow_series"
            ]
          },
          "source_variant": {
            "type": "string",
            "minLength": 1
          },
          "source_path": {
            "type": "string",
            "minLength": 1
          },
          "date": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
            "format": "date"
          },
          "amount": {
            "type": "number"
          },
          "cells": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "slot",
                "category"
              ],
              "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"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "cells": {
      "type": "array",
      "minItems": 1,
      "items": {
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "slot",
              "category",
              "output_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"
                ]
              },
              "output_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"
              }
            }
          }
        ]
      }
    },
    "source_verification": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "lease_up",
        "supplemental_metrics"
      ],
      "properties": {
        "lease_up": {
          "const": "verified"
        },
        "supplemental_metrics": {
          "enum": [
            "verified",
            "not_stated"
          ]
        }
      }
    },
    "sale_deductions": {
      "description": "RFC 0052. Present only when the plan named its deductions, in output-row order.",
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "output_row_index",
          "name",
          "amount"
        ],
        "properties": {
          "output_row_index": {
            "type": "integer",
            "minimum": 0
          },
          "name": {
            "enum": [
              "broker_commission",
              "transfer_tax",
              "title_and_escrow",
              "legal_and_closing",
              "seller_credits",
              "survey_and_diligence",
              "other"
            ]
          },
          "label": {
            "type": "string",
            "minLength": 1
          },
          "amount": {
            "type": "number"
          }
        }
      }
    },
    "net_sale_proceeds": {
      "description": "RFC 0052. Evidence about a stated figure, not proof the exit is complete.",
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "status",
            "stated",
            "computed"
          ],
          "properties": {
            "status": {
              "const": "verified"
            },
            "stated": {
              "type": "number"
            },
            "computed": {
              "type": "number"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "status"
          ],
          "properties": {
            "status": {
              "const": "not_stated"
            }
          }
        }
      ]
    }
  }
}
