{
  "$defs": {
    "AppliesTo": {
      "additionalProperties": false,
      "description": "Scope beside the estimand: compared by ``G-EST-02`` like the seven fields.",
      "properties": {
        "client_id": {
          "title": "Client Id",
          "type": "string"
        },
        "geo_ids": {
          "items": {
            "type": "string"
          },
          "title": "Geo Ids",
          "type": "array"
        },
        "kpi": {
          "title": "Kpi",
          "type": "string"
        },
        "media_ids": {
          "items": {
            "type": "string"
          },
          "title": "Media Ids",
          "type": "array"
        },
        "period": {
          "$ref": "#/$defs/Period"
        },
        "time_id": {
          "description": "Spec \u00a74 time registry entry ID.",
          "title": "Time Id",
          "type": "string"
        }
      },
      "title": "AppliesTo",
      "type": "object"
    },
    "ChannelSummary": {
      "additionalProperties": false,
      "properties": {
        "channel": {
          "title": "Channel",
          "type": "string"
        },
        "contribution": {
          "$ref": "#/$defs/ShownNumber"
        },
        "mroi": {
          "anyOf": [
            {
              "$ref": "#/$defs/ShownNumber"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "roi": {
          "$ref": "#/$defs/ShownNumber"
        },
        "spend": {
          "title": "Spend",
          "type": "number"
        }
      },
      "required": [
        "channel",
        "spend",
        "contribution",
        "roi"
      ],
      "title": "ChannelSummary",
      "type": "object"
    },
    "DependenceDeclaration": {
      "additionalProperties": false,
      "properties": {
        "assumption": {
          "anyOf": [
            {
              "enum": [
                "copula",
                "independence"
              ],
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Required when kind is declared_assumption.",
          "title": "Assumption"
        },
        "kind": {
          "enum": [
            "joint_draws",
            "joint_gaussian",
            "declared_assumption",
            "per_channel",
            "none"
          ],
          "title": "Kind",
          "type": "string"
        },
        "note": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Note"
        }
      },
      "required": [
        "kind"
      ],
      "title": "DependenceDeclaration",
      "type": "object"
    },
    "Estimand": {
      "additionalProperties": false,
      "description": "The seven fields plus ``applies_to`` and the registered optional members. ``None`` (written\n``\"undeclared\"``) means undeclared.",
      "properties": {
        "applies_to": {
          "$ref": "#/$defs/AppliesTo"
        },
        "baseline": {
          "anyOf": [
            {
              "enum": [
                "zero_spend",
                "current_plan",
                "reduced_spend",
                "control_counterfactual"
              ],
              "type": "string"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ],
          "title": "Baseline"
        },
        "baseline_x": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ],
          "description": "x of reduced_spend(x): spend at x times the current plan. Required with baseline reduced_spend; ignored otherwise (spec \u00a75).",
          "title": "Baseline X"
        },
        "field_status": {
          "additionalProperties": {
            "enum": [
              "declared",
              "undeclared",
              "assumed"
            ],
            "type": "string"
          },
          "title": "Field Status",
          "type": "object"
        },
        "horizon": {
          "anyOf": [
            {
              "$ref": "#/$defs/Horizon"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ]
        },
        "interval": {
          "anyOf": [
            {
              "$ref": "#/$defs/IntervalSpec"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ]
        },
        "intervention": {
          "anyOf": [
            {
              "$ref": "#/$defs/Intervention"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ]
        },
        "metric_family": {
          "description": "sales_return, brand_awareness, ...",
          "title": "Metric Family",
          "type": "string"
        },
        "point_rule": {
          "anyOf": [
            {
              "enum": [
                "posterior_mean",
                "posterior_median",
                "map",
                "estimator_point"
              ],
              "type": "string"
            },
            {
              "$ref": "#/$defs/PointRuleSpec"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ],
          "title": "Point Rule"
        },
        "registry_id": {
          "description": "Registered estimand id, e.g. E-BM-AVG-ROI.",
          "title": "Registry Id",
          "type": "string"
        },
        "schema_version": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ],
          "description": "Estimand registry version, e.g. est-registry/1.2.0. No default.",
          "title": "Schema Version"
        },
        "unit": {
          "anyOf": [
            {
              "$ref": "#/$defs/Unit"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ]
        }
      },
      "title": "Estimand",
      "type": "object"
    },
    "FallbackEntry": {
      "additionalProperties": false,
      "description": "\u00a719 fallback note. ``effect`` says how the interval changed, in plain words.",
      "properties": {
        "acknowledged_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Acknowledged At"
        },
        "acknowledged_by": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Acknowledged By"
        },
        "assumed": {
          "title": "Assumed",
          "type": "string"
        },
        "code": {
          "pattern": "^[A-Z][A-Z0-9_]*$",
          "title": "Code",
          "type": "string"
        },
        "effect": {
          "title": "Effect",
          "type": "string"
        },
        "envelope_kind": {
          "anyOf": [
            {
              "enum": [
                "bound",
                "range"
              ],
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "G-DEP-01 (spec \u00a77): `bound` for sums, means, CVaR and monotone functions of sums; `range` for quantile-type, non-monotone outputs and EVOI. A range is never a bound.",
          "title": "Envelope Kind"
        },
        "field": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Field"
        },
        "gate": {
          "title": "Gate",
          "type": "string"
        },
        "interval_after": {
          "anyOf": [
            {
              "$ref": "#/$defs/Interval"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "interval_before": {
          "anyOf": [
            {
              "$ref": "#/$defs/Interval"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        }
      },
      "required": [
        "code",
        "gate",
        "assumed",
        "effect"
      ],
      "title": "FallbackEntry",
      "type": "object"
    },
    "Horizon": {
      "additionalProperties": false,
      "description": "Time over which the effect is counted. ``{type: window, anchor: fit}`` is the model's fit window:\na template written before any fit (an adapter's metadata) leaves ``weeks`` absent, and every\nquantity a fit produces states ``weeks`` (spec \u00a75, \"Fit-window horizon\"). ``weeks`` is never null.",
      "properties": {
        "anchor": {
          "const": "fit",
          "description": "Spec \u00a75: `fit` means the window is the model's fit window. Absent means the window counts from the start of the intervention.",
          "title": "Anchor",
          "type": "string"
        },
        "threshold": {
          "description": "Decay threshold for total_to_decay.",
          "title": "Threshold",
          "type": "number"
        },
        "type": {
          "enum": [
            "immediate",
            "window",
            "total_to_decay",
            "total"
          ],
          "title": "Type",
          "type": "string"
        },
        "weeks": {
          "description": "Weeks counted. Absent only on a fit-window template.",
          "minimum": 0,
          "title": "Weeks",
          "type": "integer"
        }
      },
      "required": [
        "type"
      ],
      "title": "Horizon",
      "type": "object"
    },
    "Interval": {
      "additionalProperties": false,
      "properties": {
        "hi": {
          "title": "Hi",
          "type": "number"
        },
        "level": {
          "default": 0.9,
          "exclusiveMaximum": 1,
          "exclusiveMinimum": 0,
          "title": "Level",
          "type": "number"
        },
        "lo": {
          "title": "Lo",
          "type": "number"
        },
        "method": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Method"
        },
        "segments": {
          "anyOf": [
            {
              "items": {
                "maxItems": 2,
                "minItems": 2,
                "prefixItems": [
                  {
                    "type": "number"
                  },
                  {
                    "type": "number"
                  }
                ],
                "type": "array"
              },
              "type": "array"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Spec \u00a75: an `hdi` region that is not one interval, as ordered, non-overlapping [lo, hi] segments inside [lo, hi] (note MULTIMODAL_HDI).",
          "title": "Segments"
        }
      },
      "required": [
        "lo",
        "hi"
      ],
      "title": "Interval",
      "type": "object"
    },
    "IntervalSpec": {
      "additionalProperties": false,
      "properties": {
        "level": {
          "exclusiveMaximum": 1,
          "exclusiveMinimum": 0,
          "title": "Level",
          "type": "number"
        },
        "method": {
          "enum": [
            "hdi",
            "eti",
            "confidence",
            "bootstrap_pct",
            "placebo",
            "envelope",
            "imputed"
          ],
          "title": "Method",
          "type": "string"
        }
      },
      "required": [
        "method",
        "level"
      ],
      "title": "IntervalSpec",
      "type": "object"
    },
    "Intervention": {
      "additionalProperties": false,
      "properties": {
        "arms": {
          "items": {
            "type": "string"
          },
          "title": "Arms",
          "type": "array"
        },
        "population": {
          "anyOf": [
            {
              "enum": [
                "itt",
                "exposed",
                "geo_set"
              ],
              "type": "string"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ],
          "title": "Population"
        },
        "size": {
          "description": "e.g. -0.30 for a 30% cut, 0.10 for +10%.",
          "title": "Size",
          "type": "number"
        },
        "size_kind": {
          "anyOf": [
            {
              "enum": [
                "absolute",
                "relative"
              ],
              "type": "string"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ],
          "description": "How to read size: relative (a fraction of current spend) or absolute (spend in unit.currency). Required when size is present; no default (spec \u00a75).",
          "title": "Size Kind"
        },
        "type": {
          "enum": [
            "remove_all",
            "scale",
            "add",
            "marginal"
          ],
          "title": "Type",
          "type": "string"
        }
      },
      "required": [
        "type"
      ],
      "title": "Intervention",
      "type": "object"
    },
    "Note": {
      "additionalProperties": false,
      "description": "Informational or warning note (e.g. ``ENGINE_STUB``, ``NOT_IMPLEMENTED_IN_POC``).",
      "properties": {
        "code": {
          "pattern": "^[A-Z][A-Z0-9_]*$",
          "title": "Code",
          "type": "string"
        },
        "gate": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Gate"
        },
        "message": {
          "title": "Message",
          "type": "string"
        },
        "severity": {
          "default": "info",
          "enum": [
            "info",
            "warn"
          ],
          "title": "Severity",
          "type": "string"
        }
      },
      "required": [
        "code",
        "message"
      ],
      "title": "Note",
      "type": "object"
    },
    "Period": {
      "additionalProperties": false,
      "description": "Calendar dates, half-open ``[start, end)`` (spec \u00a74).",
      "properties": {
        "end": {
          "format": "date",
          "title": "End",
          "type": "string"
        },
        "start": {
          "format": "date",
          "title": "Start",
          "type": "string"
        }
      },
      "title": "Period",
      "type": "object"
    },
    "PointRuleSpec": {
      "additionalProperties": false,
      "description": "``{rule, scale}`` form of ``point_rule`` (spec \u00a75): ``scale`` is ``identity`` or ``log``.",
      "properties": {
        "rule": {
          "enum": [
            "posterior_mean",
            "posterior_median",
            "map",
            "estimator_point"
          ],
          "title": "Rule",
          "type": "string"
        },
        "scale": {
          "enum": [
            "identity",
            "log"
          ],
          "title": "Scale",
          "type": "string"
        }
      },
      "required": [
        "rule",
        "scale"
      ],
      "title": "PointRuleSpec",
      "type": "object"
    },
    "RunRecord": {
      "additionalProperties": false,
      "properties": {
        "artifact_ids": {
          "items": {
            "type": "string"
          },
          "title": "Artifact Ids",
          "type": "array"
        },
        "audit_level": {
          "default": 2,
          "enum": [
            1,
            2,
            3,
            4
          ],
          "title": "Audit Level",
          "type": "integer"
        },
        "code_commit": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Code Commit"
        },
        "dataset_hashes": {
          "items": {
            "type": "string"
          },
          "title": "Dataset Hashes",
          "type": "array"
        },
        "ended_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Ended At"
        },
        "engine": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Engine"
        },
        "engine_version": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Engine Version"
        },
        "id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Id"
        },
        "image_digest": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Image Digest"
        },
        "inputs_digest": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Inputs Digest"
        },
        "lockfile_hash": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Lockfile Hash"
        },
        "outputs_digest": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Outputs Digest"
        },
        "principal": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Principal"
        },
        "seeds": {
          "items": {
            "type": "integer"
          },
          "title": "Seeds",
          "type": "array"
        },
        "session_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Agent or UI session the call belonged to (Newton reader/actor sessions).",
          "title": "Session Id"
        },
        "started_at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Started At"
        },
        "status": {
          "default": "succeeded",
          "enum": [
            "succeeded",
            "failed",
            "refused"
          ],
          "title": "Status",
          "type": "string"
        },
        "tool": {
          "description": "e.g. 'adapter:redacted-engine/fit' or 'newton:actor/draft_decision'.",
          "title": "Tool",
          "type": "string"
        }
      },
      "required": [
        "tool"
      ],
      "title": "RunRecord",
      "type": "object"
    },
    "ShownNumber": {
      "additionalProperties": false,
      "description": "The display contract: a value can only be shown with its interval, estimand and trust labels.",
      "properties": {
        "artifact_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "G-REP-01: the artifact this number resolves to.",
          "title": "Artifact Id"
        },
        "audit_level": {
          "default": 2,
          "enum": [
            1,
            2,
            3,
            4
          ],
          "title": "Audit Level",
          "type": "integer"
        },
        "confidence": {
          "anyOf": [
            {
              "enum": [
                "high",
                "medium",
                "low"
              ],
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "From trust level and interval width (rule in ump_spec.rules.plain; proposed).",
          "title": "Confidence"
        },
        "estimand": {
          "$ref": "#/$defs/Estimand"
        },
        "fallbacks": {
          "items": {
            "$ref": "#/$defs/FallbackEntry"
          },
          "title": "Fallbacks",
          "type": "array"
        },
        "headline": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Plain short label, e.g. 'Return per $1 on Linear TV'.",
          "title": "Headline"
        },
        "interval": {
          "$ref": "#/$defs/Interval"
        },
        "label": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Short caption, e.g. 'Paid Social iROAS'.",
          "title": "Label"
        },
        "notes": {
          "items": {
            "$ref": "#/$defs/Note"
          },
          "title": "Notes",
          "type": "array"
        },
        "plain_words": {
          "description": "Estimand in plain words, including any assumed field.",
          "title": "Plain Words",
          "type": "string"
        },
        "range_words": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "The interval in words, e.g. 'likely between $0.60 and $1.87'.",
          "title": "Range Words"
        },
        "trust_level": {
          "default": 2,
          "maximum": 4,
          "minimum": 1,
          "title": "Trust Level",
          "type": "integer"
        },
        "unit_label": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Unit Label"
        },
        "value": {
          "title": "Value",
          "type": "number"
        },
        "why_best_guess": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "One plain sentence when the number rests on fallbacks.",
          "title": "Why Best Guess"
        },
        "width_label": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "narrow|moderate|wide (proposed cut points).",
          "title": "Width Label"
        }
      },
      "required": [
        "value",
        "interval",
        "estimand",
        "plain_words"
      ],
      "title": "ShownNumber",
      "type": "object"
    },
    "Unit": {
      "additionalProperties": false,
      "description": "``per`` is ``spend``, ``impression`` or ``absolute``. ``currency`` (ISO 4217) is required with\n``per: spend`` and allowed with ``per: absolute`` (a money KPI); there its absence means the KPI is\nnot money. Build a spend unit with ``spend_unit(currency)``.",
      "properties": {
        "cost_basis": {
          "anyOf": [
            {
              "enum": [
                "net",
                "gross"
              ],
              "type": "string"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ],
          "title": "Cost Basis"
        },
        "currency": {
          "anyOf": [
            {
              "pattern": "^[A-Z]{3}$",
              "type": "string"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ],
          "description": "ISO 4217 alpha-3; required with per: spend.",
          "title": "Currency"
        },
        "kpi": {
          "title": "Kpi",
          "type": "string"
        },
        "per": {
          "anyOf": [
            {
              "enum": [
                "spend",
                "impression",
                "absolute"
              ],
              "type": "string"
            },
            {
              "const": "undeclared",
              "type": "string"
            }
          ],
          "description": "Denominator: spend, impression or absolute (spec \u00a75).",
          "title": "Per"
        }
      },
      "required": [
        "kpi"
      ],
      "title": "Unit",
      "type": "object"
    }
  },
  "$id": "https://schemas.ump.dev/v1/adapter-marginal-return-response.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "properties": {
    "dependence": {
      "anyOf": [
        {
          "$ref": "#/$defs/DependenceDeclaration"
        },
        {
          "type": "null"
        }
      ],
      "default": null
    },
    "engine": {
      "title": "Engine",
      "type": "string"
    },
    "engine_version": {
      "title": "Engine Version",
      "type": "string"
    },
    "estimands": {
      "additionalProperties": {
        "$ref": "#/$defs/Estimand"
      },
      "title": "Estimands",
      "type": "object"
    },
    "fallbacks": {
      "items": {
        "$ref": "#/$defs/FallbackEntry"
      },
      "title": "Fallbacks",
      "type": "array"
    },
    "notes": {
      "items": {
        "$ref": "#/$defs/Note"
      },
      "title": "Notes",
      "type": "array"
    },
    "per_channel": {
      "items": {
        "$ref": "#/$defs/ChannelSummary"
      },
      "title": "Per Channel",
      "type": "array"
    },
    "run": {
      "anyOf": [
        {
          "$ref": "#/$defs/RunRecord"
        },
        {
          "type": "null"
        }
      ],
      "default": null
    },
    "stub": {
      "default": false,
      "title": "Stub",
      "type": "boolean"
    }
  },
  "required": [
    "engine",
    "engine_version",
    "per_channel"
  ],
  "title": "MarginalReturnResponse",
  "type": "object"
}
