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