{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/storelift-net/json-schema/storelift-net-hive-keyword-metric-history-schema.json",
  "title": "HiveKeywordMetricHistory",
  "x-generated": "2026-11-26",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/storelift-net-openapi.yml#/components/schemas/HiveKeywordMetricHistory",
  "type": "object",
  "required": [
    "metricReadVersion",
    "historical",
    "country",
    "platform",
    "term",
    "from",
    "to",
    "days",
    "popularity",
    "readStatus",
    "measurementStarted",
    "coverage",
    "pagination"
  ],
  "properties": {
    "metricReadVersion": {
      "const": 1
    },
    "historical": {
      "const": true
    },
    "country": {
      "type": "string",
      "pattern": "^[a-z]{2}$"
    },
    "platform": {
      "const": "ios"
    },
    "term": {
      "type": "string"
    },
    "from": {
      "type": "string",
      "format": "date"
    },
    "to": {
      "type": "string",
      "format": "date"
    },
    "days": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "day",
          "apps",
          "difficulty",
          "sourceObservedAt",
          "observedAtPrecision"
        ],
        "properties": {
          "day": {
            "type": "string",
            "format": "date"
          },
          "apps": {
            "type": "integer",
            "minimum": 0
          },
          "difficulty": {
            "$ref": "#/$defs/HiveMetricObservation"
          },
          "sourceObservedAt": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "string",
                "format": "date"
              }
            ]
          },
          "observedAtPrecision": {
            "enum": [
              "instant",
              "day"
            ]
          },
          "popularity": {
            "type": "object",
            "required": [
              "value",
              "status"
            ],
            "properties": {
              "value": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0,
                "maximum": 100
              },
              "status": {
                "enum": [
                  "measured",
                  "unmeasured",
                  "legacy",
                  "source_error"
                ]
              }
            },
            "description": "That day's popularity: the same number the dashboard shows for that day. `legacy` days have no comparable value."
          }
        }
      }
    },
    "popularity": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "week",
          "revisionId",
          "popularity"
        ],
        "properties": {
          "week": {
            "type": "string",
            "format": "date"
          },
          "revisionId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Opaque revision identifier scoped to your workspace; a different value means a different published reading."
          },
          "popularity": {
            "$ref": "#/$defs/popularity"
          }
        }
      }
    },
    "readStatus": {
      "type": "object",
      "required": [
        "serp",
        "difficulty",
        "popularity"
      ],
      "additionalProperties": {
        "enum": [
          "ok",
          "source_error",
          "complete_previous_page"
        ]
      }
    },
    "measurementStarted": {
      "const": false
    },
    "coverage": {
      "type": "object",
      "required": [
        "requestedDays",
        "returnedDays",
        "missingDays",
        "metrics",
        "retrievalComplete",
        "complete"
      ],
      "properties": {
        "requestedDays": {
          "type": "integer",
          "minimum": 1,
          "maximum": 90
        },
        "returnedDays": {
          "type": "integer",
          "minimum": 0
        },
        "missingDays": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string",
            "format": "date"
          },
          "description": "Null when a source error or unfinished page prevents establishing the missing days."
        },
        "metrics": {
          "type": "object",
          "required": [
            "popularity",
            "difficulty"
          ],
          "additionalProperties": {
            "type": "object"
          }
        },
        "retrievalComplete": {
          "type": "boolean",
          "description": "All database sources read successfully with no remaining pages; does not claim every day was measured."
        },
        "complete": {
          "type": "boolean"
        }
      }
    },
    "pagination": {
      "type": "object",
      "required": [
        "hasMore",
        "nextCursor"
      ],
      "properties": {
        "hasMore": {
          "type": "boolean"
        },
        "nextCursor": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    }
  },
  "$defs": {
    "HiveMetricObservation": {
      "type": "object",
      "required": [
        "status",
        "kind",
        "value",
        "current",
        "source",
        "sourceObservedAt",
        "observedAtPrecision",
        "checkedAt",
        "period",
        "modelVersion",
        "evidence",
        "lastAttempt"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "fresh",
            "stale",
            "pending",
            "absent",
            "error",
            "unmeasured",
            "restricted"
          ]
        },
        "kind": {
          "type": "string",
          "enum": [
            "observed",
            "estimated"
          ]
        },
        "value": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 100
        },
        "current": {
          "type": "boolean"
        },
        "source": {
          "type": [
            "string",
            "null"
          ]
        },
        "sourceObservedAt": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ],
          "description": "Original source observation time; a read or model calculation does not update it."
        },
        "observedAtPrecision": {
          "enum": [
            "instant",
            "day",
            null
          ]
        },
        "checkedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "period": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "kind": {
              "enum": [
                "week",
                "day"
              ]
            },
            "start": {
              "type": "string",
              "format": "date"
            }
          }
        },
        "modelVersion": {
          "type": [
            "string",
            "null"
          ]
        },
        "evidence": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": true,
          "description": "Source-bound evidence and available hashes. `observationId` is an opaque identifier scoped to your workspace: stable across your requests, never comparable with another workspace's identifiers. parsed_json_v1 describes a hash of parsed JSON, not raw response bytes."
        },
        "lastAttempt": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "status": {
              "enum": [
                "pending",
                "error"
              ]
            },
            "checkedAt": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time"
            },
            "attemptId": {
              "type": "string"
            }
          },
          "description": "Independent from a retained observation: a retry error does not erase an earlier valid value."
        }
      }
    }
  }
}