|
| 1 | +package io.getstream.chat.java.models; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 4 | +import io.getstream.chat.java.models.TeamUsageStats.QueryTeamUsageStatsRequestData.QueryTeamUsageStatsRequest; |
| 5 | +import io.getstream.chat.java.models.framework.StreamRequest; |
| 6 | +import io.getstream.chat.java.models.framework.StreamResponseObject; |
| 7 | +import io.getstream.chat.java.services.StatsService; |
| 8 | +import io.getstream.chat.java.services.framework.Client; |
| 9 | +import java.util.List; |
| 10 | +import lombok.Builder; |
| 11 | +import lombok.Data; |
| 12 | +import lombok.EqualsAndHashCode; |
| 13 | +import lombok.Getter; |
| 14 | +import lombok.NoArgsConstructor; |
| 15 | +import org.jetbrains.annotations.NotNull; |
| 16 | +import org.jetbrains.annotations.Nullable; |
| 17 | +import retrofit2.Call; |
| 18 | + |
| 19 | +/** Team-level usage statistics for multi-tenant apps. */ |
| 20 | +@Data |
| 21 | +@NoArgsConstructor |
| 22 | +public class TeamUsageStats { |
| 23 | + |
| 24 | + /** Team identifier (empty string for users not assigned to any team). */ |
| 25 | + @NotNull |
| 26 | + @JsonProperty("team") |
| 27 | + private String team; |
| 28 | + |
| 29 | + // Daily activity metrics (total = SUM of daily values) |
| 30 | + |
| 31 | + /** Daily active users. */ |
| 32 | + @NotNull |
| 33 | + @JsonProperty("users_daily") |
| 34 | + private MetricStats usersDaily; |
| 35 | + |
| 36 | + /** Daily messages sent. */ |
| 37 | + @NotNull |
| 38 | + @JsonProperty("messages_daily") |
| 39 | + private MetricStats messagesDaily; |
| 40 | + |
| 41 | + /** Daily translations. */ |
| 42 | + @NotNull |
| 43 | + @JsonProperty("translations_daily") |
| 44 | + private MetricStats translationsDaily; |
| 45 | + |
| 46 | + /** Daily image moderations. */ |
| 47 | + @NotNull |
| 48 | + @JsonProperty("image_moderations_daily") |
| 49 | + private MetricStats imageModerationDaily; |
| 50 | + |
| 51 | + // Peak metrics (total = MAX of daily values) |
| 52 | + |
| 53 | + /** Peak concurrent users. */ |
| 54 | + @NotNull |
| 55 | + @JsonProperty("concurrent_users") |
| 56 | + private MetricStats concurrentUsers; |
| 57 | + |
| 58 | + /** Peak concurrent connections. */ |
| 59 | + @NotNull |
| 60 | + @JsonProperty("concurrent_connections") |
| 61 | + private MetricStats concurrentConnections; |
| 62 | + |
| 63 | + // Rolling/cumulative metrics (total = LATEST daily value) |
| 64 | + |
| 65 | + /** Total users. */ |
| 66 | + @NotNull |
| 67 | + @JsonProperty("users_total") |
| 68 | + private MetricStats usersTotal; |
| 69 | + |
| 70 | + /** Users active in last 24 hours. */ |
| 71 | + @NotNull |
| 72 | + @JsonProperty("users_last_24_hours") |
| 73 | + private MetricStats usersLast24Hours; |
| 74 | + |
| 75 | + /** MAU - users active in last 30 days. */ |
| 76 | + @NotNull |
| 77 | + @JsonProperty("users_last_30_days") |
| 78 | + private MetricStats usersLast30Days; |
| 79 | + |
| 80 | + /** Users active this month. */ |
| 81 | + @NotNull |
| 82 | + @JsonProperty("users_month_to_date") |
| 83 | + private MetricStats usersMonthToDate; |
| 84 | + |
| 85 | + /** Engaged MAU. */ |
| 86 | + @NotNull |
| 87 | + @JsonProperty("users_engaged_last_30_days") |
| 88 | + private MetricStats usersEngagedLast30Days; |
| 89 | + |
| 90 | + /** Engaged users this month. */ |
| 91 | + @NotNull |
| 92 | + @JsonProperty("users_engaged_month_to_date") |
| 93 | + private MetricStats usersEngagedMonthToDate; |
| 94 | + |
| 95 | + /** Total messages. */ |
| 96 | + @NotNull |
| 97 | + @JsonProperty("messages_total") |
| 98 | + private MetricStats messagesTotal; |
| 99 | + |
| 100 | + /** Messages in last 24 hours. */ |
| 101 | + @NotNull |
| 102 | + @JsonProperty("messages_last_24_hours") |
| 103 | + private MetricStats messagesLast24Hours; |
| 104 | + |
| 105 | + /** Messages in last 30 days. */ |
| 106 | + @NotNull |
| 107 | + @JsonProperty("messages_last_30_days") |
| 108 | + private MetricStats messagesLast30Days; |
| 109 | + |
| 110 | + /** Messages this month. */ |
| 111 | + @NotNull |
| 112 | + @JsonProperty("messages_month_to_date") |
| 113 | + private MetricStats messagesMonthToDate; |
| 114 | + |
| 115 | + /** Statistics for a single metric with optional daily breakdown. */ |
| 116 | + @Data |
| 117 | + @NoArgsConstructor |
| 118 | + public static class MetricStats { |
| 119 | + /** Per-day values (only present in daily mode). */ |
| 120 | + @Nullable |
| 121 | + @JsonProperty("daily") |
| 122 | + private List<DailyValue> daily; |
| 123 | + |
| 124 | + /** Aggregated total value. */ |
| 125 | + @NotNull |
| 126 | + @JsonProperty("total") |
| 127 | + private Long total; |
| 128 | + } |
| 129 | + |
| 130 | + /** Represents a metric value for a specific date. */ |
| 131 | + @Data |
| 132 | + @NoArgsConstructor |
| 133 | + public static class DailyValue { |
| 134 | + /** Date in YYYY-MM-DD format. */ |
| 135 | + @NotNull |
| 136 | + @JsonProperty("date") |
| 137 | + private String date; |
| 138 | + |
| 139 | + /** Metric value for this date. */ |
| 140 | + @NotNull |
| 141 | + @JsonProperty("value") |
| 142 | + private Long value; |
| 143 | + } |
| 144 | + |
| 145 | + @Builder( |
| 146 | + builderClassName = "QueryTeamUsageStatsRequest", |
| 147 | + builderMethodName = "", |
| 148 | + buildMethodName = "internalBuild") |
| 149 | + @Getter |
| 150 | + @EqualsAndHashCode |
| 151 | + public static class QueryTeamUsageStatsRequestData { |
| 152 | + /** |
| 153 | + * Month in YYYY-MM format (e.g., '2026-01'). Mutually exclusive with start_date/end_date. |
| 154 | + * Returns aggregated monthly values. |
| 155 | + */ |
| 156 | + @Nullable |
| 157 | + @JsonProperty("month") |
| 158 | + private String month; |
| 159 | + |
| 160 | + /** |
| 161 | + * Start date in YYYY-MM-DD format. Used with end_date for custom date range. Returns daily |
| 162 | + * breakdown. |
| 163 | + */ |
| 164 | + @Nullable |
| 165 | + @JsonProperty("start_date") |
| 166 | + private String startDate; |
| 167 | + |
| 168 | + /** |
| 169 | + * End date in YYYY-MM-DD format. Used with start_date for custom date range. Returns daily |
| 170 | + * breakdown. |
| 171 | + */ |
| 172 | + @Nullable |
| 173 | + @JsonProperty("end_date") |
| 174 | + private String endDate; |
| 175 | + |
| 176 | + /** Maximum number of teams to return per page (default: 30, max: 30). */ |
| 177 | + @Nullable |
| 178 | + @JsonProperty("limit") |
| 179 | + private Integer limit; |
| 180 | + |
| 181 | + /** Cursor for pagination to fetch next page of teams. */ |
| 182 | + @Nullable |
| 183 | + @JsonProperty("next") |
| 184 | + private String next; |
| 185 | + |
| 186 | + public static class QueryTeamUsageStatsRequest |
| 187 | + extends StreamRequest<QueryTeamUsageStatsResponse> { |
| 188 | + @Override |
| 189 | + protected Call<QueryTeamUsageStatsResponse> generateCall(Client client) { |
| 190 | + return client.create(StatsService.class).queryTeamUsageStats(this.internalBuild()); |
| 191 | + } |
| 192 | + } |
| 193 | + } |
| 194 | + |
| 195 | + @Data |
| 196 | + @NoArgsConstructor |
| 197 | + @EqualsAndHashCode(callSuper = true) |
| 198 | + public static class QueryTeamUsageStatsResponse extends StreamResponseObject { |
| 199 | + /** Array of team usage statistics. */ |
| 200 | + @NotNull |
| 201 | + @JsonProperty("teams") |
| 202 | + private List<TeamUsageStats> teams; |
| 203 | + |
| 204 | + /** Cursor for pagination to fetch next page. */ |
| 205 | + @Nullable |
| 206 | + @JsonProperty("next") |
| 207 | + private String next; |
| 208 | + } |
| 209 | + |
| 210 | + /** |
| 211 | + * Queries team-level usage statistics from the warehouse database. |
| 212 | + * |
| 213 | + * <p>Returns all 16 metrics grouped by team with cursor-based pagination. |
| 214 | + * |
| 215 | + * <p>Date Range Options (mutually exclusive): |
| 216 | + * |
| 217 | + * <ul> |
| 218 | + * <li>Use 'month' parameter (YYYY-MM format) for monthly aggregated values |
| 219 | + * <li>Use 'startDate'/'endDate' parameters (YYYY-MM-DD format) for daily breakdown |
| 220 | + * <li>If neither provided, defaults to current month (monthly mode) |
| 221 | + * </ul> |
| 222 | + * |
| 223 | + * <p>This endpoint is server-side only. |
| 224 | + * |
| 225 | + * @return the created request |
| 226 | + */ |
| 227 | + @NotNull |
| 228 | + public static QueryTeamUsageStatsRequest queryTeamUsageStats() { |
| 229 | + return new QueryTeamUsageStatsRequest(); |
| 230 | + } |
| 231 | +} |
0 commit comments