{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "ModelDefinition": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "version": {
          "const": "1",
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "inputs": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "minimum": {
                "type": "number"
              },
              "maximum": {
                "type": "number"
              },
              "exclusiveMinimum": {
                "anyOf": [
                  {
                    "const": false,
                    "type": "boolean"
                  },
                  {
                    "const": true,
                    "type": "boolean"
                  }
                ]
              },
              "exclusiveMaximum": {
                "anyOf": [
                  {
                    "const": false,
                    "type": "boolean"
                  },
                  {
                    "const": true,
                    "type": "boolean"
                  }
                ]
              },
              "unit": {
                "anyOf": [
                  {
                    "const": "money",
                    "type": "string"
                  },
                  {
                    "const": "hours",
                    "type": "string"
                  },
                  {
                    "const": "ratio",
                    "type": "string"
                  }
                ]
              }
            },
            "required": [
              "title",
              "description",
              "minimum",
              "maximum",
              "unit"
            ],
            "additionalProperties": false
          }
        },
        "outputs": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string"
              },
              "format": {
                "anyOf": [
                  {
                    "const": "number",
                    "type": "string"
                  },
                  {
                    "const": "currency",
                    "type": "string"
                  },
                  {
                    "const": "percent",
                    "type": "string"
                  }
                ]
              },
              "round": {
                "anyOf": [
                  {
                    "const": "up",
                    "type": "string"
                  },
                  {
                    "const": "down",
                    "type": "string"
                  }
                ]
              }
            },
            "required": [
              "title",
              "format"
            ],
            "additionalProperties": false
          }
        },
        "formulas": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "example": {
          "type": "object",
          "additionalProperties": {
            "type": "number"
          }
        },
        "assumptions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "limits": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "variants": {
                  "type": "number"
                },
                "request_bytes": {
                  "type": "number"
                },
                "bundle_bytes": {
                  "type": "number"
                }
              },
              "required": [
                "variants",
                "request_bytes",
                "bundle_bytes"
              ],
              "additionalProperties": false
            }
          ]
        },
        "input_schema": {
          "anyOf": [
            {
              "type": "object",
              "additionalProperties": {}
            }
          ]
        }
      },
      "required": [
        "id",
        "version",
        "title",
        "description",
        "inputs",
        "outputs",
        "formulas",
        "example",
        "assumptions"
      ],
      "additionalProperties": false
    },
    "RunRequest": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "model",
            "model_version",
            "currency",
            "inputs"
          ],
          "additionalProperties": false,
          "properties": {
            "model": {
              "const": "project_quote_margin"
            },
            "model_version": {
              "const": "1"
            },
            "currency": {
              "enum": [
                "EUR",
                "USD",
                "GBP"
              ]
            },
            "inputs": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "quote",
                "hours",
                "loaded_hourly_cost",
                "external_costs",
                "target_margin"
              ],
              "properties": {
                "quote": {
                  "type": "number",
                  "description": "Quoted revenue, in the run's currency.",
                  "exclusiveMinimum": 0,
                  "maximum": 10000000,
                  "multipleOf": 0.01
                },
                "hours": {
                  "type": "number",
                  "description": "Delivery hours; include all delivery time.",
                  "minimum": 0,
                  "maximum": 10000,
                  "multipleOf": 0.01
                },
                "loaded_hourly_cost": {
                  "type": "number",
                  "description": "Loaded labor cost per hour, in the run's currency.",
                  "minimum": 0,
                  "maximum": 10000000,
                  "multipleOf": 0.01
                },
                "external_costs": {
                  "type": "number",
                  "description": "External costs, in the run's currency.",
                  "minimum": 0,
                  "maximum": 10000000,
                  "multipleOf": 0.01
                },
                "target_margin": {
                  "type": "number",
                  "description": "Target margin as a fraction: 0.30 means 30%.",
                  "minimum": 0,
                  "maximum": 0.99
                }
              }
            },
            "variants": {
              "type": "array",
              "maxItems": 5,
              "items": {
                "type": "object",
                "required": [
                  "name",
                  "overrides"
                ],
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "overrides": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [],
                    "properties": {
                      "quote": {
                        "type": "number",
                        "description": "Quoted revenue, in the run's currency.",
                        "exclusiveMinimum": 0,
                        "maximum": 10000000,
                        "multipleOf": 0.01
                      },
                      "hours": {
                        "type": "number",
                        "description": "Delivery hours; include all delivery time.",
                        "minimum": 0,
                        "maximum": 10000,
                        "multipleOf": 0.01
                      },
                      "loaded_hourly_cost": {
                        "type": "number",
                        "description": "Loaded labor cost per hour, in the run's currency.",
                        "minimum": 0,
                        "maximum": 10000000,
                        "multipleOf": 0.01
                      },
                      "external_costs": {
                        "type": "number",
                        "description": "External costs, in the run's currency.",
                        "minimum": 0,
                        "maximum": 10000000,
                        "multipleOf": 0.01
                      },
                      "target_margin": {
                        "type": "number",
                        "description": "Target margin as a fraction: 0.30 means 30%.",
                        "minimum": 0,
                        "maximum": 0.99
                      }
                    }
                  }
                }
              }
            },
            "include": {
              "type": "array",
              "uniqueItems": true,
              "maxItems": 2,
              "items": {
                "enum": [
                  "formulas",
                  "document_bundle"
                ]
              }
            }
          }
        },
        {
          "type": "object",
          "required": [
            "model",
            "model_version",
            "currency",
            "inputs"
          ],
          "additionalProperties": false,
          "properties": {
            "model": {
              "const": "contracting_hourly_rate"
            },
            "model_version": {
              "const": "1"
            },
            "currency": {
              "enum": [
                "EUR",
                "USD",
                "GBP"
              ]
            },
            "inputs": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "desired_net_monthly",
                "business_costs_monthly",
                "tax_rate",
                "billable_hours_monthly",
                "nonbillable_hours_monthly"
              ],
              "properties": {
                "desired_net_monthly": {
                  "type": "number",
                  "description": "Desired net monthly income, in the run's currency.",
                  "exclusiveMinimum": 0,
                  "maximum": 10000000,
                  "multipleOf": 0.01
                },
                "business_costs_monthly": {
                  "type": "number",
                  "description": "Monthly business costs, in the run's currency.",
                  "minimum": 0,
                  "maximum": 10000000,
                  "multipleOf": 0.01
                },
                "tax_rate": {
                  "type": "number",
                  "description": "Assumed tax rate as a fraction: 0.30 means 30%.",
                  "minimum": 0,
                  "maximum": 0.99
                },
                "billable_hours_monthly": {
                  "type": "number",
                  "description": "Monthly billable hours; include all delivery time.",
                  "exclusiveMinimum": 0,
                  "maximum": 10000,
                  "multipleOf": 0.01
                },
                "nonbillable_hours_monthly": {
                  "type": "number",
                  "description": "Monthly non-billable hours; include all delivery time.",
                  "minimum": 0,
                  "maximum": 10000,
                  "multipleOf": 0.01
                }
              }
            },
            "variants": {
              "type": "array",
              "maxItems": 5,
              "items": {
                "type": "object",
                "required": [
                  "name",
                  "overrides"
                ],
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "overrides": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [],
                    "properties": {
                      "desired_net_monthly": {
                        "type": "number",
                        "description": "Desired net monthly income, in the run's currency.",
                        "exclusiveMinimum": 0,
                        "maximum": 10000000,
                        "multipleOf": 0.01
                      },
                      "business_costs_monthly": {
                        "type": "number",
                        "description": "Monthly business costs, in the run's currency.",
                        "minimum": 0,
                        "maximum": 10000000,
                        "multipleOf": 0.01
                      },
                      "tax_rate": {
                        "type": "number",
                        "description": "Assumed tax rate as a fraction: 0.30 means 30%.",
                        "minimum": 0,
                        "maximum": 0.99
                      },
                      "billable_hours_monthly": {
                        "type": "number",
                        "description": "Monthly billable hours; include all delivery time.",
                        "exclusiveMinimum": 0,
                        "maximum": 10000,
                        "multipleOf": 0.01
                      },
                      "nonbillable_hours_monthly": {
                        "type": "number",
                        "description": "Monthly non-billable hours; include all delivery time.",
                        "minimum": 0,
                        "maximum": 10000,
                        "multipleOf": 0.01
                      }
                    }
                  }
                }
              }
            },
            "include": {
              "type": "array",
              "uniqueItems": true,
              "maxItems": 2,
              "items": {
                "enum": [
                  "formulas",
                  "document_bundle"
                ]
              }
            }
          }
        },
        {
          "type": "object",
          "required": [
            "model",
            "model_version",
            "currency",
            "inputs"
          ],
          "additionalProperties": false,
          "properties": {
            "model": {
              "const": "retainer_capacity"
            },
            "model_version": {
              "const": "1"
            },
            "currency": {
              "enum": [
                "EUR",
                "USD",
                "GBP"
              ]
            },
            "inputs": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "monthly_fee",
                "delivery_hours",
                "loaded_hourly_cost",
                "external_costs",
                "target_margin"
              ],
              "properties": {
                "monthly_fee": {
                  "type": "number",
                  "description": "Monthly fee, in the run's currency.",
                  "exclusiveMinimum": 0,
                  "maximum": 10000000,
                  "multipleOf": 0.01
                },
                "delivery_hours": {
                  "type": "number",
                  "description": "Monthly delivery hours; include all delivery time.",
                  "exclusiveMinimum": 0,
                  "maximum": 10000,
                  "multipleOf": 0.01
                },
                "loaded_hourly_cost": {
                  "type": "number",
                  "description": "Loaded labor cost per hour, in the run's currency.",
                  "exclusiveMinimum": 0,
                  "maximum": 10000000,
                  "multipleOf": 0.01
                },
                "external_costs": {
                  "type": "number",
                  "description": "Monthly external costs, in the run's currency.",
                  "minimum": 0,
                  "maximum": 10000000,
                  "multipleOf": 0.01
                },
                "target_margin": {
                  "type": "number",
                  "description": "Target margin as a fraction: 0.30 means 30%.",
                  "minimum": 0,
                  "maximum": 0.99
                }
              }
            },
            "variants": {
              "type": "array",
              "maxItems": 5,
              "items": {
                "type": "object",
                "required": [
                  "name",
                  "overrides"
                ],
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "overrides": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [],
                    "properties": {
                      "monthly_fee": {
                        "type": "number",
                        "description": "Monthly fee, in the run's currency.",
                        "exclusiveMinimum": 0,
                        "maximum": 10000000,
                        "multipleOf": 0.01
                      },
                      "delivery_hours": {
                        "type": "number",
                        "description": "Monthly delivery hours; include all delivery time.",
                        "exclusiveMinimum": 0,
                        "maximum": 10000,
                        "multipleOf": 0.01
                      },
                      "loaded_hourly_cost": {
                        "type": "number",
                        "description": "Loaded labor cost per hour, in the run's currency.",
                        "exclusiveMinimum": 0,
                        "maximum": 10000000,
                        "multipleOf": 0.01
                      },
                      "external_costs": {
                        "type": "number",
                        "description": "Monthly external costs, in the run's currency.",
                        "minimum": 0,
                        "maximum": 10000000,
                        "multipleOf": 0.01
                      },
                      "target_margin": {
                        "type": "number",
                        "description": "Target margin as a fraction: 0.30 means 30%.",
                        "minimum": 0,
                        "maximum": 0.99
                      }
                    }
                  }
                }
              }
            },
            "include": {
              "type": "array",
              "uniqueItems": true,
              "maxItems": 2,
              "items": {
                "enum": [
                  "formulas",
                  "document_bundle"
                ]
              }
            }
          }
        }
      ]
    },
    "RunResult": {
      "type": "object",
      "properties": {
        "run_id": {
          "type": "string"
        },
        "created_at": {
          "type": "string"
        },
        "model": {
          "type": "string"
        },
        "model_version": {
          "const": "1",
          "type": "string"
        },
        "engine_version": {
          "type": "string"
        },
        "currency": {
          "anyOf": [
            {
              "const": "EUR",
              "type": "string"
            },
            {
              "const": "USD",
              "type": "string"
            },
            {
              "const": "GBP",
              "type": "string"
            }
          ]
        },
        "cases": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "inputs": {
                "type": "object",
                "additionalProperties": {
                  "type": "number"
                }
              },
              "metrics": {
                "type": "object",
                "additionalProperties": {
                  "type": "number"
                }
              },
              "differences": {
                "type": "object",
                "additionalProperties": {
                  "type": "number"
                }
              },
              "checks": {
                "type": "object",
                "additionalProperties": {
                  "anyOf": [
                    {
                      "const": false,
                      "type": "boolean"
                    },
                    {
                      "const": true,
                      "type": "boolean"
                    }
                  ]
                }
              },
              "warnings": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "name",
              "inputs",
              "metrics",
              "differences",
              "checks",
              "warnings"
            ],
            "additionalProperties": false
          }
        },
        "formulas": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          ]
        },
        "document_bundle": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "format": {
                  "const": "continuum-api-review",
                  "type": "string"
                },
                "version": {
                  "const": 1,
                  "type": "number"
                },
                "engine_version": {
                  "type": "string"
                },
                "request": {
                  "type": "object",
                  "properties": {
                    "model": {
                      "type": "string"
                    },
                    "model_version": {
                      "const": "1",
                      "type": "string"
                    },
                    "currency": {
                      "anyOf": [
                        {
                          "const": "EUR",
                          "type": "string"
                        },
                        {
                          "const": "USD",
                          "type": "string"
                        },
                        {
                          "const": "GBP",
                          "type": "string"
                        }
                      ]
                    },
                    "inputs": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "number"
                      }
                    },
                    "variants": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "overrides": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "number"
                            }
                          }
                        },
                        "required": [
                          "name",
                          "overrides"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "include": {
                      "type": "array",
                      "items": {
                        "anyOf": [
                          {
                            "const": "formulas",
                            "type": "string"
                          },
                          {
                            "const": "document_bundle",
                            "type": "string"
                          }
                        ]
                      }
                    }
                  },
                  "required": [
                    "model",
                    "model_version",
                    "currency",
                    "inputs",
                    "variants",
                    "include"
                  ],
                  "additionalProperties": false
                },
                "created_at": {
                  "type": "string"
                },
                "run_id": {
                  "type": "string"
                },
                "edited": {
                  "anyOf": [
                    {
                      "const": false,
                      "type": "boolean"
                    },
                    {
                      "const": true,
                      "type": "boolean"
                    }
                  ]
                },
                "documents": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "recipe": {
                        "type": "object",
                        "properties": {
                          "version": {
                            "const": 1,
                            "type": "number"
                          },
                          "title": {
                            "type": "string"
                          },
                          "calculationSource": {
                            "type": "string"
                          },
                          "preview": {
                            "type": "object",
                            "properties": {
                              "version": {
                                "const": 1,
                                "type": "number"
                              },
                              "title": {
                                "type": "string"
                              },
                              "blocks": {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "id": {
                                      "anyOf": [
                                        {
                                          "type": "string"
                                        }
                                      ]
                                    },
                                    "kind": {
                                      "anyOf": [
                                        {
                                          "const": "comparison_cards",
                                          "type": "string"
                                        },
                                        {
                                          "const": "metric_strip",
                                          "type": "string"
                                        },
                                        {
                                          "const": "projection_timeline",
                                          "type": "string"
                                        },
                                        {
                                          "const": "risk_resilience",
                                          "type": "string"
                                        },
                                        {
                                          "const": "readiness_clarity",
                                          "type": "string"
                                        },
                                        {
                                          "const": "summary",
                                          "type": "string"
                                        },
                                        {
                                          "const": "conclusion",
                                          "type": "string"
                                        }
                                      ]
                                    },
                                    "priority": {
                                      "anyOf": [
                                        {
                                          "const": "primary",
                                          "type": "string"
                                        },
                                        {
                                          "const": "secondary",
                                          "type": "string"
                                        },
                                        {
                                          "const": "supporting",
                                          "type": "string"
                                        }
                                      ]
                                    },
                                    "data": {}
                                  },
                                  "required": [
                                    "kind",
                                    "data"
                                  ],
                                  "additionalProperties": false
                                }
                              }
                            },
                            "required": [
                              "version",
                              "title",
                              "blocks"
                            ],
                            "additionalProperties": false
                          }
                        },
                        "required": [
                          "version",
                          "title",
                          "calculationSource",
                          "preview"
                        ],
                        "additionalProperties": false
                      },
                      "source": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "name",
                      "recipe",
                      "source"
                    ],
                    "additionalProperties": false
                  }
                }
              },
              "required": [
                "format",
                "version",
                "engine_version",
                "request",
                "created_at",
                "run_id",
                "edited",
                "documents"
              ],
              "additionalProperties": false
            }
          ]
        }
      },
      "required": [
        "run_id",
        "created_at",
        "model",
        "model_version",
        "engine_version",
        "currency",
        "cases"
      ],
      "additionalProperties": false
    },
    "ReviewBundle": {
      "type": "object",
      "properties": {
        "format": {
          "const": "continuum-api-review",
          "type": "string"
        },
        "version": {
          "const": 1,
          "type": "number"
        },
        "engine_version": {
          "type": "string"
        },
        "request": {
          "type": "object",
          "properties": {
            "model": {
              "type": "string"
            },
            "model_version": {
              "const": "1",
              "type": "string"
            },
            "currency": {
              "anyOf": [
                {
                  "const": "EUR",
                  "type": "string"
                },
                {
                  "const": "USD",
                  "type": "string"
                },
                {
                  "const": "GBP",
                  "type": "string"
                }
              ]
            },
            "inputs": {
              "type": "object",
              "additionalProperties": {
                "type": "number"
              }
            },
            "variants": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "overrides": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "number"
                    }
                  }
                },
                "required": [
                  "name",
                  "overrides"
                ],
                "additionalProperties": false
              }
            },
            "include": {
              "type": "array",
              "items": {
                "anyOf": [
                  {
                    "const": "formulas",
                    "type": "string"
                  },
                  {
                    "const": "document_bundle",
                    "type": "string"
                  }
                ]
              }
            }
          },
          "required": [
            "model",
            "model_version",
            "currency",
            "inputs",
            "variants",
            "include"
          ],
          "additionalProperties": false
        },
        "created_at": {
          "type": "string"
        },
        "run_id": {
          "type": "string"
        },
        "edited": {
          "anyOf": [
            {
              "const": false,
              "type": "boolean"
            },
            {
              "const": true,
              "type": "boolean"
            }
          ]
        },
        "documents": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "recipe": {
                "type": "object",
                "properties": {
                  "version": {
                    "const": 1,
                    "type": "number"
                  },
                  "title": {
                    "type": "string"
                  },
                  "calculationSource": {
                    "type": "string"
                  },
                  "preview": {
                    "type": "object",
                    "properties": {
                      "version": {
                        "const": 1,
                        "type": "number"
                      },
                      "title": {
                        "type": "string"
                      },
                      "blocks": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "anyOf": [
                                {
                                  "type": "string"
                                }
                              ]
                            },
                            "kind": {
                              "anyOf": [
                                {
                                  "const": "comparison_cards",
                                  "type": "string"
                                },
                                {
                                  "const": "metric_strip",
                                  "type": "string"
                                },
                                {
                                  "const": "projection_timeline",
                                  "type": "string"
                                },
                                {
                                  "const": "risk_resilience",
                                  "type": "string"
                                },
                                {
                                  "const": "readiness_clarity",
                                  "type": "string"
                                },
                                {
                                  "const": "summary",
                                  "type": "string"
                                },
                                {
                                  "const": "conclusion",
                                  "type": "string"
                                }
                              ]
                            },
                            "priority": {
                              "anyOf": [
                                {
                                  "const": "primary",
                                  "type": "string"
                                },
                                {
                                  "const": "secondary",
                                  "type": "string"
                                },
                                {
                                  "const": "supporting",
                                  "type": "string"
                                }
                              ]
                            },
                            "data": {}
                          },
                          "required": [
                            "kind",
                            "data"
                          ],
                          "additionalProperties": false
                        }
                      }
                    },
                    "required": [
                      "version",
                      "title",
                      "blocks"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "version",
                  "title",
                  "calculationSource",
                  "preview"
                ],
                "additionalProperties": false
              },
              "source": {
                "type": "string"
              }
            },
            "required": [
              "name",
              "recipe",
              "source"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "format",
        "version",
        "engine_version",
        "request",
        "created_at",
        "run_id",
        "edited",
        "documents"
      ],
      "additionalProperties": false
    },
    "ApiErrorPayload": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "code": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "field": {
              "anyOf": [
                {
                  "type": "string"
                }
              ]
            }
          },
          "required": [
            "code",
            "message"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "error"
      ],
      "additionalProperties": false
    }
  }
}
