|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.tryfinch.api.models |
| 4 | + |
| 5 | +import com.tryfinch.api.core.AutoPagerAsync |
| 6 | +import com.tryfinch.api.core.PageAsync |
| 7 | +import com.tryfinch.api.core.checkRequired |
| 8 | +import com.tryfinch.api.services.async.hris.DirectoryServiceAsync |
| 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.getOrDefault |
| 14 | +import kotlin.jvm.optionals.getOrNull |
| 15 | + |
| 16 | +/** @see DirectoryServiceAsync.listIndividuals */ |
| 17 | +@Deprecated("use `list` instead") |
| 18 | +class HrisDirectoryListIndividualsPageAsync |
| 19 | +private constructor( |
| 20 | + private val service: DirectoryServiceAsync, |
| 21 | + private val streamHandlerExecutor: Executor, |
| 22 | + private val params: HrisDirectoryListIndividualsParams, |
| 23 | + private val response: HrisDirectoryListIndividualsPageResponse, |
| 24 | +) : PageAsync<IndividualInDirectory> { |
| 25 | + |
| 26 | + /** |
| 27 | + * Delegates to [HrisDirectoryListIndividualsPageResponse], but gracefully handles missing data. |
| 28 | + * |
| 29 | + * @see HrisDirectoryListIndividualsPageResponse.individuals |
| 30 | + */ |
| 31 | + fun individuals(): List<IndividualInDirectory> = |
| 32 | + response._individuals().getOptional("individuals").getOrNull() ?: emptyList() |
| 33 | + |
| 34 | + /** |
| 35 | + * Delegates to [HrisDirectoryListIndividualsPageResponse], but gracefully handles missing data. |
| 36 | + * |
| 37 | + * @see HrisDirectoryListIndividualsPageResponse.paging |
| 38 | + */ |
| 39 | + fun paging(): Optional<Paging> = response._paging().getOptional("paging") |
| 40 | + |
| 41 | + override fun items(): List<IndividualInDirectory> = individuals() |
| 42 | + |
| 43 | + override fun hasNextPage(): Boolean { |
| 44 | + if (items().isEmpty()) { |
| 45 | + return false |
| 46 | + } |
| 47 | + |
| 48 | + val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) |
| 49 | + val totalCount = paging().flatMap { it._count().getOptional("count") }.getOrNull() |
| 50 | + return totalCount == null || offset + items().size < totalCount |
| 51 | + } |
| 52 | + |
| 53 | + fun nextPageParams(): HrisDirectoryListIndividualsParams { |
| 54 | + val offset = paging().flatMap { it._offset().getOptional("offset") }.getOrDefault(0) |
| 55 | + return params.toBuilder().offset(offset + items().size).build() |
| 56 | + } |
| 57 | + |
| 58 | + override fun nextPage(): CompletableFuture<HrisDirectoryListIndividualsPageAsync> = |
| 59 | + service.listIndividuals(nextPageParams()) |
| 60 | + |
| 61 | + fun autoPager(): AutoPagerAsync<IndividualInDirectory> = |
| 62 | + AutoPagerAsync.from(this, streamHandlerExecutor) |
| 63 | + |
| 64 | + /** The parameters that were used to request this page. */ |
| 65 | + fun params(): HrisDirectoryListIndividualsParams = params |
| 66 | + |
| 67 | + /** The response that this page was parsed from. */ |
| 68 | + fun response(): HrisDirectoryListIndividualsPageResponse = response |
| 69 | + |
| 70 | + fun toBuilder() = Builder().from(this) |
| 71 | + |
| 72 | + companion object { |
| 73 | + |
| 74 | + /** |
| 75 | + * Returns a mutable builder for constructing an instance of |
| 76 | + * [HrisDirectoryListIndividualsPageAsync]. |
| 77 | + * |
| 78 | + * The following fields are required: |
| 79 | + * ```java |
| 80 | + * .service() |
| 81 | + * .streamHandlerExecutor() |
| 82 | + * .params() |
| 83 | + * .response() |
| 84 | + * ``` |
| 85 | + */ |
| 86 | + @JvmStatic fun builder() = Builder() |
| 87 | + } |
| 88 | + |
| 89 | + /** A builder for [HrisDirectoryListIndividualsPageAsync]. */ |
| 90 | + class Builder internal constructor() { |
| 91 | + |
| 92 | + private var service: DirectoryServiceAsync? = null |
| 93 | + private var streamHandlerExecutor: Executor? = null |
| 94 | + private var params: HrisDirectoryListIndividualsParams? = null |
| 95 | + private var response: HrisDirectoryListIndividualsPageResponse? = null |
| 96 | + |
| 97 | + @JvmSynthetic |
| 98 | + internal fun from( |
| 99 | + hrisDirectoryListIndividualsPageAsync: HrisDirectoryListIndividualsPageAsync |
| 100 | + ) = apply { |
| 101 | + service = hrisDirectoryListIndividualsPageAsync.service |
| 102 | + streamHandlerExecutor = hrisDirectoryListIndividualsPageAsync.streamHandlerExecutor |
| 103 | + params = hrisDirectoryListIndividualsPageAsync.params |
| 104 | + response = hrisDirectoryListIndividualsPageAsync.response |
| 105 | + } |
| 106 | + |
| 107 | + fun service(service: DirectoryServiceAsync) = apply { this.service = service } |
| 108 | + |
| 109 | + fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply { |
| 110 | + this.streamHandlerExecutor = streamHandlerExecutor |
| 111 | + } |
| 112 | + |
| 113 | + /** The parameters that were used to request this page. */ |
| 114 | + fun params(params: HrisDirectoryListIndividualsParams) = apply { this.params = params } |
| 115 | + |
| 116 | + /** The response that this page was parsed from. */ |
| 117 | + fun response(response: HrisDirectoryListIndividualsPageResponse) = apply { |
| 118 | + this.response = response |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Returns an immutable instance of [HrisDirectoryListIndividualsPageAsync]. |
| 123 | + * |
| 124 | + * Further updates to this [Builder] will not mutate the returned instance. |
| 125 | + * |
| 126 | + * The following fields are required: |
| 127 | + * ```java |
| 128 | + * .service() |
| 129 | + * .streamHandlerExecutor() |
| 130 | + * .params() |
| 131 | + * .response() |
| 132 | + * ``` |
| 133 | + * |
| 134 | + * @throws IllegalStateException if any required field is unset. |
| 135 | + */ |
| 136 | + fun build(): HrisDirectoryListIndividualsPageAsync = |
| 137 | + HrisDirectoryListIndividualsPageAsync( |
| 138 | + checkRequired("service", service), |
| 139 | + checkRequired("streamHandlerExecutor", streamHandlerExecutor), |
| 140 | + checkRequired("params", params), |
| 141 | + checkRequired("response", response), |
| 142 | + ) |
| 143 | + } |
| 144 | + |
| 145 | + override fun equals(other: Any?): Boolean { |
| 146 | + if (this === other) { |
| 147 | + return true |
| 148 | + } |
| 149 | + |
| 150 | + return other is HrisDirectoryListIndividualsPageAsync && |
| 151 | + service == other.service && |
| 152 | + streamHandlerExecutor == other.streamHandlerExecutor && |
| 153 | + params == other.params && |
| 154 | + response == other.response |
| 155 | + } |
| 156 | + |
| 157 | + override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response) |
| 158 | + |
| 159 | + override fun toString() = |
| 160 | + "HrisDirectoryListIndividualsPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}" |
| 161 | +} |
0 commit comments