|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.langchain.smith.models.sessions.insights |
| 4 | + |
| 5 | +import com.langchain.smith.core.AutoPagerAsync |
| 6 | +import com.langchain.smith.core.PageAsync |
| 7 | +import com.langchain.smith.core.checkRequired |
| 8 | +import com.langchain.smith.services.async.sessions.InsightServiceAsync |
| 9 | +import java.util.Objects |
| 10 | +import java.util.concurrent.CompletableFuture |
| 11 | +import java.util.concurrent.Executor |
| 12 | +import kotlin.jvm.optionals.getOrDefault |
| 13 | +import kotlin.jvm.optionals.getOrNull |
| 14 | + |
| 15 | +/** @see InsightServiceAsync.list */ |
| 16 | +class InsightListPageAsync |
| 17 | +private constructor( |
| 18 | + private val service: InsightServiceAsync, |
| 19 | + private val streamHandlerExecutor: Executor, |
| 20 | + private val params: InsightListParams, |
| 21 | + private val response: InsightListPageResponse, |
| 22 | +) : PageAsync<InsightListResponse> { |
| 23 | + |
| 24 | + /** |
| 25 | + * Delegates to [InsightListPageResponse], but gracefully handles missing data. |
| 26 | + * |
| 27 | + * @see InsightListPageResponse.clusteringJobs |
| 28 | + */ |
| 29 | + fun clusteringJobs(): List<InsightListResponse> = |
| 30 | + response._clusteringJobs().getOptional("clustering_jobs").getOrNull() ?: emptyList() |
| 31 | + |
| 32 | + override fun items(): List<InsightListResponse> = clusteringJobs() |
| 33 | + |
| 34 | + override fun hasNextPage(): Boolean = items().isNotEmpty() |
| 35 | + |
| 36 | + fun nextPageParams(): InsightListParams { |
| 37 | + val offset = params.offset().getOrDefault(0) |
| 38 | + return params.toBuilder().offset(offset + items().size).build() |
| 39 | + } |
| 40 | + |
| 41 | + override fun nextPage(): CompletableFuture<InsightListPageAsync> = |
| 42 | + service.list(nextPageParams()) |
| 43 | + |
| 44 | + fun autoPager(): AutoPagerAsync<InsightListResponse> = |
| 45 | + AutoPagerAsync.from(this, streamHandlerExecutor) |
| 46 | + |
| 47 | + /** The parameters that were used to request this page. */ |
| 48 | + fun params(): InsightListParams = params |
| 49 | + |
| 50 | + /** The response that this page was parsed from. */ |
| 51 | + fun response(): InsightListPageResponse = response |
| 52 | + |
| 53 | + fun toBuilder() = Builder().from(this) |
| 54 | + |
| 55 | + companion object { |
| 56 | + |
| 57 | + /** |
| 58 | + * Returns a mutable builder for constructing an instance of [InsightListPageAsync]. |
| 59 | + * |
| 60 | + * The following fields are required: |
| 61 | + * ```java |
| 62 | + * .service() |
| 63 | + * .streamHandlerExecutor() |
| 64 | + * .params() |
| 65 | + * .response() |
| 66 | + * ``` |
| 67 | + */ |
| 68 | + @JvmStatic fun builder() = Builder() |
| 69 | + } |
| 70 | + |
| 71 | + /** A builder for [InsightListPageAsync]. */ |
| 72 | + class Builder internal constructor() { |
| 73 | + |
| 74 | + private var service: InsightServiceAsync? = null |
| 75 | + private var streamHandlerExecutor: Executor? = null |
| 76 | + private var params: InsightListParams? = null |
| 77 | + private var response: InsightListPageResponse? = null |
| 78 | + |
| 79 | + @JvmSynthetic |
| 80 | + internal fun from(insightListPageAsync: InsightListPageAsync) = apply { |
| 81 | + service = insightListPageAsync.service |
| 82 | + streamHandlerExecutor = insightListPageAsync.streamHandlerExecutor |
| 83 | + params = insightListPageAsync.params |
| 84 | + response = insightListPageAsync.response |
| 85 | + } |
| 86 | + |
| 87 | + fun service(service: InsightServiceAsync) = apply { this.service = service } |
| 88 | + |
| 89 | + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { |
| 90 | + this.streamHandlerExecutor = streamHandlerExecutor |
| 91 | + } |
| 92 | + |
| 93 | + /** The parameters that were used to request this page. */ |
| 94 | + fun params(params: InsightListParams) = apply { this.params = params } |
| 95 | + |
| 96 | + /** The response that this page was parsed from. */ |
| 97 | + fun response(response: InsightListPageResponse) = apply { this.response = response } |
| 98 | + |
| 99 | + /** |
| 100 | + * Returns an immutable instance of [InsightListPageAsync]. |
| 101 | + * |
| 102 | + * Further updates to this [Builder] will not mutate the returned instance. |
| 103 | + * |
| 104 | + * The following fields are required: |
| 105 | + * ```java |
| 106 | + * .service() |
| 107 | + * .streamHandlerExecutor() |
| 108 | + * .params() |
| 109 | + * .response() |
| 110 | + * ``` |
| 111 | + * |
| 112 | + * @throws IllegalStateException if any required field is unset. |
| 113 | + */ |
| 114 | + fun build(): InsightListPageAsync = |
| 115 | + InsightListPageAsync( |
| 116 | + checkRequired("service", service), |
| 117 | + checkRequired("streamHandlerExecutor", streamHandlerExecutor), |
| 118 | + checkRequired("params", params), |
| 119 | + checkRequired("response", response), |
| 120 | + ) |
| 121 | + } |
| 122 | + |
| 123 | + override fun equals(other: Any?): Boolean { |
| 124 | + if (this === other) { |
| 125 | + return true |
| 126 | + } |
| 127 | + |
| 128 | + return other is InsightListPageAsync && |
| 129 | + service == other.service && |
| 130 | + streamHandlerExecutor == other.streamHandlerExecutor && |
| 131 | + params == other.params && |
| 132 | + response == other.response |
| 133 | + } |
| 134 | + |
| 135 | + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) |
| 136 | + |
| 137 | + override fun toString() = |
| 138 | + "InsightListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" |
| 139 | +} |
0 commit comments