|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.tryfinch.api.models |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.JsonAnyGetter |
| 6 | +import com.fasterxml.jackson.annotation.JsonAnySetter |
| 7 | +import com.fasterxml.jackson.annotation.JsonCreator |
| 8 | +import com.fasterxml.jackson.annotation.JsonProperty |
| 9 | +import com.tryfinch.api.core.ExcludeMissing |
| 10 | +import com.tryfinch.api.core.JsonField |
| 11 | +import com.tryfinch.api.core.JsonMissing |
| 12 | +import com.tryfinch.api.core.JsonValue |
| 13 | +import com.tryfinch.api.errors.FinchInvalidDataException |
| 14 | +import com.tryfinch.api.services.blocking.hris.company.PayStatementItemService |
| 15 | +import java.util.Collections |
| 16 | +import java.util.Objects |
| 17 | +import java.util.Optional |
| 18 | +import java.util.stream.Stream |
| 19 | +import java.util.stream.StreamSupport |
| 20 | +import kotlin.jvm.optionals.getOrNull |
| 21 | + |
| 22 | +/** |
| 23 | + * **Beta:** this endpoint currently serves employers onboarded after March 4th and historical |
| 24 | + * support will be added soon Retrieve a list of detailed pay statement items for the access token's |
| 25 | + * connection account. |
| 26 | + */ |
| 27 | +class HrisCompanyPayStatementItemListPage |
| 28 | +private constructor( |
| 29 | + private val payStatementItemService: PayStatementItemService, |
| 30 | + private val params: HrisCompanyPayStatementItemListParams, |
| 31 | + private val response: Response, |
| 32 | +) { |
| 33 | + |
| 34 | + fun response(): Response = response |
| 35 | + |
| 36 | + fun responses(): List<PayStatementItemListResponse> = response().responses() |
| 37 | + |
| 38 | + override fun equals(other: Any?): Boolean { |
| 39 | + if (this === other) { |
| 40 | + return true |
| 41 | + } |
| 42 | + |
| 43 | + return /* spotless:off */ other is HrisCompanyPayStatementItemListPage && payStatementItemService == other.payStatementItemService && params == other.params && response == other.response /* spotless:on */ |
| 44 | + } |
| 45 | + |
| 46 | + override fun hashCode(): Int = /* spotless:off */ Objects.hash(payStatementItemService, params, response) /* spotless:on */ |
| 47 | + |
| 48 | + override fun toString() = |
| 49 | + "HrisCompanyPayStatementItemListPage{payStatementItemService=$payStatementItemService, params=$params, response=$response}" |
| 50 | + |
| 51 | + fun hasNextPage(): Boolean { |
| 52 | + return !responses().isEmpty() |
| 53 | + } |
| 54 | + |
| 55 | + fun getNextPageParams(): Optional<HrisCompanyPayStatementItemListParams> { |
| 56 | + return Optional.empty() |
| 57 | + } |
| 58 | + |
| 59 | + fun getNextPage(): Optional<HrisCompanyPayStatementItemListPage> { |
| 60 | + return getNextPageParams().map { payStatementItemService.list(it) } |
| 61 | + } |
| 62 | + |
| 63 | + fun autoPager(): AutoPager = AutoPager(this) |
| 64 | + |
| 65 | + companion object { |
| 66 | + |
| 67 | + @JvmStatic |
| 68 | + fun of( |
| 69 | + payStatementItemService: PayStatementItemService, |
| 70 | + params: HrisCompanyPayStatementItemListParams, |
| 71 | + response: Response, |
| 72 | + ) = HrisCompanyPayStatementItemListPage(payStatementItemService, params, response) |
| 73 | + } |
| 74 | + |
| 75 | + class Response( |
| 76 | + private val responses: JsonField<List<PayStatementItemListResponse>>, |
| 77 | + private val additionalProperties: MutableMap<String, JsonValue>, |
| 78 | + ) { |
| 79 | + |
| 80 | + @JsonCreator |
| 81 | + private constructor( |
| 82 | + @JsonProperty("responses") |
| 83 | + responses: JsonField<List<PayStatementItemListResponse>> = JsonMissing.of() |
| 84 | + ) : this(responses, mutableMapOf()) |
| 85 | + |
| 86 | + fun responses(): List<PayStatementItemListResponse> = |
| 87 | + responses.getNullable("responses") ?: listOf() |
| 88 | + |
| 89 | + @JsonProperty("responses") |
| 90 | + fun _responses(): Optional<JsonField<List<PayStatementItemListResponse>>> = |
| 91 | + Optional.ofNullable(responses) |
| 92 | + |
| 93 | + @JsonAnySetter |
| 94 | + private fun putAdditionalProperty(key: String, value: JsonValue) { |
| 95 | + additionalProperties.put(key, value) |
| 96 | + } |
| 97 | + |
| 98 | + @JsonAnyGetter |
| 99 | + @ExcludeMissing |
| 100 | + fun _additionalProperties(): Map<String, JsonValue> = |
| 101 | + Collections.unmodifiableMap(additionalProperties) |
| 102 | + |
| 103 | + private var validated: Boolean = false |
| 104 | + |
| 105 | + fun validate(): Response = apply { |
| 106 | + if (validated) { |
| 107 | + return@apply |
| 108 | + } |
| 109 | + |
| 110 | + responses().map { it.validate() } |
| 111 | + validated = true |
| 112 | + } |
| 113 | + |
| 114 | + fun isValid(): Boolean = |
| 115 | + try { |
| 116 | + validate() |
| 117 | + true |
| 118 | + } catch (e: FinchInvalidDataException) { |
| 119 | + false |
| 120 | + } |
| 121 | + |
| 122 | + fun toBuilder() = Builder().from(this) |
| 123 | + |
| 124 | + override fun equals(other: Any?): Boolean { |
| 125 | + if (this === other) { |
| 126 | + return true |
| 127 | + } |
| 128 | + |
| 129 | + return /* spotless:off */ other is Response && responses == other.responses && additionalProperties == other.additionalProperties /* spotless:on */ |
| 130 | + } |
| 131 | + |
| 132 | + override fun hashCode(): Int = /* spotless:off */ Objects.hash(responses, additionalProperties) /* spotless:on */ |
| 133 | + |
| 134 | + override fun toString() = |
| 135 | + "Response{responses=$responses, additionalProperties=$additionalProperties}" |
| 136 | + |
| 137 | + companion object { |
| 138 | + |
| 139 | + /** |
| 140 | + * Returns a mutable builder for constructing an instance of |
| 141 | + * [HrisCompanyPayStatementItemListPage]. |
| 142 | + */ |
| 143 | + @JvmStatic fun builder() = Builder() |
| 144 | + } |
| 145 | + |
| 146 | + class Builder { |
| 147 | + |
| 148 | + private var responses: JsonField<List<PayStatementItemListResponse>> = JsonMissing.of() |
| 149 | + private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf() |
| 150 | + |
| 151 | + @JvmSynthetic |
| 152 | + internal fun from(page: Response) = apply { |
| 153 | + this.responses = page.responses |
| 154 | + this.additionalProperties.putAll(page.additionalProperties) |
| 155 | + } |
| 156 | + |
| 157 | + fun responses(responses: List<PayStatementItemListResponse>) = |
| 158 | + responses(JsonField.of(responses)) |
| 159 | + |
| 160 | + fun responses(responses: JsonField<List<PayStatementItemListResponse>>) = apply { |
| 161 | + this.responses = responses |
| 162 | + } |
| 163 | + |
| 164 | + fun putAdditionalProperty(key: String, value: JsonValue) = apply { |
| 165 | + this.additionalProperties.put(key, value) |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * Returns an immutable instance of [Response]. |
| 170 | + * |
| 171 | + * Further updates to this [Builder] will not mutate the returned instance. |
| 172 | + */ |
| 173 | + fun build(): Response = Response(responses, additionalProperties.toMutableMap()) |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + class AutoPager(private val firstPage: HrisCompanyPayStatementItemListPage) : |
| 178 | + Iterable<PayStatementItemListResponse> { |
| 179 | + |
| 180 | + override fun iterator(): Iterator<PayStatementItemListResponse> = iterator { |
| 181 | + var page = firstPage |
| 182 | + var index = 0 |
| 183 | + while (true) { |
| 184 | + while (index < page.responses().size) { |
| 185 | + yield(page.responses()[index++]) |
| 186 | + } |
| 187 | + page = page.getNextPage().getOrNull() ?: break |
| 188 | + index = 0 |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + fun stream(): Stream<PayStatementItemListResponse> { |
| 193 | + return StreamSupport.stream(spliterator(), false) |
| 194 | + } |
| 195 | + } |
| 196 | +} |
0 commit comments