{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dev.luling.xyz/runway-calculator/schemas/output.json",
  "title": "StartupRunwayEnvelope",
  "description": "Success or error envelope from startup-runway compute.",
  "oneOf": [
    {
      "type": "object",
      "required": ["ok", "result", "human_summary", "meta"],
      "additionalProperties": false,
      "properties": {
        "ok": { "const": true },
        "result": {
          "type": "object",
          "required": [
            "monthly_burn",
            "project_costs",
            "total_monthly_burn",
            "total_funds",
            "runway_months",
            "status",
            "recommendation_code",
            "target"
          ],
          "additionalProperties": false,
          "properties": {
            "monthly_burn": { "type": "number" },
            "project_costs": { "type": "number" },
            "total_monthly_burn": { "type": "number" },
            "total_funds": { "type": "number" },
            "runway_months": { "type": "integer", "minimum": 0 },
            "status": { "type": "string", "enum": ["safe", "caution", "danger"] },
            "recommendation_code": {
              "type": "string",
              "enum": ["SAFE_SOLID", "CAUTION_KEEP_JOB", "DANGER_DO_NOT_QUIT"]
            },
            "target": {
              "type": "object",
              "required": [
                "target_months",
                "required_funds",
                "additional_needed",
                "savings_rate",
                "months_to_save"
              ],
              "additionalProperties": false,
              "properties": {
                "target_months": { "type": "integer", "minimum": 1 },
                "required_funds": { "type": "number" },
                "additional_needed": { "type": "number", "minimum": 0 },
                "savings_rate": { "type": "number", "minimum": 0 },
                "months_to_save": {
                  "description": "null when additional_needed > 0 and savings_rate is 0",
                  "oneOf": [
                    { "type": "integer", "minimum": 0 },
                    { "type": "null" }
                  ]
                }
              }
            }
          }
        },
        "human_summary": { "type": "string" },
        "meta": {
          "type": "object",
          "required": ["tool", "version", "formula_id", "inputs_normalized"],
          "additionalProperties": false,
          "properties": {
            "tool": { "const": "startup-runway" },
            "version": { "type": "string" },
            "formula_id": { "const": "runway-1" },
            "inputs_normalized": { "type": "object" }
          }
        }
      }
    },
    {
      "type": "object",
      "required": ["ok", "code", "message"],
      "additionalProperties": false,
      "properties": {
        "ok": { "const": false },
        "code": { "type": "string" },
        "message": { "type": "string" },
        "hint": { "type": "string" }
      }
    }
  ]
}
