001package com.box.sdkgen.managers.docgen;
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.docgenbatchbasev2025r0.DocGenBatchBaseV2025R0;
015import com.box.sdkgen.schemas.v2025r0.docgenbatchcreaterequestv2025r0.DocGenBatchCreateRequestV2025R0;
016import com.box.sdkgen.schemas.v2025r0.docgenjobsfullv2025r0.DocGenJobsFullV2025R0;
017import com.box.sdkgen.schemas.v2025r0.docgenjobsv2025r0.DocGenJobsV2025R0;
018import com.box.sdkgen.schemas.v2025r0.docgenjobv2025r0.DocGenJobV2025R0;
019import com.box.sdkgen.serialization.json.JsonManager;
020import java.util.Map;
021
022public class DocgenManager {
023
024  public Authentication auth;
025
026  public NetworkSession networkSession;
027
028  public DocgenManager() {
029    this.networkSession = new NetworkSession();
030  }
031
032  protected DocgenManager(Builder builder) {
033    this.auth = builder.auth;
034    this.networkSession = builder.networkSession;
035  }
036
037  /**
038   * Get details of the Box Doc Gen job.
039   *
040   * @param jobId Box Doc Gen job ID. Example: 123
041   */
042  public DocGenJobV2025R0 getDocgenJobByIdV2025R0(String jobId) {
043    return getDocgenJobByIdV2025R0(jobId, new GetDocgenJobByIdV2025R0Headers());
044  }
045
046  /**
047   * Get details of the Box Doc Gen job.
048   *
049   * @param jobId Box Doc Gen job ID. Example: 123
050   * @param headers Headers of getDocgenJobByIdV2025R0 method
051   */
052  public DocGenJobV2025R0 getDocgenJobByIdV2025R0(
053      String jobId, GetDocgenJobByIdV2025R0Headers headers) {
054    Map<String, String> headersMap =
055        prepareParams(
056            mergeMaps(
057                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
058                headers.getExtraHeaders()));
059    FetchResponse response =
060        this.networkSession
061            .getNetworkClient()
062            .fetch(
063                new FetchOptions.Builder(
064                        String.join(
065                            "",
066                            this.networkSession.getBaseUrls().getBaseUrl(),
067                            "/2.0/docgen_jobs/",
068                            convertToString(jobId)),
069                        "GET")
070                    .headers(headersMap)
071                    .responseFormat(ResponseFormat.JSON)
072                    .auth(this.auth)
073                    .networkSession(this.networkSession)
074                    .build());
075    return JsonManager.deserialize(response.getData(), DocGenJobV2025R0.class);
076  }
077
078  /** Lists all Box Doc Gen jobs for a user. */
079  public DocGenJobsFullV2025R0 getDocgenJobsV2025R0() {
080    return getDocgenJobsV2025R0(
081        new GetDocgenJobsV2025R0QueryParams(), new GetDocgenJobsV2025R0Headers());
082  }
083
084  /**
085   * Lists all Box Doc Gen jobs for a user.
086   *
087   * @param queryParams Query parameters of getDocgenJobsV2025R0 method
088   */
089  public DocGenJobsFullV2025R0 getDocgenJobsV2025R0(GetDocgenJobsV2025R0QueryParams queryParams) {
090    return getDocgenJobsV2025R0(queryParams, new GetDocgenJobsV2025R0Headers());
091  }
092
093  /**
094   * Lists all Box Doc Gen jobs for a user.
095   *
096   * @param headers Headers of getDocgenJobsV2025R0 method
097   */
098  public DocGenJobsFullV2025R0 getDocgenJobsV2025R0(GetDocgenJobsV2025R0Headers headers) {
099    return getDocgenJobsV2025R0(new GetDocgenJobsV2025R0QueryParams(), headers);
100  }
101
102  /**
103   * Lists all Box Doc Gen jobs for a user.
104   *
105   * @param queryParams Query parameters of getDocgenJobsV2025R0 method
106   * @param headers Headers of getDocgenJobsV2025R0 method
107   */
108  public DocGenJobsFullV2025R0 getDocgenJobsV2025R0(
109      GetDocgenJobsV2025R0QueryParams queryParams, GetDocgenJobsV2025R0Headers headers) {
110    Map<String, String> queryParamsMap =
111        prepareParams(
112            mapOf(
113                entryOf("marker", convertToString(queryParams.getMarker())),
114                entryOf("limit", convertToString(queryParams.getLimit()))));
115    Map<String, String> headersMap =
116        prepareParams(
117            mergeMaps(
118                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
119                headers.getExtraHeaders()));
120    FetchResponse response =
121        this.networkSession
122            .getNetworkClient()
123            .fetch(
124                new FetchOptions.Builder(
125                        String.join(
126                            "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/docgen_jobs"),
127                        "GET")
128                    .params(queryParamsMap)
129                    .headers(headersMap)
130                    .responseFormat(ResponseFormat.JSON)
131                    .auth(this.auth)
132                    .networkSession(this.networkSession)
133                    .build());
134    return JsonManager.deserialize(response.getData(), DocGenJobsFullV2025R0.class);
135  }
136
137  /**
138   * Lists Box Doc Gen jobs in a batch.
139   *
140   * @param batchId Box Doc Gen batch ID. Example: 123
141   */
142  public DocGenJobsV2025R0 getDocgenBatchJobByIdV2025R0(String batchId) {
143    return getDocgenBatchJobByIdV2025R0(
144        batchId,
145        new GetDocgenBatchJobByIdV2025R0QueryParams(),
146        new GetDocgenBatchJobByIdV2025R0Headers());
147  }
148
149  /**
150   * Lists Box Doc Gen jobs in a batch.
151   *
152   * @param batchId Box Doc Gen batch ID. Example: 123
153   * @param queryParams Query parameters of getDocgenBatchJobByIdV2025R0 method
154   */
155  public DocGenJobsV2025R0 getDocgenBatchJobByIdV2025R0(
156      String batchId, GetDocgenBatchJobByIdV2025R0QueryParams queryParams) {
157    return getDocgenBatchJobByIdV2025R0(
158        batchId, queryParams, new GetDocgenBatchJobByIdV2025R0Headers());
159  }
160
161  /**
162   * Lists Box Doc Gen jobs in a batch.
163   *
164   * @param batchId Box Doc Gen batch ID. Example: 123
165   * @param headers Headers of getDocgenBatchJobByIdV2025R0 method
166   */
167  public DocGenJobsV2025R0 getDocgenBatchJobByIdV2025R0(
168      String batchId, GetDocgenBatchJobByIdV2025R0Headers headers) {
169    return getDocgenBatchJobByIdV2025R0(
170        batchId, new GetDocgenBatchJobByIdV2025R0QueryParams(), headers);
171  }
172
173  /**
174   * Lists Box Doc Gen jobs in a batch.
175   *
176   * @param batchId Box Doc Gen batch ID. Example: 123
177   * @param queryParams Query parameters of getDocgenBatchJobByIdV2025R0 method
178   * @param headers Headers of getDocgenBatchJobByIdV2025R0 method
179   */
180  public DocGenJobsV2025R0 getDocgenBatchJobByIdV2025R0(
181      String batchId,
182      GetDocgenBatchJobByIdV2025R0QueryParams queryParams,
183      GetDocgenBatchJobByIdV2025R0Headers headers) {
184    Map<String, String> queryParamsMap =
185        prepareParams(
186            mapOf(
187                entryOf("marker", convertToString(queryParams.getMarker())),
188                entryOf("limit", convertToString(queryParams.getLimit()))));
189    Map<String, String> headersMap =
190        prepareParams(
191            mergeMaps(
192                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
193                headers.getExtraHeaders()));
194    FetchResponse response =
195        this.networkSession
196            .getNetworkClient()
197            .fetch(
198                new FetchOptions.Builder(
199                        String.join(
200                            "",
201                            this.networkSession.getBaseUrls().getBaseUrl(),
202                            "/2.0/docgen_batch_jobs/",
203                            convertToString(batchId)),
204                        "GET")
205                    .params(queryParamsMap)
206                    .headers(headersMap)
207                    .responseFormat(ResponseFormat.JSON)
208                    .auth(this.auth)
209                    .networkSession(this.networkSession)
210                    .build());
211    return JsonManager.deserialize(response.getData(), DocGenJobsV2025R0.class);
212  }
213
214  /**
215   * Generates a document using a Box Doc Gen template.
216   *
217   * @param requestBody Request body of createDocgenBatchV2025R0 method
218   */
219  public DocGenBatchBaseV2025R0 createDocgenBatchV2025R0(
220      DocGenBatchCreateRequestV2025R0 requestBody) {
221    return createDocgenBatchV2025R0(requestBody, new CreateDocgenBatchV2025R0Headers());
222  }
223
224  /**
225   * Generates a document using a Box Doc Gen template.
226   *
227   * @param requestBody Request body of createDocgenBatchV2025R0 method
228   * @param headers Headers of createDocgenBatchV2025R0 method
229   */
230  public DocGenBatchBaseV2025R0 createDocgenBatchV2025R0(
231      DocGenBatchCreateRequestV2025R0 requestBody, CreateDocgenBatchV2025R0Headers headers) {
232    Map<String, String> headersMap =
233        prepareParams(
234            mergeMaps(
235                mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))),
236                headers.getExtraHeaders()));
237    FetchResponse response =
238        this.networkSession
239            .getNetworkClient()
240            .fetch(
241                new FetchOptions.Builder(
242                        String.join(
243                            "",
244                            this.networkSession.getBaseUrls().getBaseUrl(),
245                            "/2.0/docgen_batches"),
246                        "POST")
247                    .headers(headersMap)
248                    .data(JsonManager.serialize(requestBody))
249                    .contentType("application/json")
250                    .responseFormat(ResponseFormat.JSON)
251                    .auth(this.auth)
252                    .networkSession(this.networkSession)
253                    .build());
254    return JsonManager.deserialize(response.getData(), DocGenBatchBaseV2025R0.class);
255  }
256
257  public Authentication getAuth() {
258    return auth;
259  }
260
261  public NetworkSession getNetworkSession() {
262    return networkSession;
263  }
264
265  public static class Builder {
266
267    protected Authentication auth;
268
269    protected NetworkSession networkSession;
270
271    public Builder() {}
272
273    public Builder auth(Authentication auth) {
274      this.auth = auth;
275      return this;
276    }
277
278    public Builder networkSession(NetworkSession networkSession) {
279      this.networkSession = networkSession;
280      return this;
281    }
282
283    public DocgenManager build() {
284      if (this.networkSession == null) {
285        this.networkSession = new NetworkSession();
286      }
287      return new DocgenManager(this);
288    }
289  }
290}