|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.lithic.api.models |
| 4 | + |
| 5 | +import com.lithic.api.core.AutoPager |
| 6 | +import com.lithic.api.core.Page |
| 7 | +import com.lithic.api.core.checkRequired |
| 8 | +import com.lithic.api.services.blocking.AccountActivityService |
| 9 | +import java.util.Objects |
| 10 | +import java.util.Optional |
| 11 | +import kotlin.jvm.optionals.getOrNull |
| 12 | + |
| 13 | +/** @see AccountActivityService.list */ |
| 14 | +class AccountActivityListPage |
| 15 | +private constructor( |
| 16 | + private val service: AccountActivityService, |
| 17 | + private val params: AccountActivityListParams, |
| 18 | + private val response: AccountActivityListPageResponse, |
| 19 | +) : Page<AccountActivityListResponse> { |
| 20 | + |
| 21 | + /** |
| 22 | + * Delegates to [AccountActivityListPageResponse], but gracefully handles missing data. |
| 23 | + * |
| 24 | + * @see AccountActivityListPageResponse.data |
| 25 | + */ |
| 26 | + fun data(): List<AccountActivityListResponse> = |
| 27 | + response._data().getOptional("data").getOrNull() ?: emptyList() |
| 28 | + |
| 29 | + /** |
| 30 | + * Delegates to [AccountActivityListPageResponse], but gracefully handles missing data. |
| 31 | + * |
| 32 | + * @see AccountActivityListPageResponse.hasMore |
| 33 | + */ |
| 34 | + fun hasMore(): Optional<Boolean> = response._hasMore().getOptional("has_more") |
| 35 | + |
| 36 | + override fun items(): List<AccountActivityListResponse> = data() |
| 37 | + |
| 38 | + override fun hasNextPage(): Boolean = items().isNotEmpty() |
| 39 | + |
| 40 | + fun nextPageParams(): AccountActivityListParams = |
| 41 | + if (params.endingBefore().isPresent) { |
| 42 | + params |
| 43 | + .toBuilder() |
| 44 | + .endingBefore( |
| 45 | + items() |
| 46 | + .first() |
| 47 | + .accept( |
| 48 | + object : AccountActivityListResponse.Visitor<Optional<String>> { |
| 49 | + override fun visitFinancialTransaction( |
| 50 | + financialTransaction: |
| 51 | + AccountActivityListResponse.FinancialTransaction |
| 52 | + ): Optional<String> = |
| 53 | + financialTransaction._token().getOptional("token") |
| 54 | + |
| 55 | + override fun visitBookTransferTransaction( |
| 56 | + bookTransferTransaction: |
| 57 | + AccountActivityListResponse.BookTransferTransaction |
| 58 | + ): Optional<String> = |
| 59 | + bookTransferTransaction._token().getOptional("token") |
| 60 | + |
| 61 | + override fun visitCardTransaction( |
| 62 | + cardTransaction: AccountActivityListResponse.CardTransaction |
| 63 | + ): Optional<String> = cardTransaction._token().getOptional("token") |
| 64 | + |
| 65 | + override fun visitPaymentTransaction( |
| 66 | + paymentTransaction: |
| 67 | + AccountActivityListResponse.PaymentTransaction |
| 68 | + ): Optional<String> = |
| 69 | + paymentTransaction._token().getOptional("token") |
| 70 | + |
| 71 | + override fun visitExternalPayment( |
| 72 | + externalPayment: ExternalPayment |
| 73 | + ): Optional<String> = externalPayment._token().getOptional("token") |
| 74 | + |
| 75 | + override fun visitManagementOperationTransaction( |
| 76 | + managementOperationTransaction: ManagementOperationTransaction |
| 77 | + ): Optional<String> = |
| 78 | + managementOperationTransaction._token().getOptional("token") |
| 79 | + } |
| 80 | + ) |
| 81 | + ) |
| 82 | + .build() |
| 83 | + } else { |
| 84 | + params |
| 85 | + .toBuilder() |
| 86 | + .startingAfter( |
| 87 | + items() |
| 88 | + .last() |
| 89 | + .accept( |
| 90 | + object : AccountActivityListResponse.Visitor<Optional<String>> { |
| 91 | + override fun visitFinancialTransaction( |
| 92 | + financialTransaction: |
| 93 | + AccountActivityListResponse.FinancialTransaction |
| 94 | + ): Optional<String> = |
| 95 | + financialTransaction._token().getOptional("token") |
| 96 | + |
| 97 | + override fun visitBookTransferTransaction( |
| 98 | + bookTransferTransaction: |
| 99 | + AccountActivityListResponse.BookTransferTransaction |
| 100 | + ): Optional<String> = |
| 101 | + bookTransferTransaction._token().getOptional("token") |
| 102 | + |
| 103 | + override fun visitCardTransaction( |
| 104 | + cardTransaction: AccountActivityListResponse.CardTransaction |
| 105 | + ): Optional<String> = cardTransaction._token().getOptional("token") |
| 106 | + |
| 107 | + override fun visitPaymentTransaction( |
| 108 | + paymentTransaction: |
| 109 | + AccountActivityListResponse.PaymentTransaction |
| 110 | + ): Optional<String> = |
| 111 | + paymentTransaction._token().getOptional("token") |
| 112 | + |
| 113 | + override fun visitExternalPayment( |
| 114 | + externalPayment: ExternalPayment |
| 115 | + ): Optional<String> = externalPayment._token().getOptional("token") |
| 116 | + |
| 117 | + override fun visitManagementOperationTransaction( |
| 118 | + managementOperationTransaction: ManagementOperationTransaction |
| 119 | + ): Optional<String> = |
| 120 | + managementOperationTransaction._token().getOptional("token") |
| 121 | + } |
| 122 | + ) |
| 123 | + ) |
| 124 | + .build() |
| 125 | + } |
| 126 | + |
| 127 | + override fun nextPage(): AccountActivityListPage = service.list(nextPageParams()) |
| 128 | + |
| 129 | + fun autoPager(): AutoPager<AccountActivityListResponse> = AutoPager.from(this) |
| 130 | + |
| 131 | + /** The parameters that were used to request this page. */ |
| 132 | + fun params(): AccountActivityListParams = params |
| 133 | + |
| 134 | + /** The response that this page was parsed from. */ |
| 135 | + fun response(): AccountActivityListPageResponse = response |
| 136 | + |
| 137 | + fun toBuilder() = Builder().from(this) |
| 138 | + |
| 139 | + companion object { |
| 140 | + |
| 141 | + /** |
| 142 | + * Returns a mutable builder for constructing an instance of [AccountActivityListPage]. |
| 143 | + * |
| 144 | + * The following fields are required: |
| 145 | + * ```java |
| 146 | + * .service() |
| 147 | + * .params() |
| 148 | + * .response() |
| 149 | + * ``` |
| 150 | + */ |
| 151 | + @JvmStatic fun builder() = Builder() |
| 152 | + } |
| 153 | + |
| 154 | + /** A builder for [AccountActivityListPage]. */ |
| 155 | + class Builder internal constructor() { |
| 156 | + |
| 157 | + private var service: AccountActivityService? = null |
| 158 | + private var params: AccountActivityListParams? = null |
| 159 | + private var response: AccountActivityListPageResponse? = null |
| 160 | + |
| 161 | + @JvmSynthetic |
| 162 | + internal fun from(accountActivityListPage: AccountActivityListPage) = apply { |
| 163 | + service = accountActivityListPage.service |
| 164 | + params = accountActivityListPage.params |
| 165 | + response = accountActivityListPage.response |
| 166 | + } |
| 167 | + |
| 168 | + fun service(service: AccountActivityService) = apply { this.service = service } |
| 169 | + |
| 170 | + /** The parameters that were used to request this page. */ |
| 171 | + fun params(params: AccountActivityListParams) = apply { this.params = params } |
| 172 | + |
| 173 | + /** The response that this page was parsed from. */ |
| 174 | + fun response(response: AccountActivityListPageResponse) = apply { this.response = response } |
| 175 | + |
| 176 | + /** |
| 177 | + * Returns an immutable instance of [AccountActivityListPage]. |
| 178 | + * |
| 179 | + * Further updates to this [Builder] will not mutate the returned instance. |
| 180 | + * |
| 181 | + * The following fields are required: |
| 182 | + * ```java |
| 183 | + * .service() |
| 184 | + * .params() |
| 185 | + * .response() |
| 186 | + * ``` |
| 187 | + * |
| 188 | + * @throws IllegalStateException if any required field is unset. |
| 189 | + */ |
| 190 | + fun build(): AccountActivityListPage = |
| 191 | + AccountActivityListPage( |
| 192 | + checkRequired("service", service), |
| 193 | + checkRequired("params", params), |
| 194 | + checkRequired("response", response), |
| 195 | + ) |
| 196 | + } |
| 197 | + |
| 198 | + override fun equals(other: Any?): Boolean { |
| 199 | + if (this === other) { |
| 200 | + return true |
| 201 | + } |
| 202 | + |
| 203 | + return /* spotless:off */ other is AccountActivityListPage && service == other.service && params == other.params && response == other.response /* spotless:on */ |
| 204 | + } |
| 205 | + |
| 206 | + override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */ |
| 207 | + |
| 208 | + override fun toString() = |
| 209 | + "AccountActivityListPage{service=$service, params=$params, response=$response}" |
| 210 | +} |
0 commit comments