22
33package com.lithic.api.models
44
5+ import com.fasterxml.jackson.annotation.JsonCreator
6+ import com.lithic.api.core.Enum
7+ import com.lithic.api.core.JsonField
58import com.lithic.api.core.Params
69import com.lithic.api.core.http.Headers
710import com.lithic.api.core.http.QueryParams
11+ import com.lithic.api.errors.LithicInvalidDataException
812import java.util.Objects
913import java.util.Optional
1014import kotlin.jvm.optionals.getOrNull
@@ -16,6 +20,7 @@ private constructor(
1620 private val cardToken: String? ,
1721 private val endingBefore: String? ,
1822 private val pageSize: Long? ,
23+ private val scope: Scope ? ,
1924 private val startingAfter: String? ,
2025 private val additionalHeaders: Headers ,
2126 private val additionalQueryParams: QueryParams ,
@@ -36,6 +41,9 @@ private constructor(
3641 /* * Page size (for pagination). */
3742 fun pageSize (): Optional <Long > = Optional .ofNullable(pageSize)
3843
44+ /* * Only return Authorization Rules that are bound to the provided scope; */
45+ fun scope (): Optional <Scope > = Optional .ofNullable(scope)
46+
3947 /* *
4048 * A cursor representing an item's token after which a page of results should begin. Used to
4149 * retrieve the next page of results after this item.
@@ -63,6 +71,7 @@ private constructor(
6371 private var cardToken: String? = null
6472 private var endingBefore: String? = null
6573 private var pageSize: Long? = null
74+ private var scope: Scope ? = null
6675 private var startingAfter: String? = null
6776 private var additionalHeaders: Headers .Builder = Headers .builder()
6877 private var additionalQueryParams: QueryParams .Builder = QueryParams .builder()
@@ -73,6 +82,7 @@ private constructor(
7382 cardToken = authRuleV2ListParams.cardToken
7483 endingBefore = authRuleV2ListParams.endingBefore
7584 pageSize = authRuleV2ListParams.pageSize
85+ scope = authRuleV2ListParams.scope
7686 startingAfter = authRuleV2ListParams.startingAfter
7787 additionalHeaders = authRuleV2ListParams.additionalHeaders.toBuilder()
7888 additionalQueryParams = authRuleV2ListParams.additionalQueryParams.toBuilder()
@@ -112,6 +122,12 @@ private constructor(
112122 /* * Alias for calling [Builder.pageSize] with `pageSize.orElse(null)`. */
113123 fun pageSize (pageSize : Optional <Long >) = pageSize(pageSize.getOrNull())
114124
125+ /* * Only return Authorization Rules that are bound to the provided scope; */
126+ fun scope (scope : Scope ? ) = apply { this .scope = scope }
127+
128+ /* * Alias for calling [Builder.scope] with `scope.orElse(null)`. */
129+ fun scope (scope : Optional <Scope >) = scope(scope.getOrNull())
130+
115131 /* *
116132 * A cursor representing an item's token after which a page of results should begin. Used to
117133 * retrieve the next page of results after this item.
@@ -231,6 +247,7 @@ private constructor(
231247 cardToken,
232248 endingBefore,
233249 pageSize,
250+ scope,
234251 startingAfter,
235252 additionalHeaders.build(),
236253 additionalQueryParams.build(),
@@ -246,21 +263,154 @@ private constructor(
246263 cardToken?.let { put(" card_token" , it) }
247264 endingBefore?.let { put(" ending_before" , it) }
248265 pageSize?.let { put(" page_size" , it.toString()) }
266+ scope?.let { put(" scope" , it.toString()) }
249267 startingAfter?.let { put(" starting_after" , it) }
250268 putAll(additionalQueryParams)
251269 }
252270 .build()
253271
272+ /* * Only return Authorization Rules that are bound to the provided scope; */
273+ class Scope @JsonCreator private constructor(private val value : JsonField <String >) : Enum {
274+
275+ /* *
276+ * Returns this class instance's raw value.
277+ *
278+ * This is usually only useful if this instance was deserialized from data that doesn't
279+ * match any known member, and you want to know that value. For example, if the SDK is on an
280+ * older version than the API, then the API may respond with new members that the SDK is
281+ * unaware of.
282+ */
283+ @com.fasterxml.jackson.annotation.JsonValue fun _value (): JsonField <String > = value
284+
285+ companion object {
286+
287+ @JvmField val PROGRAM = of(" PROGRAM" )
288+
289+ @JvmField val ACCOUNT = of(" ACCOUNT" )
290+
291+ @JvmField val CARD = of(" CARD" )
292+
293+ @JvmStatic fun of (value : String ) = Scope (JsonField .of(value))
294+ }
295+
296+ /* * An enum containing [Scope]'s known values. */
297+ enum class Known {
298+ PROGRAM ,
299+ ACCOUNT ,
300+ CARD ,
301+ }
302+
303+ /* *
304+ * An enum containing [Scope]'s known values, as well as an [_UNKNOWN] member.
305+ *
306+ * An instance of [Scope] can contain an unknown value in a couple of cases:
307+ * - It was deserialized from data that doesn't match any known member. For example, if the
308+ * SDK is on an older version than the API, then the API may respond with new members that
309+ * the SDK is unaware of.
310+ * - It was constructed with an arbitrary value using the [of] method.
311+ */
312+ enum class Value {
313+ PROGRAM ,
314+ ACCOUNT ,
315+ CARD ,
316+ /* * An enum member indicating that [Scope] was instantiated with an unknown value. */
317+ _UNKNOWN ,
318+ }
319+
320+ /* *
321+ * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
322+ * if the class was instantiated with an unknown value.
323+ *
324+ * Use the [known] method instead if you're certain the value is always known or if you want
325+ * to throw for the unknown case.
326+ */
327+ fun value (): Value =
328+ when (this ) {
329+ PROGRAM -> Value .PROGRAM
330+ ACCOUNT -> Value .ACCOUNT
331+ CARD -> Value .CARD
332+ else -> Value ._UNKNOWN
333+ }
334+
335+ /* *
336+ * Returns an enum member corresponding to this class instance's value.
337+ *
338+ * Use the [value] method instead if you're uncertain the value is always known and don't
339+ * want to throw for the unknown case.
340+ *
341+ * @throws LithicInvalidDataException if this class instance's value is a not a known
342+ * member.
343+ */
344+ fun known (): Known =
345+ when (this ) {
346+ PROGRAM -> Known .PROGRAM
347+ ACCOUNT -> Known .ACCOUNT
348+ CARD -> Known .CARD
349+ else -> throw LithicInvalidDataException (" Unknown Scope: $value " )
350+ }
351+
352+ /* *
353+ * Returns this class instance's primitive wire representation.
354+ *
355+ * This differs from the [toString] method because that method is primarily for debugging
356+ * and generally doesn't throw.
357+ *
358+ * @throws LithicInvalidDataException if this class instance's value does not have the
359+ * expected primitive type.
360+ */
361+ fun asString (): String =
362+ _value ().asString().orElseThrow { LithicInvalidDataException (" Value is not a String" ) }
363+
364+ private var validated: Boolean = false
365+
366+ fun validate (): Scope = apply {
367+ if (validated) {
368+ return @apply
369+ }
370+
371+ known()
372+ validated = true
373+ }
374+
375+ fun isValid (): Boolean =
376+ try {
377+ validate()
378+ true
379+ } catch (e: LithicInvalidDataException ) {
380+ false
381+ }
382+
383+ /* *
384+ * Returns a score indicating how many valid values are contained in this object
385+ * recursively.
386+ *
387+ * Used for best match union deserialization.
388+ */
389+ @JvmSynthetic internal fun validity (): Int = if (value() == Value ._UNKNOWN ) 0 else 1
390+
391+ override fun equals (other : Any? ): Boolean {
392+ if (this == = other) {
393+ return true
394+ }
395+
396+ return /* spotless:off */ other is Scope && value == other.value /* spotless:on */
397+ }
398+
399+ override fun hashCode () = value.hashCode()
400+
401+ override fun toString () = value.toString()
402+ }
403+
254404 override fun equals (other : Any? ): Boolean {
255405 if (this == = other) {
256406 return true
257407 }
258408
259- return /* spotless:off */ other is AuthRuleV2ListParams && accountToken == other.accountToken && cardToken == other.cardToken && endingBefore == other.endingBefore && pageSize == other.pageSize && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
409+ return /* spotless:off */ other is AuthRuleV2ListParams && accountToken == other.accountToken && cardToken == other.cardToken && endingBefore == other.endingBefore && pageSize == other.pageSize && scope == other.scope && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
260410 }
261411
262- override fun hashCode (): Int = /* spotless:off */ Objects .hash(accountToken, cardToken, endingBefore, pageSize, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */
412+ override fun hashCode (): Int = /* spotless:off */ Objects .hash(accountToken, cardToken, endingBefore, pageSize, scope, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */
263413
264414 override fun toString () =
265- " AuthRuleV2ListParams{accountToken=$accountToken , cardToken=$cardToken , endingBefore=$endingBefore , pageSize=$pageSize , startingAfter=$startingAfter , additionalHeaders=$additionalHeaders , additionalQueryParams=$additionalQueryParams }"
415+ " AuthRuleV2ListParams{accountToken=$accountToken , cardToken=$cardToken , endingBefore=$endingBefore , pageSize=$pageSize , scope= $scope , startingAfter=$startingAfter , additionalHeaders=$additionalHeaders , additionalQueryParams=$additionalQueryParams }"
266416}
0 commit comments