{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tune.toys/schemas/platform/api-usage.schema.json",
  "title": "ApiUsage",
  "description": "Metered usage of one developer app in UTC hourly or daily windows. Counters are informational and may lag by up to 30 seconds.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "appId": { "$ref": "common.schema.json#/$defs/EntityId" },
    "granularity": { "enum": ["hour", "day"] },
    "since": { "$ref": "common.schema.json#/$defs/Timestamp" },
    "series": {
      "type": "array",
      "maxItems": 2160,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "windowStart": { "$ref": "common.schema.json#/$defs/Timestamp" },
          "requests": { "type": "integer", "minimum": 0 },
          "rejected": { "type": "integer", "minimum": 0 },
          "bytesOut": { "type": "integer", "minimum": 0 }
        },
        "required": ["windowStart", "requests", "rejected", "bytesOut"]
      }
    },
    "keys": {
      "type": "array",
      "maxItems": 100,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "keyId": { "$ref": "common.schema.json#/$defs/EntityId" },
          "prefix": { "type": "string", "pattern": "^[a-z2-7]{8}$" },
          "requests": { "type": "integer", "minimum": 0 },
          "rejected": { "type": "integer", "minimum": 0 },
          "bytesOut": { "type": "integer", "minimum": 0 }
        },
        "required": ["keyId", "prefix", "requests", "rejected", "bytesOut"]
      }
    },
    "totals": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "requests": { "type": "integer", "minimum": 0 },
        "rejected": { "type": "integer", "minimum": 0 },
        "bytesOut": { "type": "integer", "minimum": 0 }
      },
      "required": ["requests", "rejected", "bytesOut"]
    }
  },
  "required": ["appId", "granularity", "since", "series", "keys", "totals"]
}
