{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uwmd.org/schemas/lease-recovery-terms.schema.json",
  "title": "lease-recovery-terms",
  "description": "RFC 0081 G1 / Format §4.3. cap may be stated alone, without method, over or accumulation. method is required whenever any other member is stated non-null; a member stated as null is not stated. REC-02: once method is stated, a stated cap.pct requires cap.accumulation (no default). Method-dependent REC rules run only when method is stated. RFC0096 REC-11 owns only listed remaining typed leaves and extra closed members. Present method:null is REC-02; nullable companion nulls do not trigger method. M/P are own non-null presence, not successful method/pct admission.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "method": {
      "enum": [
        "net",
        "base_year_stop",
        "fixed_stop",
        "fixed_amount",
        "none"
      ]
    },
    "pro_rata_share": {
      "description": "Fraction in (0,1]. 0.0412 is 4.12%.",
      "type": [
        "number",
        "null"
      ],
      "exclusiveMinimum": 0,
      "maximum": 1
    },
    "share_basis": {
      "enum": [
        "nra",
        "gla",
        "stated",
        null
      ]
    },
    "base_year": {
      "type": [
        "integer",
        "null"
      ]
    },
    "expense_stop_per_sqft": {
      "type": [
        "number",
        "null"
      ],
      "minimum": 0
    },
    "fixed_recovery_annual": {
      "type": [
        "number",
        "null"
      ],
      "minimum": 0
    },
    "admin_fee_pct": {
      "type": [
        "number",
        "null"
      ],
      "minimum": 0,
      "exclusiveMaximum": 1
    },
    "gross_up_pct": {
      "description": "The occupancy the pool was grossed up TO. Recorded, never applied.",
      "type": [
        "number",
        "null"
      ],
      "exclusiveMinimum": 0,
      "maximum": 1
    },
    "recoverable_pool": {
      "type": [
        "array",
        "null"
      ],
      "minItems": 1,
      "items": {
        "type": "string"
      }
    },
    "cap": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "properties": {
        "pct": {
          "type": [
            "number",
            "null"
          ],
          "exclusiveMinimum": 0,
          "exclusiveMaximum": 1
        },
        "over": {
          "enum": [
            "base_year",
            "prior_year",
            null
          ]
        },
        "accumulation": {
          "description": "No default: the three treatments disagree.",
          "enum": [
            "cumulative",
            "non_cumulative",
            "compounding",
            null
          ]
        }
      }
    }
  },
  "dependentSchemas": {
    "pro_rata_share": {
      "if": {
        "properties": {
          "pro_rata_share": {
            "type": "null"
          }
        }
      },
      "else": {
        "required": [
          "method"
        ]
      }
    },
    "share_basis": {
      "if": {
        "properties": {
          "share_basis": {
            "type": "null"
          }
        }
      },
      "else": {
        "required": [
          "method"
        ]
      }
    },
    "base_year": {
      "if": {
        "properties": {
          "base_year": {
            "type": "null"
          }
        }
      },
      "else": {
        "required": [
          "method"
        ]
      }
    },
    "expense_stop_per_sqft": {
      "if": {
        "properties": {
          "expense_stop_per_sqft": {
            "type": "null"
          }
        }
      },
      "else": {
        "required": [
          "method"
        ]
      }
    },
    "fixed_recovery_annual": {
      "if": {
        "properties": {
          "fixed_recovery_annual": {
            "type": "null"
          }
        }
      },
      "else": {
        "required": [
          "method"
        ]
      }
    },
    "admin_fee_pct": {
      "if": {
        "properties": {
          "admin_fee_pct": {
            "type": "null"
          }
        }
      },
      "else": {
        "required": [
          "method"
        ]
      }
    },
    "gross_up_pct": {
      "if": {
        "properties": {
          "gross_up_pct": {
            "type": "null"
          }
        }
      },
      "else": {
        "required": [
          "method"
        ]
      }
    },
    "recoverable_pool": {
      "if": {
        "properties": {
          "recoverable_pool": {
            "type": "null"
          }
        }
      },
      "else": {
        "required": [
          "method"
        ]
      }
    }
  },
  "allOf": [
    {
      "description": "REC-02: own non-null method and own non-null cap.pct require non-null valid accumulation, even when method/pct is otherwise invalid. Otherwise accumulation remains optional nullable (REC-11 for invalid non-null).",
      "if": {
        "required": [
          "method",
          "cap"
        ],
        "properties": {
          "cap": {
            "type": "object",
            "required": [
              "pct"
            ],
            "properties": {
              "pct": {
                "not": {
                  "type": "null"
                }
              }
            }
          },
          "method": {
            "not": {
              "type": "null"
            }
          }
        }
      },
      "then": {
        "properties": {
          "cap": {
            "required": [
              "accumulation"
            ],
            "properties": {
              "accumulation": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  ]
}
