{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/shruwd-io/json-schema/shruwd-io-visibility-series-schema.json",
  "title": "VisibilitySeries",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/shruwd-io-openapi.json#/components/schemas/VisibilitySeries",
  "type": "object",
  "required": [
    "brand",
    "engine",
    "windowDays",
    "range",
    "historyFrom",
    "points",
    "entities",
    "modelChanges"
  ],
  "properties": {
    "brand": {
      "type": "object",
      "required": [
        "brandId",
        "name",
        "timezone"
      ],
      "properties": {
        "brandId": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "timezone": {
          "type": "string"
        }
      }
    },
    "engine": {
      "$ref": "#/$defs/Engine"
    },
    "windowDays": {
      "type": "integer",
      "enum": [
        7,
        30,
        90
      ]
    },
    "range": {
      "type": "object",
      "required": [
        "from",
        "to"
      ],
      "properties": {
        "from": {
          "type": "string",
          "format": "date"
        },
        "to": {
          "type": "string",
          "format": "date"
        }
      }
    },
    "historyFrom": {
      "type": [
        "string",
        "null"
      ],
      "format": "date",
      "description": "Set when `from` was moved forward to the plan's history window."
    },
    "points": {
      "type": "array",
      "items": {
        "type": "string",
        "format": "date"
      },
      "description": "Cycle-close days in the range, ascending. Every entity's `series` is index-aligned with this."
    },
    "entities": {
      "type": "array",
      "description": "The brand first, then competitors by how often they were named over the range.",
      "items": {
        "type": "object",
        "required": [
          "entityId",
          "canonicalName",
          "isSelf",
          "series"
        ],
        "properties": {
          "entityId": {
            "type": "string"
          },
          "canonicalName": {
            "type": "string"
          },
          "isSelf": {
            "type": "boolean"
          },
          "series": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "$ref": "#/$defs/SeriesPoint"
                },
                {
                  "type": "null"
                }
              ]
            },
            "description": "One entry per `points` day; null when the rollup has no row for the entity on that close."
          }
        }
      }
    },
    "modelChanges": {
      "type": "array",
      "description": "Closes where the provider's model set differed from the previous close. A comparison across one is confounded.",
      "items": {
        "$ref": "#/$defs/ModelChange"
      }
    }
  },
  "$defs": {
    "DisplayableMetric": {
      "description": "A metric that can be shown. Never a bare number: either a point\nestimate with its 95% interval and `n`, or an explicit reason there is\nno number. `insufficient_data` is **not** zero.\n",
      "oneOf": [
        {
          "type": "object",
          "required": [
            "state",
            "point",
            "lo",
            "hi",
            "n"
          ],
          "properties": {
            "state": {
              "type": "string",
              "const": "ok"
            },
            "point": {
              "type": "number",
              "description": "Proportion in [0, 1]."
            },
            "lo": {
              "type": "number",
              "description": "Lower bound of the 95% interval."
            },
            "hi": {
              "type": "number",
              "description": "Upper bound of the 95% interval."
            },
            "n": {
              "type": "integer",
              "description": "Responses the estimate rests on."
            }
          }
        },
        {
          "type": "object",
          "required": [
            "state",
            "n",
            "needed"
          ],
          "properties": {
            "state": {
              "type": "string",
              "const": "insufficient_data"
            },
            "n": {
              "type": "integer"
            },
            "needed": {
              "type": "integer",
              "description": "How many more responses would cross the floor of ten."
            }
          }
        },
        {
          "type": "object",
          "required": [
            "state",
            "n",
            "reason"
          ],
          "properties": {
            "state": {
              "type": "string",
              "const": "undefined"
            },
            "n": {
              "type": "integer"
            },
            "reason": {
              "type": "string"
            }
          }
        }
      ]
    },
    "Engine": {
      "type": "string",
      "enum": [
        "google_aio",
        "google_ai_mode",
        "chatgpt",
        "gemini",
        "perplexity"
      ],
      "description": "`google_aio` — Google AI Overviews. `google_ai_mode` — Google AI Mode, tracked since 2026-10-15. `chatgpt` — ChatGPT. `gemini` — Gemini, tracked since 2026-11-10. `perplexity` — Perplexity, asked through its Sonar API, tracked since 2026-11-11."
    },
    "ModelChange": {
      "type": "object",
      "required": [
        "asOf",
        "engine",
        "from",
        "to"
      ],
      "properties": {
        "asOf": {
          "type": "string",
          "format": "date"
        },
        "engine": {
          "$ref": "#/$defs/Engine"
        },
        "from": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "to": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "SeriesPoint": {
      "type": "object",
      "required": [
        "asOf",
        "n",
        "mentionRate",
        "shareOfVoice",
        "avgProminence",
        "modelIds"
      ],
      "properties": {
        "asOf": {
          "type": "string",
          "format": "date",
          "description": "The cycle-close day this window ends on."
        },
        "n": {
          "type": "integer",
          "description": "Responses in the window measured while the entity was tracked: the mention rate's n."
        },
        "mentionRate": {
          "allOf": [
            {
              "$ref": "#/$defs/DisplayableMetric"
            }
          ],
          "description": "Share of the window's responses that mentioned the entity, with its Wilson interval."
        },
        "shareOfVoice": {
          "allOf": [
            {
              "$ref": "#/$defs/DisplayableMetric"
            }
          ],
          "description": "Among the entities tracked at the window's end, over the responses checked against all of them; its own n."
        },
        "avgProminence": {
          "type": [
            "number",
            "null"
          ]
        },
        "modelIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    }
  }
}