{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/bettermenu/json-schema/bettermenu-patch-added-sugars-report-row-request-schema.json",
  "title": "PatchAddedSugarsReportRowRequest",
  "description": "A person's answer for one ingredient row of the Added Sugars report.",
  "x-generated": "2026-11-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/bettermenu-studio-api-openapi.yml#/components/schemas/PatchAddedSugarsReportRowRequest",
  "properties": {
    "action": {
      "$ref": "#/$defs/CallerAction",
      "description": "What you are doing with the row.\n\n- `accept_suggestion`: take the row's suggested answer. The row must have a suggestion that proposes grams, or the answer is refused.\n- `set_contribution`: state the added sugars yourself, in grams in this row (`added_sugars_grams`) or per 100 g of the ingredient (`added_sugars_per_100g`); give exactly one of them.\n- `add_contribution`: the same as `set_contribution`; either may be used on any row.\n- `remove_contribution`: state that the row has no added sugars (0 g).\n- `keep`: confirm the answer the data checks already gave the row. A row the data checks left open has none to keep."
    },
    "added_sugars_grams": {
      "anyOf": [
        {
          "type": "number",
          "maximum": 1000000000000000.0,
          "minimum": 0.0
        },
        {
          "type": "string",
          "pattern": "^(?!^[-+.]*$)[+-]?0*(?:\\d{0,16}|(?=[\\d.]{1,23}0*$)\\d{0,16}\\.\\d{0,6}0*$)"
        },
        {
          "type": "null"
        }
      ],
      "title": "Added Sugars Grams",
      "description": "Grams of added sugars in this row at its current quantity, zero or more. For `set_contribution` and `add_contribution` give exactly one of this and `added_sugars_per_100g`; not allowed for any other action. At most six decimal places are accepted. It is stored as you enter it, with the row's quantity at the time. If the row's quantity changes later, the amount that counts is scaled to the new quantity."
    },
    "added_sugars_per_100g": {
      "anyOf": [
        {
          "type": "number",
          "maximum": 100.0,
          "minimum": 0.0
        },
        {
          "type": "string",
          "pattern": "^(?!^[-+.]*$)[+-]?0*(?:\\d{0,3}|(?=[\\d.]{1,10}0*$)\\d{0,3}\\.\\d{0,6}0*$)"
        },
        {
          "type": "null"
        }
      ],
      "title": "Added Sugars Per 100G",
      "description": "Grams of added sugars per 100 g of this ingredient, from 0 to 100, as a supplier specification states it; at most six decimal places are accepted. The alternative to `added_sugars_grams`: for `set_contribution` and `add_contribution` give exactly one of the two; not allowed for any other action. The server works out the grams in this row at its current quantity (`per 100 g x quantity / 100`) and stores them as if you had given them. The stored grams are that exact product, never rounded, so they can carry more than six decimal places (3.333333 on a 3 g row is stored as 0.0999999900) even though the figure you give is limited to six; the figures that count are shown at four decimal places in `effective`. The per-100 g figure is kept beside them as the way you entered it (`caller.entered_added_sugars_per_100g`). If the row's quantity changes later, the grams that count scale with it, as for `added_sugars_grams`."
    },
    "reason": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 1000,
          "minLength": 1
        },
        {
          "type": "null"
        }
      ],
      "title": "Reason",
      "description": "Optional. Why you gave this answer, for the record."
    },
    "supplier_reference": {
      "anyOf": [
        {
          "type": "string",
          "maxLength": 1000,
          "minLength": 1
        },
        {
          "type": "null"
        }
      ],
      "title": "Supplier Reference",
      "description": "Optional. A reference to the document that supports the answer, such as a supplier specification sheet and its date."
    }
  },
  "additionalProperties": false,
  "type": "object",
  "required": [
    "action"
  ],
  "$defs": {
    "CallerAction": {
      "type": "string",
      "enum": [
        "accept_suggestion",
        "set_contribution",
        "remove_contribution",
        "add_contribution",
        "keep"
      ],
      "title": "CallerAction",
      "description": "What a person did with an ingredient row's answer."
    }
  }
}