{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uwmd.org/schemas/pro-forma-report.schema.json",
  "title": "RFC0092 completed assessment",
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "status": {
          "const": "completed"
        },
        "profile": {
          "const": "pro-forma"
        },
        "level": {
          "const": "L1"
        },
        "selection": {
          "type": "object",
          "properties": {
            "operation": {
              "enum": [
                "source",
                "model"
              ]
            },
            "claim": {
              "type": "object",
              "properties": {
                "block_address_kind": {
                  "enum": [
                    "source",
                    "model"
                  ]
                },
                "block_address": {
                  "oneOf": [
                    {
                      "type": "integer",
                      "minimum": 0
                    },
                    {
                      "type": "array",
                      "items": {
                        "type": [
                          "string",
                          "integer"
                        ]
                      }
                    }
                  ]
                },
                "section_id": {
                  "type": "string"
                },
                "variant": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "target_pointer": {
                  "type": "string"
                },
                "period_key": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "loan_ref": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "block_address_kind",
                "block_address",
                "section_id",
                "variant",
                "target_pointer",
                "period_key",
                "loan_ref"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "operation",
            "claim"
          ],
          "additionalProperties": false
        },
        "assertions": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "key": {
                "type": "string"
              },
              "target": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "block_address_kind": {
                        "enum": [
                          "source",
                          "model"
                        ]
                      },
                      "block_address": {
                        "oneOf": [
                          {
                            "type": "integer",
                            "minimum": 0
                          },
                          {
                            "type": "array",
                            "items": {
                              "type": [
                                "string",
                                "integer"
                              ]
                            }
                          }
                        ]
                      },
                      "section_id": {
                        "type": "string"
                      },
                      "variant": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "target_pointer": {
                        "type": "string"
                      },
                      "period_key": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "loan_ref": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    },
                    "required": [
                      "block_address_kind",
                      "block_address",
                      "section_id",
                      "variant",
                      "target_pointer",
                      "period_key",
                      "loan_ref"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "address": {
                "$ref": "#/$defs/address"
              },
              "origins": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "row_family": {
                "enum": [
                  "growth",
                  "revenue",
                  "expenses",
                  "noi",
                  "ncf",
                  "debt_service",
                  "interest_principal",
                  "balance_balloon",
                  "dscr",
                  "debt_yield",
                  "ltv",
                  "exit",
                  "equity_sale_proceeds",
                  "cash_flows",
                  "irr",
                  "equity_multiple",
                  "cash_on_cash",
                  "npv",
                  "unclassified"
                ]
              },
              "stated": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "state": {
                "enum": [
                  "verified",
                  "failed",
                  "unverifiable"
                ]
              },
              "reasons": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "relationships": {
                "type": "array",
                "items": {
                  "type": "integer",
                  "minimum": 0
                }
              }
            },
            "required": [
              "key",
              "target",
              "address",
              "origins",
              "row_family",
              "stated",
              "state",
              "reasons",
              "relationships"
            ],
            "additionalProperties": false
          }
        },
        "relationships": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "assertion_key": {
                "type": "string"
              },
              "identity": {
                "type": "string"
              },
              "origins": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "declaration": {},
              "state": {
                "enum": [
                  "verified",
                  "failed",
                  "unverifiable"
                ]
              },
              "reason": {
                "type": "string"
              },
              "computed": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "local_state": {
                "enum": [
                  "verified",
                  "failed",
                  "unverifiable"
                ]
              },
              "findings": {
                "type": "array",
                "items": {}
              },
              "dependencies": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "assertion_key",
              "identity",
              "origins",
              "declaration",
              "state",
              "computed",
              "local_state",
              "findings",
              "dependencies"
            ],
            "additionalProperties": false
          }
        },
        "inputs": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "address": {
                "$ref": "#/$defs/address"
              },
              "target": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "block_address_kind": {
                        "enum": [
                          "source",
                          "model"
                        ]
                      },
                      "block_address": {
                        "oneOf": [
                          {
                            "type": "integer",
                            "minimum": 0
                          },
                          {
                            "type": "array",
                            "items": {
                              "type": [
                                "string",
                                "integer"
                              ]
                            }
                          }
                        ]
                      },
                      "section_id": {
                        "type": "string"
                      },
                      "variant": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "target_pointer": {
                        "type": "string"
                      },
                      "period_key": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "loan_ref": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    },
                    "required": [
                      "block_address_kind",
                      "block_address",
                      "section_id",
                      "variant",
                      "target_pointer",
                      "period_key",
                      "loan_ref"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "origins": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "row_family": {
                "enum": [
                  "growth",
                  "revenue",
                  "expenses",
                  "noi",
                  "ncf",
                  "debt_service",
                  "interest_principal",
                  "balance_balloon",
                  "dscr",
                  "debt_yield",
                  "ltv",
                  "exit",
                  "equity_sale_proceeds",
                  "cash_flows",
                  "irr",
                  "equity_multiple",
                  "cash_on_cash",
                  "npv",
                  "unclassified"
                ]
              },
              "reason": {
                "enum": [
                  "input",
                  "assumption"
                ]
              }
            },
            "required": [
              "address",
              "target",
              "origins",
              "row_family",
              "reason"
            ],
            "additionalProperties": false
          }
        },
        "input_count": {
          "type": "integer",
          "minimum": 0
        },
        "coverage": {
          "type": "object",
          "properties": {
            "total": {
              "type": "integer",
              "minimum": 0
            },
            "by_verdict": {
              "type": "object",
              "properties": {
                "verified": {
                  "type": "integer",
                  "minimum": 0
                },
                "failed": {
                  "type": "integer",
                  "minimum": 0
                },
                "unverifiable": {
                  "type": "integer",
                  "minimum": 0
                }
              },
              "required": [
                "verified",
                "failed",
                "unverifiable"
              ],
              "additionalProperties": false
            },
            "by_row_family": {
              "type": "object",
              "propertyNames": {
                "enum": [
                  "growth",
                  "revenue",
                  "expenses",
                  "noi",
                  "ncf",
                  "debt_service",
                  "interest_principal",
                  "balance_balloon",
                  "dscr",
                  "debt_yield",
                  "ltv",
                  "exit",
                  "equity_sale_proceeds",
                  "cash_flows",
                  "irr",
                  "equity_multiple",
                  "cash_on_cash",
                  "npv",
                  "unclassified"
                ]
              },
              "additionalProperties": {
                "type": "object",
                "properties": {
                  "total": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "verified": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "failed": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "unverifiable": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "required": [
                  "total",
                  "verified",
                  "failed",
                  "unverifiable"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "total",
            "by_verdict",
            "by_row_family"
          ],
          "additionalProperties": false
        },
        "gaps": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "event": {
                "$ref": "#/$defs/address"
              },
              "role": {
                "type": "string"
              },
              "required": {
                "type": "boolean"
              },
              "reason": {
                "type": "string"
              },
              "origins": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "event",
              "role",
              "required",
              "reason",
              "origins"
            ],
            "additionalProperties": false
          },
          "description": "RFC0128: role_conflict for an in-universe event bound under an undeclared role uses the declared member required flag and is not itself an out-of-universe profile error."
        },
        "exclusions": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "origin": {
                "type": "string"
              },
              "reason": {
                "type": "string"
              }
            },
            "required": [
              "origin",
              "reason"
            ],
            "additionalProperties": false
          }
        },
        "profile_claim_findings": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "severity": {
                "enum": [
                  "error",
                  "indeterminate"
                ]
              },
              "reason": {
                "type": "string"
              },
              "origins": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "error": {
                "$ref": "https://uwmd.org/schemas/protocol-error.schema.json"
              }
            },
            "required": [
              "code",
              "severity",
              "reason",
              "origins"
            ],
            "additionalProperties": false
          },
          "description": "Includes error-severity unsupported_registry even with zero rows; unknown claim members and unsupported global convention values complete as profile errors."
        },
        "validation": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "exit_code": {
          "enum": [
            0,
            1
          ]
        }
      },
      "required": [
        "status",
        "profile",
        "level",
        "selection",
        "assertions",
        "relationships",
        "inputs",
        "input_count",
        "coverage",
        "gaps",
        "exclusions",
        "profile_claim_findings",
        "validation",
        "exit_code"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "status": {
          "const": "refused"
        },
        "error": {
          "$ref": "https://uwmd.org/schemas/protocol-error.schema.json"
        }
      },
      "required": [
        "status",
        "error"
      ],
      "additionalProperties": false
    }
  ],
  "$defs": {
    "address": {
      "type": "object",
      "properties": {
        "section": {
          "type": "string",
          "minLength": 1
        },
        "variant": {
          "type": [
            "string",
            "null"
          ]
        },
        "pointer": {
          "type": "string",
          "pattern": "^(?:/.*)?$"
        }
      },
      "required": [
        "section",
        "variant",
        "pointer"
      ],
      "additionalProperties": false
    }
  }
}
