{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.calculatorx.com/schemas/engineering.tolerance.stackup.output.json",
  "title": "Tolerance stack-up — success output",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "status",
    "capability_id",
    "engine",
    "inputs",
    "result",
    "result_detail",
    "calculation_version",
    "verification"
  ],
  "properties": {
    "id": {
      "type": "string",
      "description": "Requested tool id"
    },
    "status": {
      "const": "success"
    },
    "capability_id": {
      "const": "engineering.tolerance.stackup"
    },
    "tool": {
      "type": "string",
      "description": "Requested tool id"
    },
    "engine": {
      "type": "string"
    },
    "inputs": {
      "type": "object",
      "description": "Normalized calculation inputs (aliases resolved)"
    },
    "result": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "profile",
        "n",
        "tol",
        "stack",
        "stack_rss",
        "stack_worst",
        "stack_worst_plus",
        "stack_worst_minus",
        "stack_range",
        "stack_half_range",
        "stack_nom",
        "stack_stat_center",
        "stack_center_shift",
        "stack_min",
        "stack_max",
        "rss_over_wca",
        "dimensions"
      ],
      "properties": {
        "mode": {
          "type": "string"
        },
        "profile": {
          "type": "string",
          "enum": [
            "basic",
            "engineering"
          ]
        },
        "n": {
          "type": "integer"
        },
        "tol": {
          "type": "array",
          "items": {
            "type": "number"
          }
        },
        "stack": {
          "type": "number"
        },
        "stack_rss": {
          "type": "number"
        },
        "stack_worst": {
          "type": "number",
          "description": "Scalar worst-case = max(stack_worst_plus, stack_worst_minus). Equals half-range only when tolerances are symmetric about nominal."
        },
        "stack_worst_plus": {
          "type": "number",
          "description": "stack_max − stack_nom (Engineering); equals stack_worst in Basic"
        },
        "stack_worst_minus": {
          "type": "number",
          "description": "stack_nom − stack_min (Engineering); equals stack_worst in Basic"
        },
        "stack_range": {
          "type": "number",
          "description": "stack_max − stack_min = worst_plus + worst_minus"
        },
        "stack_half_range": {
          "type": "number",
          "description": "stack_range / 2 — not the same as stack_worst when asymmetric"
        },
        "stack_nom": {
          "type": [
            "number",
            "null"
          ]
        },
        "stack_stat_center": {
          "type": [
            "number",
            "null"
          ],
          "description": "Engineering: signed stack using uniform midpoints where statistical_basis=uniform; equals stack_nom otherwise. Basic: null"
        },
        "stack_center_shift": {
          "type": [
            "number",
            "null"
          ],
          "description": "stack_stat_center − stack_nom (Engineering); Basic: null"
        },
        "stack_min": {
          "type": [
            "number",
            "null"
          ]
        },
        "stack_max": {
          "type": [
            "number",
            "null"
          ]
        },
        "rss_over_wca": {
          "type": [
            "number",
            "null"
          ]
        },
        "dimensions": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "name": {
                "type": "string"
              },
              "nom": {
                "type": "number"
              },
              "tol_plus": {
                "type": "number"
              },
              "tol_minus": {
                "type": "number"
              },
              "direction": {
                "type": "string"
              },
              "statistical_basis": {
                "type": "string",
                "enum": [
                  "magnitude",
                  "1sigma",
                  "3sigma",
                  "uniform"
                ]
              },
              "distribution": {
                "type": "string",
                "description": "Legacy mirror of statistical_basis"
              },
              "signed_nom": {
                "type": "number"
              },
              "center_shift": {
                "type": "number",
                "description": "Physical midpoint − nominal; non-zero only for uniform asymmetric ±tol"
              },
              "signed_center": {
                "type": "number",
                "description": "direction × (nom + center_shift)"
              },
              "delta_max": {
                "type": "number"
              },
              "delta_min": {
                "type": "number"
              },
              "tol_rss": {
                "type": "number"
              }
            }
          }
        }
      }
    },
    "result_detail": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "value",
        "unit",
        "formatted"
      ],
      "properties": {
        "value": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode",
            "profile",
            "n",
            "tol",
            "stack",
            "stack_rss",
            "stack_worst",
            "stack_worst_plus",
            "stack_worst_minus",
            "stack_range",
            "stack_half_range",
            "stack_nom",
            "stack_stat_center",
            "stack_center_shift",
            "stack_min",
            "stack_max",
            "rss_over_wca",
            "dimensions"
          ],
          "properties": {
            "mode": {
              "type": "string"
            },
            "profile": {
              "type": "string",
              "enum": [
                "basic",
                "engineering"
              ]
            },
            "n": {
              "type": "integer"
            },
            "tol": {
              "type": "array",
              "items": {
                "type": "number"
              }
            },
            "stack": {
              "type": "number"
            },
            "stack_rss": {
              "type": "number"
            },
            "stack_worst": {
              "type": "number",
              "description": "Scalar worst-case = max(stack_worst_plus, stack_worst_minus). Equals half-range only when tolerances are symmetric about nominal."
            },
            "stack_worst_plus": {
              "type": "number",
              "description": "stack_max − stack_nom (Engineering); equals stack_worst in Basic"
            },
            "stack_worst_minus": {
              "type": "number",
              "description": "stack_nom − stack_min (Engineering); equals stack_worst in Basic"
            },
            "stack_range": {
              "type": "number",
              "description": "stack_max − stack_min = worst_plus + worst_minus"
            },
            "stack_half_range": {
              "type": "number",
              "description": "stack_range / 2 — not the same as stack_worst when asymmetric"
            },
            "stack_nom": {
              "type": [
                "number",
                "null"
              ]
            },
            "stack_stat_center": {
              "type": [
                "number",
                "null"
              ],
              "description": "Engineering: signed stack using uniform midpoints where statistical_basis=uniform; equals stack_nom otherwise. Basic: null"
            },
            "stack_center_shift": {
              "type": [
                "number",
                "null"
              ],
              "description": "stack_stat_center − stack_nom (Engineering); Basic: null"
            },
            "stack_min": {
              "type": [
                "number",
                "null"
              ]
            },
            "stack_max": {
              "type": [
                "number",
                "null"
              ]
            },
            "rss_over_wca": {
              "type": [
                "number",
                "null"
              ]
            },
            "dimensions": {
              "type": [
                "array",
                "null"
              ],
              "items": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "nom": {
                    "type": "number"
                  },
                  "tol_plus": {
                    "type": "number"
                  },
                  "tol_minus": {
                    "type": "number"
                  },
                  "direction": {
                    "type": "string"
                  },
                  "statistical_basis": {
                    "type": "string",
                    "enum": [
                      "magnitude",
                      "1sigma",
                      "3sigma",
                      "uniform"
                    ]
                  },
                  "distribution": {
                    "type": "string",
                    "description": "Legacy mirror of statistical_basis"
                  },
                  "signed_nom": {
                    "type": "number"
                  },
                  "center_shift": {
                    "type": "number",
                    "description": "Physical midpoint − nominal; non-zero only for uniform asymmetric ±tol"
                  },
                  "signed_center": {
                    "type": "number",
                    "description": "direction × (nom + center_shift)"
                  },
                  "delta_max": {
                    "type": "number"
                  },
                  "delta_min": {
                    "type": "number"
                  },
                  "tol_rss": {
                    "type": "number"
                  }
                }
              }
            }
          }
        },
        "unit": {
          "type": [
            "string",
            "null"
          ]
        },
        "formatted": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "formula": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "type": "string"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string"
            },
            "expression": {
              "type": "string"
            },
            "label": {
              "type": "string"
            }
          }
        }
      ]
    },
    "assumptions": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "severity": {
            "type": "string"
          },
          "detail": {
            "type": "string"
          },
          "suggestion": {
            "type": "string"
          }
        }
      }
    },
    "verification": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tier",
        "engine_tested",
        "expert_reviewed",
        "source_checked",
        "reviewed_by",
        "reviewer_role",
        "last_reviewed"
      ],
      "properties": {
        "tier": {
          "type": "string",
          "enum": [
            "candidate",
            "engine_tested",
            "internally_reviewed",
            "expert_verified"
          ]
        },
        "engine_tested": {
          "type": "boolean"
        },
        "expert_reviewed": {
          "type": "boolean"
        },
        "internally_reviewed": {
          "type": "boolean"
        },
        "review_kind": {
          "type": [
            "string",
            "null"
          ]
        },
        "source_checked": {
          "type": "boolean"
        },
        "reviewed_by": {
          "type": [
            "string",
            "null"
          ]
        },
        "reviewer_role": {
          "type": [
            "string",
            "null"
          ]
        },
        "last_reviewed": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "tier": {
                "const": "expert_verified"
              }
            },
            "required": [
              "tier"
            ]
          },
          "then": {
            "properties": {
              "engine_tested": {
                "const": true
              },
              "expert_reviewed": {
                "const": true
              },
              "source_checked": {
                "const": true
              },
              "reviewed_by": {
                "type": "string",
                "minLength": 1
              },
              "reviewer_role": {
                "type": "string",
                "minLength": 1
              },
              "last_reviewed": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "tier": {
                "const": "internally_reviewed"
              }
            },
            "required": [
              "tier"
            ]
          },
          "then": {
            "properties": {
              "engine_tested": {
                "const": true
              },
              "internally_reviewed": {
                "const": true
              },
              "source_checked": {
                "const": true
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "tier": {
                "const": "engine_tested"
              }
            },
            "required": [
              "tier"
            ]
          },
          "then": {
            "properties": {
              "engine_tested": {
                "const": true
              }
            }
          }
        }
      ]
    },
    "calculation_version": {
      "type": "string",
      "const": "1.4.0"
    },
    "api_version": {
      "type": "string"
    },
    "api_contract_version": {
      "type": "string"
    },
    "spec_version": {
      "type": "string"
    },
    "page": {
      "type": [
        "string",
        "null"
      ],
      "description": "Canonical calculator page URL"
    },
    "links": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schema_input": {
          "type": "string",
          "format": "uri"
        },
        "schema_output": {
          "type": "string",
          "format": "uri"
        },
        "evidence": {
          "type": "string",
          "format": "uri"
        },
        "openapi": {
          "type": "string",
          "format": "uri"
        },
        "capabilities": {
          "type": "string",
          "format": "uri"
        },
        "mcp": {
          "type": "string",
          "format": "uri"
        }
      }
    }
  }
}
