{
  "$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"
    },
    "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"
    },
    "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"
    },
    "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"
    },
    "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"
    },
    "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-request.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "properties": {
    "at_spend": {
      "anyOf": [
        {
          "additionalProperties": {
            "type": "number"
          },
          "type": "object"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "At Spend"
    },
    "delta_rel": {
      "default": 0.1,
      "description": "+10% matches E-BM-MARG-ROI.",
      "exclusiveMinimum": 0,
      "title": "Delta Rel",
      "type": "number"
    },
    "estimand": {
      "anyOf": [
        {
          "$ref": "#/$defs/Estimand"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "G-EST-02 re-ask rung: the estimand the caller wants answered. Adapters that can re-summarise answer with it; others ignore it, answer with their own estimand and add the note REASK_NOT_HONOURED, and the caller aligns as before."
    },
    "fit_id": {
      "title": "Fit Id",
      "type": "string"
    }
  },
  "required": [
    "fit_id"
  ],
  "title": "MarginalReturnRequest",
  "type": "object"
}
