{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uwmd.org/schemas/renovation-draw.schema.json",
  "title": "renovation-draw",
  "description": "RFC 0081 G1 / Format §4.8. At least budget or contingency; draw group all-or-none and requires both. contingency_remaining only with draw group. CAPX-01 validates stated members; CAPX-02–04 evaluate only with draw group. A member stated as null is not stated: contingency_remaining: null needs no draw group.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "budget": {
      "description": "Hard plus soft costs, excluding the contingency.",
      "type": "number",
      "minimum": 0
    },
    "contingency": {
      "type": "number",
      "minimum": 0
    },
    "contingency_used": {
      "description": "Drawn from the contingency to date. Never exceeds contingency (CAPX-02).",
      "type": "number",
      "minimum": 0
    },
    "contingency_remaining": {
      "description": "Stated and verified against contingency less contingency_used, rather than left to every reader's subtraction.",
      "type": [
        "number",
        "null"
      ]
    },
    "drawn_to_date": {
      "description": "Total drawn, the budget line plus the contingency draw.",
      "type": "number",
      "minimum": 0
    },
    "as_of_date": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
      "format": "date"
    },
    "expense_targeted": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "https://uwmd.org/schemas/expense-targeted-capex.schema.json"
      }
    }
  },
  "anyOf": [
    {
      "required": [
        "budget"
      ]
    },
    {
      "required": [
        "contingency"
      ]
    }
  ],
  "dependentRequired": {
    "contingency_used": [
      "drawn_to_date",
      "as_of_date",
      "budget",
      "contingency"
    ],
    "drawn_to_date": [
      "contingency_used",
      "as_of_date",
      "budget",
      "contingency"
    ],
    "as_of_date": [
      "contingency_used",
      "drawn_to_date",
      "budget",
      "contingency"
    ]
  },
  "dependentSchemas": {
    "contingency_remaining": {
      "if": {
        "properties": {
          "contingency_remaining": {
            "type": "null"
          }
        }
      },
      "else": {
        "required": [
          "contingency_used",
          "drawn_to_date",
          "as_of_date",
          "budget",
          "contingency"
        ]
      }
    }
  }
}
