{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/kunkafa-com/json-schema/kunkafa-com-integration-usage-response-schema.json",
  "title": "IntegrationUsageResponse",
  "x-generated": "2026-11-14",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/kunkafa-com-openapi.json#/components/schemas/IntegrationUsageResponse",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "data",
    "following",
    "usage",
    "notices",
    "page",
    "dataUse"
  ],
  "properties": {
    "data": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "permittedMarkets",
        "outlookLimits",
        "connection"
      ],
      "properties": {
        "permittedMarkets": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/IntegrationMarketSlug"
          },
          "maxItems": 50
        },
        "outlookLimits": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "marketsPerCall",
            "maxDurations",
            "maxForecasts"
          ],
          "properties": {
            "marketsPerCall": {
              "const": 1
            },
            "maxDurations": {
              "const": 6
            },
            "maxForecasts": {
              "const": 72
            }
          },
          "description": "What one get_outlooks call can return."
        },
        "connection": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "kind",
            "permissions",
            "expiresAt",
            "canFollow"
          ],
          "properties": {
            "kind": {
              "enum": [
                "oauth",
                "personal_token"
              ]
            },
            "permissions": {
              "type": "array",
              "items": {
                "enum": [
                  "markets:read",
                  "outlooks:read",
                  "performance:read",
                  "results:read",
                  "usage:read",
                  "following:write"
                ]
              },
              "minItems": 1,
              "maxItems": 6,
              "uniqueItems": true
            },
            "expiresAt": {
              "$ref": "#/$defs/IntegrationTimestamp"
            },
            "staysConnectedWhileUsed": {
              "const": true
            },
            "idleDays": {
              "const": 90
            },
            "canFollow": {
              "type": "boolean",
              "description": "Whether this connection may follow and unfollow markets (the following:write permission)."
            },
            "howToAllowFollowing": {
              "type": "string",
              "description": "Present only when canFollow is false: how the user allows following for this connection."
            }
          },
          "description": "This connection's permissions and expiry. An MCP (OAuth) connection stays connected while used: it expires after idleDays without use, at most one year after it was approved. A reconnect from the same app replaces it without using another connection."
        }
      }
    },
    "following": {
      "$ref": "#/$defs/IntegrationFollowing"
    },
    "usage": {
      "$ref": "#/$defs/IntegrationUsage"
    },
    "notices": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/IntegrationNotice"
      },
      "maxItems": 3
    },
    "page": {
      "$ref": "#/$defs/IntegrationPage"
    },
    "dataUse": {
      "type": "string",
      "description": "Use restriction on every reply: data collection is prohibited; the data may not be collected, saved, stored, exported or compiled, or used to train, retrain, fine-tune or distil any model."
    }
  },
  "$defs": {
    "IntegrationFollowing": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "followed",
        "followLimit",
        "canFollowMore",
        "readsEveryMarket",
        "message",
        "followInApp",
        "otherMarkets",
        "otherMarketsTotal"
      ],
      "properties": {
        "followed": {
          "type": "integer",
          "minimum": 0,
          "description": "Markets on the account's following list, as the app counts them."
        },
        "followLimit": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "description": "The plan's Following count; null when the account reads every market."
        },
        "canFollowMore": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "description": "How many more markets can be followed; null when the account reads every market."
        },
        "readsEveryMarket": {
          "type": "boolean"
        },
        "message": {
          "type": "string",
          "description": "Plain explanation for the user, including for accounts that read every market."
        },
        "followInApp": {
          "type": "string",
          "format": "uri",
          "description": "Where the user follows markets in the Kunkafa app."
        },
        "otherMarkets": {
          "type": "array",
          "maxItems": 100,
          "description": "Catalogue markets the account does not follow, by English name, sorted by name; at most 100 (otherMarketsTotal gives the full count). Any market can still be followed by its slug.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "market",
              "name"
            ],
            "properties": {
              "market": {
                "$ref": "#/$defs/IntegrationMarketSlug"
              },
              "name": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        "otherMarketsTotal": {
          "type": "integer",
          "minimum": 0,
          "description": "How many catalogue markets the account does not follow."
        },
        "canFollow": {
          "type": "boolean",
          "description": "Whether this connection may follow and unfollow markets."
        },
        "howToAllowFollowing": {
          "type": "string",
          "minLength": 1,
          "description": "Present when canFollow is false."
        }
      },
      "description": "What the account follows and can still follow. Following decides which markets can be read; it happens in the Kunkafa app."
    },
    "IntegrationMarketSlug": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$",
      "description": "Published English-name market slug returned by authorized discovery."
    },
    "IntegrationNotice": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "period",
        "kind",
        "message",
        "used",
        "limit",
        "remaining",
        "nextCapacityAt"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "period": {
          "enum": [
            "day",
            "week",
            "month"
          ]
        },
        "kind": {
          "enum": [
            "approaching_limit",
            "limit_reached"
          ]
        },
        "message": {
          "type": "string"
        },
        "used": {
          "type": "integer",
          "minimum": 0
        },
        "limit": {
          "type": "integer",
          "minimum": 0
        },
        "remaining": {
          "type": "integer",
          "minimum": 0
        },
        "nextCapacityAt": {
          "anyOf": [
            {
              "$ref": "#/$defs/IntegrationTimestamp"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "IntegrationPage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "total",
        "returned",
        "nextCursor"
      ],
      "properties": {
        "total": {
          "type": "integer",
          "minimum": 0
        },
        "returned": {
          "type": "integer",
          "minimum": 0,
          "maximum": 50
        },
        "nextCursor": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 256,
              "pattern": "^[A-Za-z0-9_-]+$"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "description": "Follow nextCursor until null. Cursors are invalidated by relevant access or market-list changes; restart without a cursor."
    },
    "IntegrationTimestamp": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 UTC timestamp supplied by Kunkafa."
    },
    "IntegrationUsage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "calculatedAt",
        "tier",
        "requests",
        "concurrency",
        "windows"
      ],
      "properties": {
        "calculatedAt": {
          "$ref": "#/$defs/IntegrationTimestamp"
        },
        "tier": {
          "enum": [
            "free",
            "starter",
            "core",
            "pro",
            "publisher"
          ]
        },
        "requests": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "perMinute",
            "burst",
            "remaining",
            "nextRequestAt"
          ],
          "properties": {
            "perMinute": {
              "type": "integer",
              "minimum": 0
            },
            "burst": {
              "type": "integer",
              "minimum": 0
            },
            "remaining": {
              "type": "integer",
              "minimum": 0
            },
            "nextRequestAt": {
              "anyOf": [
                {
                  "$ref": "#/$defs/IntegrationTimestamp"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "description": "Steady request rate with bounded burst capacity; metadata and repeated summaries still count toward request protection."
        },
        "concurrency": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "limit",
            "remaining",
            "nextRequestAt"
          ],
          "description": "Private requests that can run at the same time. Requests from one connection run side by side up to this limit (the plan burst); a request from another connection waits until they finish.",
          "properties": {
            "limit": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            },
            "remaining": {
              "type": "integer",
              "minimum": 0,
              "maximum": 100
            },
            "nextRequestAt": {
              "anyOf": [
                {
                  "$ref": "#/$defs/IntegrationTimestamp"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        "windows": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/IntegrationWindowUsage"
          },
          "minItems": 3,
          "maxItems": 3
        },
        "adjustment": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "expiresAt"
          ],
          "properties": {
            "expiresAt": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time"
            }
          },
          "description": "An owner-approved account allowance increase. A null expiration is permanent until changed. Usage is never reset; market access and credential eligibility still follow the current plan."
        }
      }
    },
    "IntegrationWindowUsage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "period",
        "used",
        "limit",
        "remaining",
        "nextCapacityAt",
        "notice",
        "noticeId"
      ],
      "properties": {
        "period": {
          "enum": [
            "day",
            "week",
            "month"
          ]
        },
        "used": {
          "type": "integer",
          "minimum": 0
        },
        "limit": {
          "type": "integer",
          "minimum": 0
        },
        "remaining": {
          "type": "integer",
          "minimum": 0
        },
        "nextCapacityAt": {
          "anyOf": [
            {
              "$ref": "#/$defs/IntegrationTimestamp"
            },
            {
              "type": "null"
            }
          ]
        },
        "notice": {
          "enum": [
            "approaching_limit",
            "limit_reached",
            null
          ]
        },
        "noticeId": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "description": "Rolling 24-hour, 7-day or 30-day allowance, not a midnight reset. Used can exceed the current limit after a downgrade; remaining is never negative."
    }
  }
}