@@ -30,11 +30,7 @@ private constructor(
3030
3131 fun data (): List <Account > = response().data()
3232
33- fun page (): Long = response().page()
34-
35- fun totalEntries (): Long = response().totalEntries()
36-
37- fun totalPages (): Long = response().totalPages()
33+ fun hasMore (): Boolean = response().hasMore()
3834
3935 override fun equals (other : Any? ): Boolean {
4036 if (this == = other) {
@@ -59,21 +55,29 @@ private constructor(
5955 " AccountListPageAsync{accountsService=$accountsService , params=$params , response=$response }"
6056
6157 fun hasNextPage (): Boolean {
62- if (data().isEmpty()) {
63- return false
64- }
65-
66- return page() < totalPages()
58+ return data().isEmpty()
6759 }
6860
6961 fun getNextPageParams (): Optional <AccountListParams > {
7062 if (! hasNextPage()) {
7163 return Optional .empty()
7264 }
7365
74- return Optional .of(
75- AccountListParams .builder().from(params).page(params.page().orElse(0 ) + 1 ).build()
76- )
66+ return if (params.endingBefore().isPresent) {
67+ Optional .of(
68+ AccountListParams .builder()
69+ .from(params)
70+ .endingBefore(data().first().token())
71+ .build()
72+ )
73+ } else {
74+ Optional .of(
75+ AccountListParams .builder()
76+ .from(params)
77+ .startingAfter(data().last().token())
78+ .build()
79+ )
80+ }
7781 }
7882
7983 fun getNextPage (): CompletableFuture <Optional <AccountListPageAsync >> {
@@ -104,32 +108,21 @@ private constructor(
104108 class Response
105109 constructor (
106110 private val data: JsonField <List <Account >>,
107- private val page: JsonField <Long >,
108- private val totalEntries: JsonField <Long >,
109- private val totalPages: JsonField <Long >,
111+ private val hasMore: JsonField <Boolean >,
110112 private val additionalProperties: Map <String , JsonValue >,
111113 ) {
112114
113115 private var validated: Boolean = false
114116
115117 fun data (): List <Account > = data.getNullable(" data" ) ? : listOf ()
116118
117- fun page (): Long = page.getRequired(" page" )
118-
119- fun totalEntries (): Long = totalEntries.getRequired(" total_entries" )
120-
121- fun totalPages (): Long = totalPages.getRequired(" total_pages" )
119+ fun hasMore (): Boolean = hasMore.getRequired(" has_more" )
122120
123121 @JsonProperty(" data" )
124122 fun _data (): Optional <JsonField <List <Account >>> = Optional .ofNullable(data)
125123
126- @JsonProperty(" page" ) fun _page (): Optional <JsonField <Long >> = Optional .ofNullable(page)
127-
128- @JsonProperty(" total_entries" )
129- fun _totalEntries (): Optional <JsonField <Long >> = Optional .ofNullable(totalEntries)
130-
131- @JsonProperty(" total_pages" )
132- fun _totalPages (): Optional <JsonField <Long >> = Optional .ofNullable(totalPages)
124+ @JsonProperty(" has_more" )
125+ fun _hasMore (): Optional <JsonField <Boolean >> = Optional .ofNullable(hasMore)
133126
134127 @JsonAnyGetter
135128 @ExcludeMissing
@@ -138,9 +131,7 @@ private constructor(
138131 fun validate (): Response = apply {
139132 if (! validated) {
140133 data().map { it.validate() }
141- page()
142- totalEntries()
143- totalPages()
134+ hasMore()
144135 validated = true
145136 }
146137 }
@@ -154,24 +145,20 @@ private constructor(
154145
155146 return other is Response &&
156147 this .data == other.data &&
157- this .page == other.page &&
158- this .totalEntries == other.totalEntries &&
159- this .totalPages == other.totalPages &&
148+ this .hasMore == other.hasMore &&
160149 this .additionalProperties == other.additionalProperties
161150 }
162151
163152 override fun hashCode (): Int {
164153 return Objects .hash(
165154 data,
166- page,
167- totalEntries,
168- totalPages,
155+ hasMore,
169156 additionalProperties,
170157 )
171158 }
172159
173160 override fun toString () =
174- " AccountListPageAsync.Response{data=$data , page= $page , totalEntries= $totalEntries , totalPages= $totalPages , additionalProperties=$additionalProperties }"
161+ " AccountListPageAsync.Response{data=$data , hasMore= $hasMore , additionalProperties=$additionalProperties }"
175162
176163 companion object {
177164
@@ -181,17 +168,13 @@ private constructor(
181168 class Builder {
182169
183170 private var data: JsonField <List <Account >> = JsonMissing .of()
184- private var page: JsonField <Long > = JsonMissing .of()
185- private var totalEntries: JsonField <Long > = JsonMissing .of()
186- private var totalPages: JsonField <Long > = JsonMissing .of()
171+ private var hasMore: JsonField <Boolean > = JsonMissing .of()
187172 private var additionalProperties: MutableMap <String , JsonValue > = mutableMapOf ()
188173
189174 @JvmSynthetic
190175 internal fun from (page : Response ) = apply {
191176 this .data = page.data
192- this .page = page.page
193- this .totalEntries = page.totalEntries
194- this .totalPages = page.totalPages
177+ this .hasMore = page.hasMore
195178 this .additionalProperties.putAll(page.additionalProperties)
196179 }
197180
@@ -200,21 +183,10 @@ private constructor(
200183 @JsonProperty(" data" )
201184 fun data (data : JsonField <List <Account >>) = apply { this .data = data }
202185
203- fun page (page : Long ) = page(JsonField .of(page))
204-
205- @JsonProperty(" page" ) fun page (page : JsonField <Long >) = apply { this .page = page }
206-
207- fun totalEntries (totalEntries : Long ) = totalEntries(JsonField .of(totalEntries))
208-
209- @JsonProperty(" total_entries" )
210- fun totalEntries (totalEntries : JsonField <Long >) = apply {
211- this .totalEntries = totalEntries
212- }
213-
214- fun totalPages (totalPages : Long ) = totalPages(JsonField .of(totalPages))
186+ fun hasMore (hasMore : Boolean ) = hasMore(JsonField .of(hasMore))
215187
216- @JsonProperty(" total_pages " )
217- fun totalPages ( totalPages : JsonField <Long >) = apply { this .totalPages = totalPages }
188+ @JsonProperty(" has_more " )
189+ fun hasMore ( hasMore : JsonField <Boolean >) = apply { this .hasMore = hasMore }
218190
219191 @JsonAnySetter
220192 fun putAdditionalProperty (key : String , value : JsonValue ) = apply {
@@ -224,9 +196,7 @@ private constructor(
224196 fun build () =
225197 Response (
226198 data,
227- page,
228- totalEntries,
229- totalPages,
199+ hasMore,
230200 additionalProperties.toUnmodifiable(),
231201 )
232202 }
0 commit comments