001package com.box.sdkgen.managers.hubdocument;
002
003import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
004import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
005import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
006import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
007import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
008
009import com.box.sdkgen.networking.auth.Authentication;
010import com.box.sdkgen.networking.fetchoptions.FetchOptions;
011import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
012import com.box.sdkgen.networking.fetchresponse.FetchResponse;
013import com.box.sdkgen.networking.network.NetworkSession;
014import com.box.sdkgen.schemas.v2025r0.hubdocumentblocksv2025r0.HubDocumentBlocksV2025R0;
015import com.box.sdkgen.schemas.v2025r0.hubdocumentpagesv2025r0.HubDocumentPagesV2025R0;
016import com.box.sdkgen.serialization.json.JsonManager;
017import java.util.Map;
018
019public class HubDocumentManager {
020
021  public Authentication auth;
022
023  public NetworkSession networkSession;
024
025  public HubDocumentManager() {
026    this.networkSession = new NetworkSession();
027  }
028
029  protected HubDocumentManager(Builder builder) {
030    this.auth = builder.auth;
031    this.networkSession = builder.networkSession;
032  }
033
034  /**
035   * Retrieves a list of Hub Document Pages for the specified hub. Includes both root-level pages
036   * and sub pages.
037   *
038   * @param queryParams Query parameters of getHubDocumentPagesV2025R0 method
039   */
040  public HubDocumentPagesV2025R0 getHubDocumentPagesV2025R0(
041      GetHubDocumentPagesV2025R0QueryParams queryParams) {
042    return getHubDocumentPagesV2025R0(queryParams, new GetHubDocumentPagesV2025R0Headers());
043  }
044
045  /**
046   * Retrieves a list of Hub Document Pages for the specified hub. Includes both root-level pages
047   * and sub pages.
048   *
049   * @param queryParams Query parameters of getHubDocumentPagesV2025R0 method
050   * @param headers Headers of getHubDocumentPagesV2025R0 method
051   */
052  public HubDocumentPagesV2025R0 getHubDocumentPagesV2025R0(
053      GetHubDocumentPagesV2025R0QueryParams queryParams,
054      GetHubDocumentPagesV2025R0Headers headers) {
055    Map<String, String> queryParamsMap =
056        prepareParams(
057            mapOf(
058                entryOf("hub_id", convertToString(queryParams.getHubId())),
059                entryOf("marker", convertToString(queryParams.getMarker())),
060                entryOf("limit", convertToString(queryParams.getLimit()))));
061    Map<String, String> headersMap =
062        prepareParams(
063            mergeMaps(
064                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
065                headers.getExtraHeaders()));
066    FetchResponse response =
067        this.networkSession
068            .getNetworkClient()
069            .fetch(
070                new FetchOptions.Builder(
071                        String.join(
072                            "",
073                            this.networkSession.getBaseUrls().getBaseUrl(),
074                            "/2.0/hub_document_pages"),
075                        "GET")
076                    .params(queryParamsMap)
077                    .headers(headersMap)
078                    .responseFormat(ResponseFormat.JSON)
079                    .auth(this.auth)
080                    .networkSession(this.networkSession)
081                    .build());
082    return JsonManager.deserialize(response.getData(), HubDocumentPagesV2025R0.class);
083  }
084
085  /**
086   * Retrieves a sorted list of all Hub Document Blocks on a specified page in the hub document,
087   * excluding items. Blocks are hierarchically organized by their `parent_id`. Blocks are sorted in
088   * order based on user specification in the user interface. The response will only include content
089   * blocks that belong to the specified page. This will not include sub pages or sub page content
090   * blocks.
091   *
092   * @param queryParams Query parameters of getHubDocumentBlocksV2025R0 method
093   */
094  public HubDocumentBlocksV2025R0 getHubDocumentBlocksV2025R0(
095      GetHubDocumentBlocksV2025R0QueryParams queryParams) {
096    return getHubDocumentBlocksV2025R0(queryParams, new GetHubDocumentBlocksV2025R0Headers());
097  }
098
099  /**
100   * Retrieves a sorted list of all Hub Document Blocks on a specified page in the hub document,
101   * excluding items. Blocks are hierarchically organized by their `parent_id`. Blocks are sorted in
102   * order based on user specification in the user interface. The response will only include content
103   * blocks that belong to the specified page. This will not include sub pages or sub page content
104   * blocks.
105   *
106   * @param queryParams Query parameters of getHubDocumentBlocksV2025R0 method
107   * @param headers Headers of getHubDocumentBlocksV2025R0 method
108   */
109  public HubDocumentBlocksV2025R0 getHubDocumentBlocksV2025R0(
110      GetHubDocumentBlocksV2025R0QueryParams queryParams,
111      GetHubDocumentBlocksV2025R0Headers headers) {
112    Map<String, String> queryParamsMap =
113        prepareParams(
114            mapOf(
115                entryOf("hub_id", convertToString(queryParams.getHubId())),
116                entryOf("page_id", convertToString(queryParams.getPageId())),
117                entryOf("marker", convertToString(queryParams.getMarker())),
118                entryOf("limit", convertToString(queryParams.getLimit()))));
119    Map<String, String> headersMap =
120        prepareParams(
121            mergeMaps(
122                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
123                headers.getExtraHeaders()));
124    FetchResponse response =
125        this.networkSession
126            .getNetworkClient()
127            .fetch(
128                new FetchOptions.Builder(
129                        String.join(
130                            "",
131                            this.networkSession.getBaseUrls().getBaseUrl(),
132                            "/2.0/hub_document_blocks"),
133                        "GET")
134                    .params(queryParamsMap)
135                    .headers(headersMap)
136                    .responseFormat(ResponseFormat.JSON)
137                    .auth(this.auth)
138                    .networkSession(this.networkSession)
139                    .build());
140    return JsonManager.deserialize(response.getData(), HubDocumentBlocksV2025R0.class);
141  }
142
143  public Authentication getAuth() {
144    return auth;
145  }
146
147  public NetworkSession getNetworkSession() {
148    return networkSession;
149  }
150
151  public static class Builder {
152
153    protected Authentication auth;
154
155    protected NetworkSession networkSession;
156
157    public Builder() {}
158
159    public Builder auth(Authentication auth) {
160      this.auth = auth;
161      return this;
162    }
163
164    public Builder networkSession(NetworkSession networkSession) {
165      this.networkSession = networkSession;
166      return this;
167    }
168
169    public HubDocumentManager build() {
170      if (this.networkSession == null) {
171        this.networkSession = new NetworkSession();
172      }
173      return new HubDocumentManager(this);
174    }
175  }
176}