22
33package com.withorb.api.models
44
5+ import com.withorb.api.core.checkRequired
56import com.withorb.api.services.async.AlertServiceAsync
67import java.util.Objects
78import java.util.Optional
@@ -10,27 +11,14 @@ import java.util.concurrent.Executor
1011import java.util.function.Predicate
1112import kotlin.jvm.optionals.getOrNull
1213
13- /* *
14- * This endpoint returns a list of alerts within Orb.
15- *
16- * The request must specify one of `customer_id`, `external_customer_id`, or `subscription_id`.
17- *
18- * If querying by subscripion_id, the endpoint will return the subscription level alerts as well as
19- * the plan level alerts associated with the subscription.
20- *
21- * The list of alerts is ordered starting from the most recently created alert. This endpoint
22- * follows Orb's [standardized pagination format](/api-reference/pagination).
23- */
14+ /* * @see [AlertServiceAsync.list] */
2415class AlertListPageAsync
2516private constructor (
26- private val alertsService : AlertServiceAsync ,
17+ private val service : AlertServiceAsync ,
2718 private val params: AlertListParams ,
2819 private val response: AlertListPageResponse ,
2920) {
3021
31- /* * Returns the response that this page was parsed from. */
32- fun response (): AlertListPageResponse = response
33-
3422 /* *
3523 * Delegates to [AlertListPageResponse], but gracefully handles missing data.
3624 *
@@ -46,19 +34,6 @@ private constructor(
4634 fun paginationMetadata (): Optional <PaginationMetadata > =
4735 response._paginationMetadata ().getOptional(" pagination_metadata" )
4836
49- override fun equals (other : Any? ): Boolean {
50- if (this == = other) {
51- return true
52- }
53-
54- return /* spotless:off */ other is AlertListPageAsync && alertsService == other.alertsService && params == other.params && response == other.response /* spotless:on */
55- }
56-
57- override fun hashCode (): Int = /* spotless:off */ Objects .hash(alertsService, params, response) /* spotless:on */
58-
59- override fun toString () =
60- " AlertListPageAsync{alertsService=$alertsService , params=$params , response=$response }"
61-
6237 fun hasNextPage (): Boolean =
6338 data().isNotEmpty() &&
6439 paginationMetadata().flatMap { it._nextCursor ().getOptional(" next_cursor" ) }.isPresent
@@ -80,22 +55,78 @@ private constructor(
8055 )
8156 }
8257
83- fun getNextPage (): CompletableFuture <Optional <AlertListPageAsync >> {
84- return getNextPageParams()
85- .map { alertsService .list(it).thenApply { Optional .of(it) } }
58+ fun getNextPage (): CompletableFuture <Optional <AlertListPageAsync >> =
59+ getNextPageParams()
60+ .map { service .list(it).thenApply { Optional .of(it) } }
8661 .orElseGet { CompletableFuture .completedFuture(Optional .empty()) }
87- }
8862
8963 fun autoPager (): AutoPager = AutoPager (this )
9064
65+ /* * The parameters that were used to request this page. */
66+ fun params (): AlertListParams = params
67+
68+ /* * The response that this page was parsed from. */
69+ fun response (): AlertListPageResponse = response
70+
71+ fun toBuilder () = Builder ().from(this )
72+
9173 companion object {
9274
93- @JvmStatic
94- fun of (
95- alertsService : AlertServiceAsync ,
96- params : AlertListParams ,
97- response : AlertListPageResponse ,
98- ) = AlertListPageAsync (alertsService, params, response)
75+ /* *
76+ * Returns a mutable builder for constructing an instance of [AlertListPageAsync].
77+ *
78+ * The following fields are required:
79+ * ```java
80+ * .service()
81+ * .params()
82+ * .response()
83+ * ```
84+ */
85+ @JvmStatic fun builder () = Builder ()
86+ }
87+
88+ /* * A builder for [AlertListPageAsync]. */
89+ class Builder internal constructor() {
90+
91+ private var service: AlertServiceAsync ? = null
92+ private var params: AlertListParams ? = null
93+ private var response: AlertListPageResponse ? = null
94+
95+ @JvmSynthetic
96+ internal fun from (alertListPageAsync : AlertListPageAsync ) = apply {
97+ service = alertListPageAsync.service
98+ params = alertListPageAsync.params
99+ response = alertListPageAsync.response
100+ }
101+
102+ fun service (service : AlertServiceAsync ) = apply { this .service = service }
103+
104+ /* * The parameters that were used to request this page. */
105+ fun params (params : AlertListParams ) = apply { this .params = params }
106+
107+ /* * The response that this page was parsed from. */
108+ fun response (response : AlertListPageResponse ) = apply { this .response = response }
109+
110+ /* *
111+ * Returns an immutable instance of [AlertListPageAsync].
112+ *
113+ * Further updates to this [Builder] will not mutate the returned instance.
114+ *
115+ * The following fields are required:
116+ * ```java
117+ * .service()
118+ * .params()
119+ * .response()
120+ * ```
121+ *
122+ * @throws IllegalStateException if any required field is unset.
123+ */
124+ fun build (): AlertListPageAsync =
125+ AlertListPageAsync (
126+ checkRequired(" service" , service),
127+ checkRequired(" params" , params),
128+ checkRequired(" response" , response),
129+ )
99130 }
100131
101132 class AutoPager (private val firstPage : AlertListPageAsync ) {
@@ -123,4 +154,17 @@ private constructor(
123154 return forEach(values::add, executor).thenApply { values }
124155 }
125156 }
157+
158+ override fun equals (other : Any? ): Boolean {
159+ if (this == = other) {
160+ return true
161+ }
162+
163+ return /* spotless:off */ other is AlertListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */
164+ }
165+
166+ override fun hashCode (): Int = /* spotless:off */ Objects .hash(service, params, response) /* spotless:on */
167+
168+ override fun toString () =
169+ " AlertListPageAsync{service=$service , params=$params , response=$response }"
126170}
0 commit comments