001// Generated by delombok at Thu Aug 13 13:56:43 UTC 2026
002/*
003 * Copyright (c) 2010-2026 Mark Allen, Norbert Bartels.
004 *
005 * Permission is hereby granted, free of charge, to any person obtaining a copy
006 * of this software and associated documentation files (the "Software"), to deal
007 * in the Software without restriction, including without limitation the rights
008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
009 * copies of the Software, and to permit persons to whom the Software is
010 * furnished to do so, subject to the following conditions:
011 *
012 * The above copyright notice and this permission notice shall be included in
013 * all copies or substantial portions of the Software.
014 *
015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
021 * THE SOFTWARE.
022 */
023package com.restfb;
024
025import java.io.Serializable;
026import java.util.ArrayList;
027import java.util.HashMap;
028import java.util.List;
029import java.util.Map;
030import com.restfb.json.Json;
031import com.restfb.json.JsonObject;
032import com.restfb.util.StringUtils;
033
034public class DebugHeaderInfo implements Serializable {
035  /**
036   * x-fb-debug
037   */
038  private final String debug;
039  /**
040   * x-fb-rev
041   */
042  private final String rev;
043  /**
044   * x-fb-trace-id
045   */
046  private final String traceId;
047  /**
048   * the use version
049   */
050  private final Version usedVersion;
051  /**
052   * x-app-usage
053   */
054  private final HeaderUsage appUsage;
055  /**
056   * x-page-usage
057   */
058  private final HeaderUsage pageUsage;
059  /**
060   * x-ad-account-usage
061   */
062  private final HeaderUsage adAccountUsage;
063  private final BusinessUseCaseUsage businessUseCaseUsage;
064
065  private DebugHeaderInfo(String debug, String rev, String traceId, Version version, String appUsage, String pageUsage, String adAccountUsage, String businessUsage) {
066    this.debug = debug;
067    this.rev = rev;
068    this.traceId = traceId;
069    this.usedVersion = version;
070    this.appUsage = createUsage(appUsage);
071    this.pageUsage = createUsage(pageUsage);
072    this.adAccountUsage = createUsage(adAccountUsage);
073    this.businessUseCaseUsage = createBusinessUsage(businessUsage);
074  }
075
076  /**
077   * get Facebook response header field <code>x-fb-debug</code>
078   *
079   * @return the Facebook response header field <code>x-fb-debug</code>
080   */
081  public String getDebug() {
082    return debug;
083  }
084
085  /**
086   * get Facebook response header field <code>x-fb-rev</code>
087   *
088   * @return the Facebook response header field <code>x-fb-rev</code>
089   */
090  public String getRev() {
091    return rev;
092  }
093
094  /**
095   * get Facebook response header field <code>x-fb-trace-id</code>
096   *
097   * @return the Facebook response header field x-fb-trace-id
098   */
099  public String getTraceId() {
100    return traceId;
101  }
102
103  /**
104   * get the version, facebook used internally to fulfill the request
105   *
106   * @return the version, facebook used internally to fulfill the request
107   */
108  public Version getUsedVersion() {
109    return usedVersion;
110  }
111
112  /**
113   * get Facebook response header field <code>x-app-usage</code>
114   *
115   * @return the Facebook response header field x-app-usage
116   */
117  public HeaderUsage getAppUsage() {
118    return appUsage;
119  }
120
121  /**
122   * get Facebook response header field <code>x-page-usage</code>
123   *
124   * @return the Facebook response header field x-page-usage
125   */
126  public HeaderUsage getPageUsage() {
127    return pageUsage;
128  }
129
130  /**
131   * get Facebook response header field <code>x-ad-account-usage</code>
132   *
133   * @return the Facebook response header field x-ad-account-usage
134   */
135  public HeaderUsage getAdAccountUsage() {
136    return adAccountUsage;
137  }
138
139  public BusinessUseCaseUsage getBusinessUseCaseUsage() {
140    return businessUseCaseUsage;
141  }
142
143  private BusinessUseCaseUsage createBusinessUsage(String businessUsageInformation) {
144    if (StringUtils.isBlank(businessUsageInformation)) {
145      return null;
146    }
147    try {
148      DefaultJsonMapper jsonMapper = new DefaultJsonMapper();
149      JsonObject jsonObject = Json.parse(businessUsageInformation).asObject();
150      BusinessUseCaseUsage usage = new BusinessUseCaseUsage();
151      for (String key : jsonObject.names()) {
152        usage.put(key, jsonMapper.toJavaList(jsonObject.get(key).toString(), InnerBusinessUseCaseUsage.class));
153      }
154      return usage;
155    } catch (Exception e) {
156      return null;
157    }
158  }
159
160  private HeaderUsage createUsage(String usageInformation) {
161    if (StringUtils.isBlank(usageInformation)) {
162      return null;
163    }
164    try {
165      JsonObject jsonValue = Json.parse(usageInformation).asObject();
166      if (jsonValue.names().size() == 1 && jsonValue.contains("acc_id_util_pct")) {
167        return new HeaderUsage(jsonValue.getDouble("acc_id_util_pct", 0.0));
168      }
169      if (jsonValue.contains("call_volume") && jsonValue.contains("cpu_time")) {
170        return new HeaderUsage(jsonValue.getInt("call_volume", -1), jsonValue.getInt("cpu_time", -1));
171      }
172      return new HeaderUsage(jsonValue.getInt("call_count", -1), jsonValue.getInt("total_time", -1), jsonValue.getInt("total_cputime", -1));
173    } catch (Exception e) {
174      return new HeaderUsage(usageInformation);
175    }
176  }
177
178
179  /**
180   * business use case based usage object.
181   * <p>
182   * This usage object is used in Graph API 3.3+ and provides access to the complete set of inner objects.
183   */
184  public static class BusinessUseCaseUsage implements Serializable {
185    private Map<String, List<InnerBusinessUseCaseUsage>> usageMap = new HashMap<>();
186
187    /**
188     * add a new list of usages that belongs to the business id to the outer object
189     *
190     * @param key
191     *          the business id the list of usages is connected with
192     * @param businessUseCaseUsageList
193     *          the list of usages
194     */
195    void put(String key, List<InnerBusinessUseCaseUsage> businessUseCaseUsageList) {
196      usageMap.put(key, businessUseCaseUsageList);
197    }
198
199    /**
200     * returns the usage list that belongs to the given business id
201     *
202     * @param businessId
203     *          the business ids you like to fetch the usage list for
204     * @return the list of usages
205     */
206    public List<InnerBusinessUseCaseUsage> get(String businessId) {
207      return usageMap.get(businessId);
208    }
209
210    /**
211     * returns the list of Business Ids that are provided in the the business use case usage header
212     *
213     * @return list of business ids
214     */
215    public List<String> getBusinessIds() {
216      return new ArrayList<>(usageMap.keySet());
217    }
218  }
219
220
221  public static class InnerBusinessUseCaseUsage implements Serializable {
222    /**
223     * Percentage of calls made for this business id/business ad account
224     */
225    @Facebook("call_count")
226    private Integer callCount;
227    /**
228     * Percentage of the total CPU time that has been used
229     */
230    @Facebook("total_cputime")
231    private Integer totalCputime;
232    /**
233     * Percentage of the total time that has been used
234     */
235    @Facebook("total_time")
236    private Integer totalTime;
237    /**
238     * Type of rate limit logic being applied
239     */
240    @Facebook
241    private String type;
242    /**
243     * Time in minutes to resume calls
244     */
245    @Facebook("estimated_time_to_regain_access")
246    private Integer estimatedTimeToRegainAccess;
247
248    /**
249     * Percentage of calls made for this business id/business ad account
250     */
251    @java.lang.SuppressWarnings("all")
252    @lombok.Generated
253    public Integer getCallCount() {
254      return this.callCount;
255    }
256
257    /**
258     * Percentage of the total CPU time that has been used
259     */
260    @java.lang.SuppressWarnings("all")
261    @lombok.Generated
262    public Integer getTotalCputime() {
263      return this.totalCputime;
264    }
265
266    /**
267     * Percentage of the total time that has been used
268     */
269    @java.lang.SuppressWarnings("all")
270    @lombok.Generated
271    public Integer getTotalTime() {
272      return this.totalTime;
273    }
274
275    /**
276     * Type of rate limit logic being applied
277     */
278    @java.lang.SuppressWarnings("all")
279    @lombok.Generated
280    public String getType() {
281      return this.type;
282    }
283
284    /**
285     * Time in minutes to resume calls
286     */
287    @java.lang.SuppressWarnings("all")
288    @lombok.Generated
289    public Integer getEstimatedTimeToRegainAccess() {
290      return this.estimatedTimeToRegainAccess;
291    }
292  }
293
294
295  public static class HeaderUsage implements Serializable {
296    HeaderUsage(String percentage) {
297      this.percentage = percentage;
298      this.percentageOnly = true;
299      this.adAccountHeader = false;
300    }
301
302    HeaderUsage(Integer callVolume, Integer cpuTime) {
303      this.callVolume = callVolume;
304      this.cpuTime = cpuTime;
305      this.percentageOnly = false;
306      this.adAccountHeader = false;
307    }
308
309    HeaderUsage(Integer callCount, Integer totalTime, Integer totalCputime) {
310      this.callCount = callCount;
311      this.totalTime = totalTime;
312      this.totalCputime = totalCputime;
313      this.percentageOnly = false;
314      this.adAccountHeader = false;
315    }
316
317    HeaderUsage(Double percentage) {
318      this.accIdUtilPct = percentage;
319      this.percentageOnly = false;
320      this.adAccountHeader = true;
321    }
322
323    private final boolean percentageOnly;
324    private final boolean adAccountHeader;
325    private String percentage;
326    private Integer callCount;
327    private Integer callVolume;
328    private Integer totalTime;
329    private Integer totalCputime;
330    private Integer cpuTime;
331    private Double accIdUtilPct;
332
333    @java.lang.SuppressWarnings("all")
334    @lombok.Generated
335    public boolean isPercentageOnly() {
336      return this.percentageOnly;
337    }
338
339    @java.lang.SuppressWarnings("all")
340    @lombok.Generated
341    public boolean isAdAccountHeader() {
342      return this.adAccountHeader;
343    }
344
345    @java.lang.SuppressWarnings("all")
346    @lombok.Generated
347    public String getPercentage() {
348      return this.percentage;
349    }
350
351    @java.lang.SuppressWarnings("all")
352    @lombok.Generated
353    public Integer getCallCount() {
354      return this.callCount;
355    }
356
357    @java.lang.SuppressWarnings("all")
358    @lombok.Generated
359    public Integer getCallVolume() {
360      return this.callVolume;
361    }
362
363    @java.lang.SuppressWarnings("all")
364    @lombok.Generated
365    public Integer getTotalTime() {
366      return this.totalTime;
367    }
368
369    @java.lang.SuppressWarnings("all")
370    @lombok.Generated
371    public Integer getTotalCputime() {
372      return this.totalCputime;
373    }
374
375    @java.lang.SuppressWarnings("all")
376    @lombok.Generated
377    public Integer getCpuTime() {
378      return this.cpuTime;
379    }
380
381    @java.lang.SuppressWarnings("all")
382    @lombok.Generated
383    public Double getAccIdUtilPct() {
384      return this.accIdUtilPct;
385    }
386  }
387
388
389  public static class DebugHeaderInfoFactory implements Serializable {
390    private String debug;
391    private String rev;
392    private String traceId;
393    private Version version;
394    private String appUsage;
395    private String pageUsage;
396    private String adAccountUsage;
397    private String businessUseCaseUsage;
398
399    public static DebugHeaderInfoFactory create() {
400      return new DebugHeaderInfoFactory();
401    }
402
403    public DebugHeaderInfoFactory setVersion(Version version) {
404      this.version = version;
405      return this;
406    }
407
408    public DebugHeaderInfoFactory setDebug(String debug) {
409      this.debug = debug;
410      return this;
411    }
412
413    public DebugHeaderInfoFactory setRev(String rev) {
414      this.rev = rev;
415      return this;
416    }
417
418    public DebugHeaderInfoFactory setTraceId(String traceId) {
419      this.traceId = traceId;
420      return this;
421    }
422
423    public DebugHeaderInfoFactory setAppUsage(String appUsage) {
424      this.appUsage = appUsage;
425      return this;
426    }
427
428    public DebugHeaderInfoFactory setPageUsage(String pageUsage) {
429      this.pageUsage = pageUsage;
430      return this;
431    }
432
433    public DebugHeaderInfoFactory setAdAccountUsage(String adAccountUsage) {
434      this.adAccountUsage = adAccountUsage;
435      return this;
436    }
437
438    public DebugHeaderInfoFactory setBusinessUseCaseUsage(String businessUseCaseUsage) {
439      this.businessUseCaseUsage = businessUseCaseUsage;
440      return this;
441    }
442
443    public DebugHeaderInfo build() {
444      return new DebugHeaderInfo(this.debug, this.rev, this.traceId, this.version, this.appUsage, this.pageUsage, this.adAccountUsage, this.businessUseCaseUsage);
445    }
446  }
447}