// File generated from our OpenAPI spec by Stainless.

package com.increase.api.models.cards

import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonAnySetter
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import com.increase.api.core.Enum
import com.increase.api.core.ExcludeMissing
import com.increase.api.core.JsonField
import com.increase.api.core.JsonMissing
import com.increase.api.core.JsonValue
import com.increase.api.core.checkKnown
import com.increase.api.core.checkRequired
import com.increase.api.core.toImmutable
import com.increase.api.errors.IncreaseInvalidDataException
import java.time.OffsetDateTime
import java.util.Collections
import java.util.Objects
import java.util.Optional
import kotlin.jvm.optionals.getOrNull

/**
 * Cards may operate on credit, debit, or prepaid BINs. They’ll immediately work for online
 * purchases after you create them. All cards work on a good funds model, and maintain a maximum
 * limit of 100% of the Account’s available balance at the time of transaction. Funds are deducted
 * from the Account upon transaction settlement.
 */
class Card
@JsonCreator(mode = JsonCreator.Mode.DISABLED)
private constructor(
    private val id: JsonField<String>,
    private val accountId: JsonField<String>,
    private val authorizationControls: JsonField<AuthorizationControls>,
    private val billingAddress: JsonField<BillingAddress>,
    private val bin: JsonField<String>,
    private val createdAt: JsonField<OffsetDateTime>,
    private val description: JsonField<String>,
    private val digitalWallet: JsonField<DigitalWallet>,
    private val entityId: JsonField<String>,
    private val expirationMonth: JsonField<Long>,
    private val expirationYear: JsonField<Long>,
    private val idempotencyKey: JsonField<String>,
    private val last4: JsonField<String>,
    private val status: JsonField<Status>,
    private val type: JsonField<Type>,
    private val additionalProperties: MutableMap<String, JsonValue>,
) {

    @JsonCreator
    private constructor(
        @JsonProperty("id") @ExcludeMissing id: JsonField<String> = JsonMissing.of(),
        @JsonProperty("account_id") @ExcludeMissing accountId: JsonField<String> = JsonMissing.of(),
        @JsonProperty("authorization_controls")
        @ExcludeMissing
        authorizationControls: JsonField<AuthorizationControls> = JsonMissing.of(),
        @JsonProperty("billing_address")
        @ExcludeMissing
        billingAddress: JsonField<BillingAddress> = JsonMissing.of(),
        @JsonProperty("bin") @ExcludeMissing bin: JsonField<String> = JsonMissing.of(),
        @JsonProperty("created_at")
        @ExcludeMissing
        createdAt: JsonField<OffsetDateTime> = JsonMissing.of(),
        @JsonProperty("description")
        @ExcludeMissing
        description: JsonField<String> = JsonMissing.of(),
        @JsonProperty("digital_wallet")
        @ExcludeMissing
        digitalWallet: JsonField<DigitalWallet> = JsonMissing.of(),
        @JsonProperty("entity_id") @ExcludeMissing entityId: JsonField<String> = JsonMissing.of(),
        @JsonProperty("expiration_month")
        @ExcludeMissing
        expirationMonth: JsonField<Long> = JsonMissing.of(),
        @JsonProperty("expiration_year")
        @ExcludeMissing
        expirationYear: JsonField<Long> = JsonMissing.of(),
        @JsonProperty("idempotency_key")
        @ExcludeMissing
        idempotencyKey: JsonField<String> = JsonMissing.of(),
        @JsonProperty("last4") @ExcludeMissing last4: JsonField<String> = JsonMissing.of(),
        @JsonProperty("status") @ExcludeMissing status: JsonField<Status> = JsonMissing.of(),
        @JsonProperty("type") @ExcludeMissing type: JsonField<Type> = JsonMissing.of(),
    ) : this(
        id,
        accountId,
        authorizationControls,
        billingAddress,
        bin,
        createdAt,
        description,
        digitalWallet,
        entityId,
        expirationMonth,
        expirationYear,
        idempotencyKey,
        last4,
        status,
        type,
        mutableMapOf(),
    )

    /**
     * The card identifier.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or is
     *   unexpectedly missing or null (e.g. if the server responded with an unexpected value).
     */
    fun id(): String = id.getRequired("id")

    /**
     * The identifier for the account this card belongs to.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or is
     *   unexpectedly missing or null (e.g. if the server responded with an unexpected value).
     */
    fun accountId(): String = accountId.getRequired("account_id")

    /**
     * Controls that restrict how this card can be used.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if the
     *   server responded with an unexpected value).
     */
    fun authorizationControls(): Optional<AuthorizationControls> =
        authorizationControls.getOptional("authorization_controls")

    /**
     * The Card's billing address.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or is
     *   unexpectedly missing or null (e.g. if the server responded with an unexpected value).
     */
    fun billingAddress(): BillingAddress = billingAddress.getRequired("billing_address")

    /**
     * The Bank Identification Number (BIN) of the Card.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or is
     *   unexpectedly missing or null (e.g. if the server responded with an unexpected value).
     */
    fun bin(): String = bin.getRequired("bin")

    /**
     * The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time at which the Card was
     * created.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or is
     *   unexpectedly missing or null (e.g. if the server responded with an unexpected value).
     */
    fun createdAt(): OffsetDateTime = createdAt.getRequired("created_at")

    /**
     * The card's description for display purposes.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if the
     *   server responded with an unexpected value).
     */
    fun description(): Optional<String> = description.getOptional("description")

    /**
     * The contact information used in the two-factor steps for digital wallet card creation. At
     * least one field must be present to complete the digital wallet steps.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if the
     *   server responded with an unexpected value).
     */
    fun digitalWallet(): Optional<DigitalWallet> = digitalWallet.getOptional("digital_wallet")

    /**
     * The identifier for the entity associated with this card.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if the
     *   server responded with an unexpected value).
     */
    fun entityId(): Optional<String> = entityId.getOptional("entity_id")

    /**
     * The month the card expires in M format (e.g., August is 8).
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or is
     *   unexpectedly missing or null (e.g. if the server responded with an unexpected value).
     */
    fun expirationMonth(): Long = expirationMonth.getRequired("expiration_month")

    /**
     * The year the card expires in YYYY format (e.g., 2025).
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or is
     *   unexpectedly missing or null (e.g. if the server responded with an unexpected value).
     */
    fun expirationYear(): Long = expirationYear.getRequired("expiration_year")

    /**
     * The idempotency key you chose for this object. This value is unique across Increase and is
     * used to ensure that a request is only processed once. Learn more about
     * [idempotency](https://increase.com/documentation/idempotency-keys).
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if the
     *   server responded with an unexpected value).
     */
    fun idempotencyKey(): Optional<String> = idempotencyKey.getOptional("idempotency_key")

    /**
     * The last 4 digits of the Card's Primary Account Number.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or is
     *   unexpectedly missing or null (e.g. if the server responded with an unexpected value).
     */
    fun last4(): String = last4.getRequired("last4")

    /**
     * This indicates if payments can be made with the card.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or is
     *   unexpectedly missing or null (e.g. if the server responded with an unexpected value).
     */
    fun status(): Status = status.getRequired("status")

    /**
     * A constant representing the object's type. For this resource it will always be `card`.
     *
     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or is
     *   unexpectedly missing or null (e.g. if the server responded with an unexpected value).
     */
    fun type(): Type = type.getRequired("type")

    /**
     * Returns the raw JSON value of [id].
     *
     * Unlike [id], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("id") @ExcludeMissing fun _id(): JsonField<String> = id

    /**
     * Returns the raw JSON value of [accountId].
     *
     * Unlike [accountId], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("account_id") @ExcludeMissing fun _accountId(): JsonField<String> = accountId

    /**
     * Returns the raw JSON value of [authorizationControls].
     *
     * Unlike [authorizationControls], this method doesn't throw if the JSON field has an unexpected
     * type.
     */
    @JsonProperty("authorization_controls")
    @ExcludeMissing
    fun _authorizationControls(): JsonField<AuthorizationControls> = authorizationControls

    /**
     * Returns the raw JSON value of [billingAddress].
     *
     * Unlike [billingAddress], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("billing_address")
    @ExcludeMissing
    fun _billingAddress(): JsonField<BillingAddress> = billingAddress

    /**
     * Returns the raw JSON value of [bin].
     *
     * Unlike [bin], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("bin") @ExcludeMissing fun _bin(): JsonField<String> = bin

    /**
     * Returns the raw JSON value of [createdAt].
     *
     * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("created_at")
    @ExcludeMissing
    fun _createdAt(): JsonField<OffsetDateTime> = createdAt

    /**
     * Returns the raw JSON value of [description].
     *
     * Unlike [description], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("description") @ExcludeMissing fun _description(): JsonField<String> = description

    /**
     * Returns the raw JSON value of [digitalWallet].
     *
     * Unlike [digitalWallet], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("digital_wallet")
    @ExcludeMissing
    fun _digitalWallet(): JsonField<DigitalWallet> = digitalWallet

    /**
     * Returns the raw JSON value of [entityId].
     *
     * Unlike [entityId], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("entity_id") @ExcludeMissing fun _entityId(): JsonField<String> = entityId

    /**
     * Returns the raw JSON value of [expirationMonth].
     *
     * Unlike [expirationMonth], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("expiration_month")
    @ExcludeMissing
    fun _expirationMonth(): JsonField<Long> = expirationMonth

    /**
     * Returns the raw JSON value of [expirationYear].
     *
     * Unlike [expirationYear], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("expiration_year")
    @ExcludeMissing
    fun _expirationYear(): JsonField<Long> = expirationYear

    /**
     * Returns the raw JSON value of [idempotencyKey].
     *
     * Unlike [idempotencyKey], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("idempotency_key")
    @ExcludeMissing
    fun _idempotencyKey(): JsonField<String> = idempotencyKey

    /**
     * Returns the raw JSON value of [last4].
     *
     * Unlike [last4], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("last4") @ExcludeMissing fun _last4(): JsonField<String> = last4

    /**
     * Returns the raw JSON value of [status].
     *
     * Unlike [status], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("status") @ExcludeMissing fun _status(): JsonField<Status> = status

    /**
     * Returns the raw JSON value of [type].
     *
     * Unlike [type], this method doesn't throw if the JSON field has an unexpected type.
     */
    @JsonProperty("type") @ExcludeMissing fun _type(): JsonField<Type> = type

    @JsonAnySetter
    private fun putAdditionalProperty(key: String, value: JsonValue) {
        additionalProperties.put(key, value)
    }

    @JsonAnyGetter
    @ExcludeMissing
    fun _additionalProperties(): Map<String, JsonValue> =
        Collections.unmodifiableMap(additionalProperties)

    fun toBuilder() = Builder().from(this)

    companion object {

        /**
         * Returns a mutable builder for constructing an instance of [Card].
         *
         * The following fields are required:
         * ```java
         * .id()
         * .accountId()
         * .authorizationControls()
         * .billingAddress()
         * .bin()
         * .createdAt()
         * .description()
         * .digitalWallet()
         * .entityId()
         * .expirationMonth()
         * .expirationYear()
         * .idempotencyKey()
         * .last4()
         * .status()
         * .type()
         * ```
         */
        @JvmStatic fun builder() = Builder()
    }

    /** A builder for [Card]. */
    class Builder internal constructor() {

        private var id: JsonField<String>? = null
        private var accountId: JsonField<String>? = null
        private var authorizationControls: JsonField<AuthorizationControls>? = null
        private var billingAddress: JsonField<BillingAddress>? = null
        private var bin: JsonField<String>? = null
        private var createdAt: JsonField<OffsetDateTime>? = null
        private var description: JsonField<String>? = null
        private var digitalWallet: JsonField<DigitalWallet>? = null
        private var entityId: JsonField<String>? = null
        private var expirationMonth: JsonField<Long>? = null
        private var expirationYear: JsonField<Long>? = null
        private var idempotencyKey: JsonField<String>? = null
        private var last4: JsonField<String>? = null
        private var status: JsonField<Status>? = null
        private var type: JsonField<Type>? = null
        private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

        @JvmSynthetic
        internal fun from(card: Card) = apply {
            id = card.id
            accountId = card.accountId
            authorizationControls = card.authorizationControls
            billingAddress = card.billingAddress
            bin = card.bin
            createdAt = card.createdAt
            description = card.description
            digitalWallet = card.digitalWallet
            entityId = card.entityId
            expirationMonth = card.expirationMonth
            expirationYear = card.expirationYear
            idempotencyKey = card.idempotencyKey
            last4 = card.last4
            status = card.status
            type = card.type
            additionalProperties = card.additionalProperties.toMutableMap()
        }

        /** The card identifier. */
        fun id(id: String) = id(JsonField.of(id))

        /**
         * Sets [Builder.id] to an arbitrary JSON value.
         *
         * You should usually call [Builder.id] with a well-typed [String] value instead. This
         * method is primarily for setting the field to an undocumented or not yet supported value.
         */
        fun id(id: JsonField<String>) = apply { this.id = id }

        /** The identifier for the account this card belongs to. */
        fun accountId(accountId: String) = accountId(JsonField.of(accountId))

        /**
         * Sets [Builder.accountId] to an arbitrary JSON value.
         *
         * You should usually call [Builder.accountId] with a well-typed [String] value instead.
         * This method is primarily for setting the field to an undocumented or not yet supported
         * value.
         */
        fun accountId(accountId: JsonField<String>) = apply { this.accountId = accountId }

        /** Controls that restrict how this card can be used. */
        fun authorizationControls(authorizationControls: AuthorizationControls?) =
            authorizationControls(JsonField.ofNullable(authorizationControls))

        /**
         * Alias for calling [Builder.authorizationControls] with
         * `authorizationControls.orElse(null)`.
         */
        fun authorizationControls(authorizationControls: Optional<AuthorizationControls>) =
            authorizationControls(authorizationControls.getOrNull())

        /**
         * Sets [Builder.authorizationControls] to an arbitrary JSON value.
         *
         * You should usually call [Builder.authorizationControls] with a well-typed
         * [AuthorizationControls] value instead. This method is primarily for setting the field to
         * an undocumented or not yet supported value.
         */
        fun authorizationControls(authorizationControls: JsonField<AuthorizationControls>) = apply {
            this.authorizationControls = authorizationControls
        }

        /** The Card's billing address. */
        fun billingAddress(billingAddress: BillingAddress) =
            billingAddress(JsonField.of(billingAddress))

        /**
         * Sets [Builder.billingAddress] to an arbitrary JSON value.
         *
         * You should usually call [Builder.billingAddress] with a well-typed [BillingAddress] value
         * instead. This method is primarily for setting the field to an undocumented or not yet
         * supported value.
         */
        fun billingAddress(billingAddress: JsonField<BillingAddress>) = apply {
            this.billingAddress = billingAddress
        }

        /** The Bank Identification Number (BIN) of the Card. */
        fun bin(bin: String) = bin(JsonField.of(bin))

        /**
         * Sets [Builder.bin] to an arbitrary JSON value.
         *
         * You should usually call [Builder.bin] with a well-typed [String] value instead. This
         * method is primarily for setting the field to an undocumented or not yet supported value.
         */
        fun bin(bin: JsonField<String>) = apply { this.bin = bin }

        /**
         * The [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time at which the Card
         * was created.
         */
        fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt))

        /**
         * Sets [Builder.createdAt] to an arbitrary JSON value.
         *
         * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value
         * instead. This method is primarily for setting the field to an undocumented or not yet
         * supported value.
         */
        fun createdAt(createdAt: JsonField<OffsetDateTime>) = apply { this.createdAt = createdAt }

        /** The card's description for display purposes. */
        fun description(description: String?) = description(JsonField.ofNullable(description))

        /** Alias for calling [Builder.description] with `description.orElse(null)`. */
        fun description(description: Optional<String>) = description(description.getOrNull())

        /**
         * Sets [Builder.description] to an arbitrary JSON value.
         *
         * You should usually call [Builder.description] with a well-typed [String] value instead.
         * This method is primarily for setting the field to an undocumented or not yet supported
         * value.
         */
        fun description(description: JsonField<String>) = apply { this.description = description }

        /**
         * The contact information used in the two-factor steps for digital wallet card creation. At
         * least one field must be present to complete the digital wallet steps.
         */
        fun digitalWallet(digitalWallet: DigitalWallet?) =
            digitalWallet(JsonField.ofNullable(digitalWallet))

        /** Alias for calling [Builder.digitalWallet] with `digitalWallet.orElse(null)`. */
        fun digitalWallet(digitalWallet: Optional<DigitalWallet>) =
            digitalWallet(digitalWallet.getOrNull())

        /**
         * Sets [Builder.digitalWallet] to an arbitrary JSON value.
         *
         * You should usually call [Builder.digitalWallet] with a well-typed [DigitalWallet] value
         * instead. This method is primarily for setting the field to an undocumented or not yet
         * supported value.
         */
        fun digitalWallet(digitalWallet: JsonField<DigitalWallet>) = apply {
            this.digitalWallet = digitalWallet
        }

        /** The identifier for the entity associated with this card. */
        fun entityId(entityId: String?) = entityId(JsonField.ofNullable(entityId))

        /** Alias for calling [Builder.entityId] with `entityId.orElse(null)`. */
        fun entityId(entityId: Optional<String>) = entityId(entityId.getOrNull())

        /**
         * Sets [Builder.entityId] to an arbitrary JSON value.
         *
         * You should usually call [Builder.entityId] with a well-typed [String] value instead. This
         * method is primarily for setting the field to an undocumented or not yet supported value.
         */
        fun entityId(entityId: JsonField<String>) = apply { this.entityId = entityId }

        /** The month the card expires in M format (e.g., August is 8). */
        fun expirationMonth(expirationMonth: Long) = expirationMonth(JsonField.of(expirationMonth))

        /**
         * Sets [Builder.expirationMonth] to an arbitrary JSON value.
         *
         * You should usually call [Builder.expirationMonth] with a well-typed [Long] value instead.
         * This method is primarily for setting the field to an undocumented or not yet supported
         * value.
         */
        fun expirationMonth(expirationMonth: JsonField<Long>) = apply {
            this.expirationMonth = expirationMonth
        }

        /** The year the card expires in YYYY format (e.g., 2025). */
        fun expirationYear(expirationYear: Long) = expirationYear(JsonField.of(expirationYear))

        /**
         * Sets [Builder.expirationYear] to an arbitrary JSON value.
         *
         * You should usually call [Builder.expirationYear] with a well-typed [Long] value instead.
         * This method is primarily for setting the field to an undocumented or not yet supported
         * value.
         */
        fun expirationYear(expirationYear: JsonField<Long>) = apply {
            this.expirationYear = expirationYear
        }

        /**
         * The idempotency key you chose for this object. This value is unique across Increase and
         * is used to ensure that a request is only processed once. Learn more about
         * [idempotency](https://increase.com/documentation/idempotency-keys).
         */
        fun idempotencyKey(idempotencyKey: String?) =
            idempotencyKey(JsonField.ofNullable(idempotencyKey))

        /** Alias for calling [Builder.idempotencyKey] with `idempotencyKey.orElse(null)`. */
        fun idempotencyKey(idempotencyKey: Optional<String>) =
            idempotencyKey(idempotencyKey.getOrNull())

        /**
         * Sets [Builder.idempotencyKey] to an arbitrary JSON value.
         *
         * You should usually call [Builder.idempotencyKey] with a well-typed [String] value
         * instead. This method is primarily for setting the field to an undocumented or not yet
         * supported value.
         */
        fun idempotencyKey(idempotencyKey: JsonField<String>) = apply {
            this.idempotencyKey = idempotencyKey
        }

        /** The last 4 digits of the Card's Primary Account Number. */
        fun last4(last4: String) = last4(JsonField.of(last4))

        /**
         * Sets [Builder.last4] to an arbitrary JSON value.
         *
         * You should usually call [Builder.last4] with a well-typed [String] value instead. This
         * method is primarily for setting the field to an undocumented or not yet supported value.
         */
        fun last4(last4: JsonField<String>) = apply { this.last4 = last4 }

        /** This indicates if payments can be made with the card. */
        fun status(status: Status) = status(JsonField.of(status))

        /**
         * Sets [Builder.status] to an arbitrary JSON value.
         *
         * You should usually call [Builder.status] with a well-typed [Status] value instead. This
         * method is primarily for setting the field to an undocumented or not yet supported value.
         */
        fun status(status: JsonField<Status>) = apply { this.status = status }

        /**
         * A constant representing the object's type. For this resource it will always be `card`.
         */
        fun type(type: Type) = type(JsonField.of(type))

        /**
         * Sets [Builder.type] to an arbitrary JSON value.
         *
         * You should usually call [Builder.type] with a well-typed [Type] value instead. This
         * method is primarily for setting the field to an undocumented or not yet supported value.
         */
        fun type(type: JsonField<Type>) = apply { this.type = type }

        fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
            this.additionalProperties.clear()
            putAllAdditionalProperties(additionalProperties)
        }

        fun putAdditionalProperty(key: String, value: JsonValue) = apply {
            additionalProperties.put(key, value)
        }

        fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
            this.additionalProperties.putAll(additionalProperties)
        }

        fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }

        fun removeAllAdditionalProperties(keys: Set<String>) = apply {
            keys.forEach(::removeAdditionalProperty)
        }

        /**
         * Returns an immutable instance of [Card].
         *
         * Further updates to this [Builder] will not mutate the returned instance.
         *
         * The following fields are required:
         * ```java
         * .id()
         * .accountId()
         * .authorizationControls()
         * .billingAddress()
         * .bin()
         * .createdAt()
         * .description()
         * .digitalWallet()
         * .entityId()
         * .expirationMonth()
         * .expirationYear()
         * .idempotencyKey()
         * .last4()
         * .status()
         * .type()
         * ```
         *
         * @throws IllegalStateException if any required field is unset.
         */
        fun build(): Card =
            Card(
                checkRequired("id", id),
                checkRequired("accountId", accountId),
                checkRequired("authorizationControls", authorizationControls),
                checkRequired("billingAddress", billingAddress),
                checkRequired("bin", bin),
                checkRequired("createdAt", createdAt),
                checkRequired("description", description),
                checkRequired("digitalWallet", digitalWallet),
                checkRequired("entityId", entityId),
                checkRequired("expirationMonth", expirationMonth),
                checkRequired("expirationYear", expirationYear),
                checkRequired("idempotencyKey", idempotencyKey),
                checkRequired("last4", last4),
                checkRequired("status", status),
                checkRequired("type", type),
                additionalProperties.toMutableMap(),
            )
    }

    private var validated: Boolean = false

    /**
     * Validates that the types of all values in this object match their expected types recursively.
     *
     * This method is _not_ forwards compatible with new types from the API for existing fields.
     *
     * @throws IncreaseInvalidDataException if any value type in this object doesn't match its
     *   expected type.
     */
    fun validate(): Card = apply {
        if (validated) {
            return@apply
        }

        id()
        accountId()
        authorizationControls().ifPresent { it.validate() }
        billingAddress().validate()
        bin()
        createdAt()
        description()
        digitalWallet().ifPresent { it.validate() }
        entityId()
        expirationMonth()
        expirationYear()
        idempotencyKey()
        last4()
        status().validate()
        type().validate()
        validated = true
    }

    fun isValid(): Boolean =
        try {
            validate()
            true
        } catch (e: IncreaseInvalidDataException) {
            false
        }

    /**
     * Returns a score indicating how many valid values are contained in this object recursively.
     *
     * Used for best match union deserialization.
     */
    @JvmSynthetic
    internal fun validity(): Int =
        (if (id.asKnown().isPresent) 1 else 0) +
            (if (accountId.asKnown().isPresent) 1 else 0) +
            (authorizationControls.asKnown().getOrNull()?.validity() ?: 0) +
            (billingAddress.asKnown().getOrNull()?.validity() ?: 0) +
            (if (bin.asKnown().isPresent) 1 else 0) +
            (if (createdAt.asKnown().isPresent) 1 else 0) +
            (if (description.asKnown().isPresent) 1 else 0) +
            (digitalWallet.asKnown().getOrNull()?.validity() ?: 0) +
            (if (entityId.asKnown().isPresent) 1 else 0) +
            (if (expirationMonth.asKnown().isPresent) 1 else 0) +
            (if (expirationYear.asKnown().isPresent) 1 else 0) +
            (if (idempotencyKey.asKnown().isPresent) 1 else 0) +
            (if (last4.asKnown().isPresent) 1 else 0) +
            (status.asKnown().getOrNull()?.validity() ?: 0) +
            (type.asKnown().getOrNull()?.validity() ?: 0)

    /** Controls that restrict how this card can be used. */
    class AuthorizationControls
    @JsonCreator(mode = JsonCreator.Mode.DISABLED)
    private constructor(
        private val merchantAcceptorIdentifier: JsonField<MerchantAcceptorIdentifier>,
        private val merchantCategoryCode: JsonField<MerchantCategoryCode>,
        private val merchantCountry: JsonField<MerchantCountry>,
        private val usage: JsonField<Usage>,
        private val additionalProperties: MutableMap<String, JsonValue>,
    ) {

        @JsonCreator
        private constructor(
            @JsonProperty("merchant_acceptor_identifier")
            @ExcludeMissing
            merchantAcceptorIdentifier: JsonField<MerchantAcceptorIdentifier> = JsonMissing.of(),
            @JsonProperty("merchant_category_code")
            @ExcludeMissing
            merchantCategoryCode: JsonField<MerchantCategoryCode> = JsonMissing.of(),
            @JsonProperty("merchant_country")
            @ExcludeMissing
            merchantCountry: JsonField<MerchantCountry> = JsonMissing.of(),
            @JsonProperty("usage") @ExcludeMissing usage: JsonField<Usage> = JsonMissing.of(),
        ) : this(
            merchantAcceptorIdentifier,
            merchantCategoryCode,
            merchantCountry,
            usage,
            mutableMapOf(),
        )

        /**
         * Restricts which Merchant Acceptor IDs are allowed or blocked for authorizations on this
         * card.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun merchantAcceptorIdentifier(): Optional<MerchantAcceptorIdentifier> =
            merchantAcceptorIdentifier.getOptional("merchant_acceptor_identifier")

        /**
         * Restricts which Merchant Category Codes are allowed or blocked for authorizations on this
         * card.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun merchantCategoryCode(): Optional<MerchantCategoryCode> =
            merchantCategoryCode.getOptional("merchant_category_code")

        /**
         * Restricts which merchant countries are allowed or blocked for authorizations on this
         * card.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun merchantCountry(): Optional<MerchantCountry> =
            merchantCountry.getOptional("merchant_country")

        /**
         * Controls how many times this card can be used.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun usage(): Optional<Usage> = usage.getOptional("usage")

        /**
         * Returns the raw JSON value of [merchantAcceptorIdentifier].
         *
         * Unlike [merchantAcceptorIdentifier], this method doesn't throw if the JSON field has an
         * unexpected type.
         */
        @JsonProperty("merchant_acceptor_identifier")
        @ExcludeMissing
        fun _merchantAcceptorIdentifier(): JsonField<MerchantAcceptorIdentifier> =
            merchantAcceptorIdentifier

        /**
         * Returns the raw JSON value of [merchantCategoryCode].
         *
         * Unlike [merchantCategoryCode], this method doesn't throw if the JSON field has an
         * unexpected type.
         */
        @JsonProperty("merchant_category_code")
        @ExcludeMissing
        fun _merchantCategoryCode(): JsonField<MerchantCategoryCode> = merchantCategoryCode

        /**
         * Returns the raw JSON value of [merchantCountry].
         *
         * Unlike [merchantCountry], this method doesn't throw if the JSON field has an unexpected
         * type.
         */
        @JsonProperty("merchant_country")
        @ExcludeMissing
        fun _merchantCountry(): JsonField<MerchantCountry> = merchantCountry

        /**
         * Returns the raw JSON value of [usage].
         *
         * Unlike [usage], this method doesn't throw if the JSON field has an unexpected type.
         */
        @JsonProperty("usage") @ExcludeMissing fun _usage(): JsonField<Usage> = usage

        @JsonAnySetter
        private fun putAdditionalProperty(key: String, value: JsonValue) {
            additionalProperties.put(key, value)
        }

        @JsonAnyGetter
        @ExcludeMissing
        fun _additionalProperties(): Map<String, JsonValue> =
            Collections.unmodifiableMap(additionalProperties)

        fun toBuilder() = Builder().from(this)

        companion object {

            /**
             * Returns a mutable builder for constructing an instance of [AuthorizationControls].
             *
             * The following fields are required:
             * ```java
             * .merchantAcceptorIdentifier()
             * .merchantCategoryCode()
             * .merchantCountry()
             * .usage()
             * ```
             */
            @JvmStatic fun builder() = Builder()
        }

        /** A builder for [AuthorizationControls]. */
        class Builder internal constructor() {

            private var merchantAcceptorIdentifier: JsonField<MerchantAcceptorIdentifier>? = null
            private var merchantCategoryCode: JsonField<MerchantCategoryCode>? = null
            private var merchantCountry: JsonField<MerchantCountry>? = null
            private var usage: JsonField<Usage>? = null
            private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

            @JvmSynthetic
            internal fun from(authorizationControls: AuthorizationControls) = apply {
                merchantAcceptorIdentifier = authorizationControls.merchantAcceptorIdentifier
                merchantCategoryCode = authorizationControls.merchantCategoryCode
                merchantCountry = authorizationControls.merchantCountry
                usage = authorizationControls.usage
                additionalProperties = authorizationControls.additionalProperties.toMutableMap()
            }

            /**
             * Restricts which Merchant Acceptor IDs are allowed or blocked for authorizations on
             * this card.
             */
            fun merchantAcceptorIdentifier(
                merchantAcceptorIdentifier: MerchantAcceptorIdentifier?
            ) = merchantAcceptorIdentifier(JsonField.ofNullable(merchantAcceptorIdentifier))

            /**
             * Alias for calling [Builder.merchantAcceptorIdentifier] with
             * `merchantAcceptorIdentifier.orElse(null)`.
             */
            fun merchantAcceptorIdentifier(
                merchantAcceptorIdentifier: Optional<MerchantAcceptorIdentifier>
            ) = merchantAcceptorIdentifier(merchantAcceptorIdentifier.getOrNull())

            /**
             * Sets [Builder.merchantAcceptorIdentifier] to an arbitrary JSON value.
             *
             * You should usually call [Builder.merchantAcceptorIdentifier] with a well-typed
             * [MerchantAcceptorIdentifier] value instead. This method is primarily for setting the
             * field to an undocumented or not yet supported value.
             */
            fun merchantAcceptorIdentifier(
                merchantAcceptorIdentifier: JsonField<MerchantAcceptorIdentifier>
            ) = apply { this.merchantAcceptorIdentifier = merchantAcceptorIdentifier }

            /**
             * Restricts which Merchant Category Codes are allowed or blocked for authorizations on
             * this card.
             */
            fun merchantCategoryCode(merchantCategoryCode: MerchantCategoryCode?) =
                merchantCategoryCode(JsonField.ofNullable(merchantCategoryCode))

            /**
             * Alias for calling [Builder.merchantCategoryCode] with
             * `merchantCategoryCode.orElse(null)`.
             */
            fun merchantCategoryCode(merchantCategoryCode: Optional<MerchantCategoryCode>) =
                merchantCategoryCode(merchantCategoryCode.getOrNull())

            /**
             * Sets [Builder.merchantCategoryCode] to an arbitrary JSON value.
             *
             * You should usually call [Builder.merchantCategoryCode] with a well-typed
             * [MerchantCategoryCode] value instead. This method is primarily for setting the field
             * to an undocumented or not yet supported value.
             */
            fun merchantCategoryCode(merchantCategoryCode: JsonField<MerchantCategoryCode>) =
                apply {
                    this.merchantCategoryCode = merchantCategoryCode
                }

            /**
             * Restricts which merchant countries are allowed or blocked for authorizations on this
             * card.
             */
            fun merchantCountry(merchantCountry: MerchantCountry?) =
                merchantCountry(JsonField.ofNullable(merchantCountry))

            /** Alias for calling [Builder.merchantCountry] with `merchantCountry.orElse(null)`. */
            fun merchantCountry(merchantCountry: Optional<MerchantCountry>) =
                merchantCountry(merchantCountry.getOrNull())

            /**
             * Sets [Builder.merchantCountry] to an arbitrary JSON value.
             *
             * You should usually call [Builder.merchantCountry] with a well-typed [MerchantCountry]
             * value instead. This method is primarily for setting the field to an undocumented or
             * not yet supported value.
             */
            fun merchantCountry(merchantCountry: JsonField<MerchantCountry>) = apply {
                this.merchantCountry = merchantCountry
            }

            /** Controls how many times this card can be used. */
            fun usage(usage: Usage?) = usage(JsonField.ofNullable(usage))

            /** Alias for calling [Builder.usage] with `usage.orElse(null)`. */
            fun usage(usage: Optional<Usage>) = usage(usage.getOrNull())

            /**
             * Sets [Builder.usage] to an arbitrary JSON value.
             *
             * You should usually call [Builder.usage] with a well-typed [Usage] value instead. This
             * method is primarily for setting the field to an undocumented or not yet supported
             * value.
             */
            fun usage(usage: JsonField<Usage>) = apply { this.usage = usage }

            fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                this.additionalProperties.clear()
                putAllAdditionalProperties(additionalProperties)
            }

            fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                additionalProperties.put(key, value)
            }

            fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                this.additionalProperties.putAll(additionalProperties)
            }

            fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }

            fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                keys.forEach(::removeAdditionalProperty)
            }

            /**
             * Returns an immutable instance of [AuthorizationControls].
             *
             * Further updates to this [Builder] will not mutate the returned instance.
             *
             * The following fields are required:
             * ```java
             * .merchantAcceptorIdentifier()
             * .merchantCategoryCode()
             * .merchantCountry()
             * .usage()
             * ```
             *
             * @throws IllegalStateException if any required field is unset.
             */
            fun build(): AuthorizationControls =
                AuthorizationControls(
                    checkRequired("merchantAcceptorIdentifier", merchantAcceptorIdentifier),
                    checkRequired("merchantCategoryCode", merchantCategoryCode),
                    checkRequired("merchantCountry", merchantCountry),
                    checkRequired("usage", usage),
                    additionalProperties.toMutableMap(),
                )
        }

        private var validated: Boolean = false

        /**
         * Validates that the types of all values in this object match their expected types
         * recursively.
         *
         * This method is _not_ forwards compatible with new types from the API for existing fields.
         *
         * @throws IncreaseInvalidDataException if any value type in this object doesn't match its
         *   expected type.
         */
        fun validate(): AuthorizationControls = apply {
            if (validated) {
                return@apply
            }

            merchantAcceptorIdentifier().ifPresent { it.validate() }
            merchantCategoryCode().ifPresent { it.validate() }
            merchantCountry().ifPresent { it.validate() }
            usage().ifPresent { it.validate() }
            validated = true
        }

        fun isValid(): Boolean =
            try {
                validate()
                true
            } catch (e: IncreaseInvalidDataException) {
                false
            }

        /**
         * Returns a score indicating how many valid values are contained in this object
         * recursively.
         *
         * Used for best match union deserialization.
         */
        @JvmSynthetic
        internal fun validity(): Int =
            (merchantAcceptorIdentifier.asKnown().getOrNull()?.validity() ?: 0) +
                (merchantCategoryCode.asKnown().getOrNull()?.validity() ?: 0) +
                (merchantCountry.asKnown().getOrNull()?.validity() ?: 0) +
                (usage.asKnown().getOrNull()?.validity() ?: 0)

        /**
         * Restricts which Merchant Acceptor IDs are allowed or blocked for authorizations on this
         * card.
         */
        class MerchantAcceptorIdentifier
        @JsonCreator(mode = JsonCreator.Mode.DISABLED)
        private constructor(
            private val allowed: JsonField<List<Allowed>>,
            private val blocked: JsonField<List<Blocked>>,
            private val additionalProperties: MutableMap<String, JsonValue>,
        ) {

            @JsonCreator
            private constructor(
                @JsonProperty("allowed")
                @ExcludeMissing
                allowed: JsonField<List<Allowed>> = JsonMissing.of(),
                @JsonProperty("blocked")
                @ExcludeMissing
                blocked: JsonField<List<Blocked>> = JsonMissing.of(),
            ) : this(allowed, blocked, mutableMapOf())

            /**
             * The Merchant Acceptor IDs that are allowed for authorizations on this card.
             *
             * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g.
             *   if the server responded with an unexpected value).
             */
            fun allowed(): Optional<List<Allowed>> = allowed.getOptional("allowed")

            /**
             * The Merchant Acceptor IDs that are blocked for authorizations on this card.
             *
             * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g.
             *   if the server responded with an unexpected value).
             */
            fun blocked(): Optional<List<Blocked>> = blocked.getOptional("blocked")

            /**
             * Returns the raw JSON value of [allowed].
             *
             * Unlike [allowed], this method doesn't throw if the JSON field has an unexpected type.
             */
            @JsonProperty("allowed")
            @ExcludeMissing
            fun _allowed(): JsonField<List<Allowed>> = allowed

            /**
             * Returns the raw JSON value of [blocked].
             *
             * Unlike [blocked], this method doesn't throw if the JSON field has an unexpected type.
             */
            @JsonProperty("blocked")
            @ExcludeMissing
            fun _blocked(): JsonField<List<Blocked>> = blocked

            @JsonAnySetter
            private fun putAdditionalProperty(key: String, value: JsonValue) {
                additionalProperties.put(key, value)
            }

            @JsonAnyGetter
            @ExcludeMissing
            fun _additionalProperties(): Map<String, JsonValue> =
                Collections.unmodifiableMap(additionalProperties)

            fun toBuilder() = Builder().from(this)

            companion object {

                /**
                 * Returns a mutable builder for constructing an instance of
                 * [MerchantAcceptorIdentifier].
                 *
                 * The following fields are required:
                 * ```java
                 * .allowed()
                 * .blocked()
                 * ```
                 */
                @JvmStatic fun builder() = Builder()
            }

            /** A builder for [MerchantAcceptorIdentifier]. */
            class Builder internal constructor() {

                private var allowed: JsonField<MutableList<Allowed>>? = null
                private var blocked: JsonField<MutableList<Blocked>>? = null
                private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                @JvmSynthetic
                internal fun from(merchantAcceptorIdentifier: MerchantAcceptorIdentifier) = apply {
                    allowed = merchantAcceptorIdentifier.allowed.map { it.toMutableList() }
                    blocked = merchantAcceptorIdentifier.blocked.map { it.toMutableList() }
                    additionalProperties =
                        merchantAcceptorIdentifier.additionalProperties.toMutableMap()
                }

                /** The Merchant Acceptor IDs that are allowed for authorizations on this card. */
                fun allowed(allowed: List<Allowed>?) = allowed(JsonField.ofNullable(allowed))

                /** Alias for calling [Builder.allowed] with `allowed.orElse(null)`. */
                fun allowed(allowed: Optional<List<Allowed>>) = allowed(allowed.getOrNull())

                /**
                 * Sets [Builder.allowed] to an arbitrary JSON value.
                 *
                 * You should usually call [Builder.allowed] with a well-typed `List<Allowed>` value
                 * instead. This method is primarily for setting the field to an undocumented or not
                 * yet supported value.
                 */
                fun allowed(allowed: JsonField<List<Allowed>>) = apply {
                    this.allowed = allowed.map { it.toMutableList() }
                }

                /**
                 * Adds a single [Allowed] to [Builder.allowed].
                 *
                 * @throws IllegalStateException if the field was previously set to a non-list.
                 */
                fun addAllowed(allowed: Allowed) = apply {
                    this.allowed =
                        (this.allowed ?: JsonField.of(mutableListOf())).also {
                            checkKnown("allowed", it).add(allowed)
                        }
                }

                /** The Merchant Acceptor IDs that are blocked for authorizations on this card. */
                fun blocked(blocked: List<Blocked>?) = blocked(JsonField.ofNullable(blocked))

                /** Alias for calling [Builder.blocked] with `blocked.orElse(null)`. */
                fun blocked(blocked: Optional<List<Blocked>>) = blocked(blocked.getOrNull())

                /**
                 * Sets [Builder.blocked] to an arbitrary JSON value.
                 *
                 * You should usually call [Builder.blocked] with a well-typed `List<Blocked>` value
                 * instead. This method is primarily for setting the field to an undocumented or not
                 * yet supported value.
                 */
                fun blocked(blocked: JsonField<List<Blocked>>) = apply {
                    this.blocked = blocked.map { it.toMutableList() }
                }

                /**
                 * Adds a single [Blocked] to [Builder.blocked].
                 *
                 * @throws IllegalStateException if the field was previously set to a non-list.
                 */
                fun addBlocked(blocked: Blocked) = apply {
                    this.blocked =
                        (this.blocked ?: JsonField.of(mutableListOf())).also {
                            checkKnown("blocked", it).add(blocked)
                        }
                }

                fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                    this.additionalProperties.clear()
                    putAllAdditionalProperties(additionalProperties)
                }

                fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                    additionalProperties.put(key, value)
                }

                fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                    apply {
                        this.additionalProperties.putAll(additionalProperties)
                    }

                fun removeAdditionalProperty(key: String) = apply {
                    additionalProperties.remove(key)
                }

                fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                    keys.forEach(::removeAdditionalProperty)
                }

                /**
                 * Returns an immutable instance of [MerchantAcceptorIdentifier].
                 *
                 * Further updates to this [Builder] will not mutate the returned instance.
                 *
                 * The following fields are required:
                 * ```java
                 * .allowed()
                 * .blocked()
                 * ```
                 *
                 * @throws IllegalStateException if any required field is unset.
                 */
                fun build(): MerchantAcceptorIdentifier =
                    MerchantAcceptorIdentifier(
                        checkRequired("allowed", allowed).map { it.toImmutable() },
                        checkRequired("blocked", blocked).map { it.toImmutable() },
                        additionalProperties.toMutableMap(),
                    )
            }

            private var validated: Boolean = false

            /**
             * Validates that the types of all values in this object match their expected types
             * recursively.
             *
             * This method is _not_ forwards compatible with new types from the API for existing
             * fields.
             *
             * @throws IncreaseInvalidDataException if any value type in this object doesn't match
             *   its expected type.
             */
            fun validate(): MerchantAcceptorIdentifier = apply {
                if (validated) {
                    return@apply
                }

                allowed().ifPresent { it.forEach { it.validate() } }
                blocked().ifPresent { it.forEach { it.validate() } }
                validated = true
            }

            fun isValid(): Boolean =
                try {
                    validate()
                    true
                } catch (e: IncreaseInvalidDataException) {
                    false
                }

            /**
             * Returns a score indicating how many valid values are contained in this object
             * recursively.
             *
             * Used for best match union deserialization.
             */
            @JvmSynthetic
            internal fun validity(): Int =
                (allowed.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
                    (blocked.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0)

            class Allowed
            @JsonCreator(mode = JsonCreator.Mode.DISABLED)
            private constructor(
                private val identifier: JsonField<String>,
                private val additionalProperties: MutableMap<String, JsonValue>,
            ) {

                @JsonCreator
                private constructor(
                    @JsonProperty("identifier")
                    @ExcludeMissing
                    identifier: JsonField<String> = JsonMissing.of()
                ) : this(identifier, mutableMapOf())

                /**
                 * The Merchant Acceptor ID.
                 *
                 * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or
                 *   is unexpectedly missing or null (e.g. if the server responded with an
                 *   unexpected value).
                 */
                fun identifier(): String = identifier.getRequired("identifier")

                /**
                 * Returns the raw JSON value of [identifier].
                 *
                 * Unlike [identifier], this method doesn't throw if the JSON field has an
                 * unexpected type.
                 */
                @JsonProperty("identifier")
                @ExcludeMissing
                fun _identifier(): JsonField<String> = identifier

                @JsonAnySetter
                private fun putAdditionalProperty(key: String, value: JsonValue) {
                    additionalProperties.put(key, value)
                }

                @JsonAnyGetter
                @ExcludeMissing
                fun _additionalProperties(): Map<String, JsonValue> =
                    Collections.unmodifiableMap(additionalProperties)

                fun toBuilder() = Builder().from(this)

                companion object {

                    /**
                     * Returns a mutable builder for constructing an instance of [Allowed].
                     *
                     * The following fields are required:
                     * ```java
                     * .identifier()
                     * ```
                     */
                    @JvmStatic fun builder() = Builder()
                }

                /** A builder for [Allowed]. */
                class Builder internal constructor() {

                    private var identifier: JsonField<String>? = null
                    private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                    @JvmSynthetic
                    internal fun from(allowed: Allowed) = apply {
                        identifier = allowed.identifier
                        additionalProperties = allowed.additionalProperties.toMutableMap()
                    }

                    /** The Merchant Acceptor ID. */
                    fun identifier(identifier: String) = identifier(JsonField.of(identifier))

                    /**
                     * Sets [Builder.identifier] to an arbitrary JSON value.
                     *
                     * You should usually call [Builder.identifier] with a well-typed [String] value
                     * instead. This method is primarily for setting the field to an undocumented or
                     * not yet supported value.
                     */
                    fun identifier(identifier: JsonField<String>) = apply {
                        this.identifier = identifier
                    }

                    fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                        this.additionalProperties.clear()
                        putAllAdditionalProperties(additionalProperties)
                    }

                    fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                        additionalProperties.put(key, value)
                    }

                    fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                        apply {
                            this.additionalProperties.putAll(additionalProperties)
                        }

                    fun removeAdditionalProperty(key: String) = apply {
                        additionalProperties.remove(key)
                    }

                    fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                        keys.forEach(::removeAdditionalProperty)
                    }

                    /**
                     * Returns an immutable instance of [Allowed].
                     *
                     * Further updates to this [Builder] will not mutate the returned instance.
                     *
                     * The following fields are required:
                     * ```java
                     * .identifier()
                     * ```
                     *
                     * @throws IllegalStateException if any required field is unset.
                     */
                    fun build(): Allowed =
                        Allowed(
                            checkRequired("identifier", identifier),
                            additionalProperties.toMutableMap(),
                        )
                }

                private var validated: Boolean = false

                /**
                 * Validates that the types of all values in this object match their expected types
                 * recursively.
                 *
                 * This method is _not_ forwards compatible with new types from the API for existing
                 * fields.
                 *
                 * @throws IncreaseInvalidDataException if any value type in this object doesn't
                 *   match its expected type.
                 */
                fun validate(): Allowed = apply {
                    if (validated) {
                        return@apply
                    }

                    identifier()
                    validated = true
                }

                fun isValid(): Boolean =
                    try {
                        validate()
                        true
                    } catch (e: IncreaseInvalidDataException) {
                        false
                    }

                /**
                 * Returns a score indicating how many valid values are contained in this object
                 * recursively.
                 *
                 * Used for best match union deserialization.
                 */
                @JvmSynthetic
                internal fun validity(): Int = (if (identifier.asKnown().isPresent) 1 else 0)

                override fun equals(other: Any?): Boolean {
                    if (this === other) {
                        return true
                    }

                    return other is Allowed &&
                        identifier == other.identifier &&
                        additionalProperties == other.additionalProperties
                }

                private val hashCode: Int by lazy { Objects.hash(identifier, additionalProperties) }

                override fun hashCode(): Int = hashCode

                override fun toString() =
                    "Allowed{identifier=$identifier, additionalProperties=$additionalProperties}"
            }

            class Blocked
            @JsonCreator(mode = JsonCreator.Mode.DISABLED)
            private constructor(
                private val identifier: JsonField<String>,
                private val additionalProperties: MutableMap<String, JsonValue>,
            ) {

                @JsonCreator
                private constructor(
                    @JsonProperty("identifier")
                    @ExcludeMissing
                    identifier: JsonField<String> = JsonMissing.of()
                ) : this(identifier, mutableMapOf())

                /**
                 * The Merchant Acceptor ID.
                 *
                 * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or
                 *   is unexpectedly missing or null (e.g. if the server responded with an
                 *   unexpected value).
                 */
                fun identifier(): String = identifier.getRequired("identifier")

                /**
                 * Returns the raw JSON value of [identifier].
                 *
                 * Unlike [identifier], this method doesn't throw if the JSON field has an
                 * unexpected type.
                 */
                @JsonProperty("identifier")
                @ExcludeMissing
                fun _identifier(): JsonField<String> = identifier

                @JsonAnySetter
                private fun putAdditionalProperty(key: String, value: JsonValue) {
                    additionalProperties.put(key, value)
                }

                @JsonAnyGetter
                @ExcludeMissing
                fun _additionalProperties(): Map<String, JsonValue> =
                    Collections.unmodifiableMap(additionalProperties)

                fun toBuilder() = Builder().from(this)

                companion object {

                    /**
                     * Returns a mutable builder for constructing an instance of [Blocked].
                     *
                     * The following fields are required:
                     * ```java
                     * .identifier()
                     * ```
                     */
                    @JvmStatic fun builder() = Builder()
                }

                /** A builder for [Blocked]. */
                class Builder internal constructor() {

                    private var identifier: JsonField<String>? = null
                    private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                    @JvmSynthetic
                    internal fun from(blocked: Blocked) = apply {
                        identifier = blocked.identifier
                        additionalProperties = blocked.additionalProperties.toMutableMap()
                    }

                    /** The Merchant Acceptor ID. */
                    fun identifier(identifier: String) = identifier(JsonField.of(identifier))

                    /**
                     * Sets [Builder.identifier] to an arbitrary JSON value.
                     *
                     * You should usually call [Builder.identifier] with a well-typed [String] value
                     * instead. This method is primarily for setting the field to an undocumented or
                     * not yet supported value.
                     */
                    fun identifier(identifier: JsonField<String>) = apply {
                        this.identifier = identifier
                    }

                    fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                        this.additionalProperties.clear()
                        putAllAdditionalProperties(additionalProperties)
                    }

                    fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                        additionalProperties.put(key, value)
                    }

                    fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                        apply {
                            this.additionalProperties.putAll(additionalProperties)
                        }

                    fun removeAdditionalProperty(key: String) = apply {
                        additionalProperties.remove(key)
                    }

                    fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                        keys.forEach(::removeAdditionalProperty)
                    }

                    /**
                     * Returns an immutable instance of [Blocked].
                     *
                     * Further updates to this [Builder] will not mutate the returned instance.
                     *
                     * The following fields are required:
                     * ```java
                     * .identifier()
                     * ```
                     *
                     * @throws IllegalStateException if any required field is unset.
                     */
                    fun build(): Blocked =
                        Blocked(
                            checkRequired("identifier", identifier),
                            additionalProperties.toMutableMap(),
                        )
                }

                private var validated: Boolean = false

                /**
                 * Validates that the types of all values in this object match their expected types
                 * recursively.
                 *
                 * This method is _not_ forwards compatible with new types from the API for existing
                 * fields.
                 *
                 * @throws IncreaseInvalidDataException if any value type in this object doesn't
                 *   match its expected type.
                 */
                fun validate(): Blocked = apply {
                    if (validated) {
                        return@apply
                    }

                    identifier()
                    validated = true
                }

                fun isValid(): Boolean =
                    try {
                        validate()
                        true
                    } catch (e: IncreaseInvalidDataException) {
                        false
                    }

                /**
                 * Returns a score indicating how many valid values are contained in this object
                 * recursively.
                 *
                 * Used for best match union deserialization.
                 */
                @JvmSynthetic
                internal fun validity(): Int = (if (identifier.asKnown().isPresent) 1 else 0)

                override fun equals(other: Any?): Boolean {
                    if (this === other) {
                        return true
                    }

                    return other is Blocked &&
                        identifier == other.identifier &&
                        additionalProperties == other.additionalProperties
                }

                private val hashCode: Int by lazy { Objects.hash(identifier, additionalProperties) }

                override fun hashCode(): Int = hashCode

                override fun toString() =
                    "Blocked{identifier=$identifier, additionalProperties=$additionalProperties}"
            }

            override fun equals(other: Any?): Boolean {
                if (this === other) {
                    return true
                }

                return other is MerchantAcceptorIdentifier &&
                    allowed == other.allowed &&
                    blocked == other.blocked &&
                    additionalProperties == other.additionalProperties
            }

            private val hashCode: Int by lazy {
                Objects.hash(allowed, blocked, additionalProperties)
            }

            override fun hashCode(): Int = hashCode

            override fun toString() =
                "MerchantAcceptorIdentifier{allowed=$allowed, blocked=$blocked, additionalProperties=$additionalProperties}"
        }

        /**
         * Restricts which Merchant Category Codes are allowed or blocked for authorizations on this
         * card.
         */
        class MerchantCategoryCode
        @JsonCreator(mode = JsonCreator.Mode.DISABLED)
        private constructor(
            private val allowed: JsonField<List<Allowed>>,
            private val blocked: JsonField<List<Blocked>>,
            private val additionalProperties: MutableMap<String, JsonValue>,
        ) {

            @JsonCreator
            private constructor(
                @JsonProperty("allowed")
                @ExcludeMissing
                allowed: JsonField<List<Allowed>> = JsonMissing.of(),
                @JsonProperty("blocked")
                @ExcludeMissing
                blocked: JsonField<List<Blocked>> = JsonMissing.of(),
            ) : this(allowed, blocked, mutableMapOf())

            /**
             * The Merchant Category Codes that are allowed for authorizations on this card.
             *
             * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g.
             *   if the server responded with an unexpected value).
             */
            fun allowed(): Optional<List<Allowed>> = allowed.getOptional("allowed")

            /**
             * The Merchant Category Codes that are blocked for authorizations on this card.
             *
             * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g.
             *   if the server responded with an unexpected value).
             */
            fun blocked(): Optional<List<Blocked>> = blocked.getOptional("blocked")

            /**
             * Returns the raw JSON value of [allowed].
             *
             * Unlike [allowed], this method doesn't throw if the JSON field has an unexpected type.
             */
            @JsonProperty("allowed")
            @ExcludeMissing
            fun _allowed(): JsonField<List<Allowed>> = allowed

            /**
             * Returns the raw JSON value of [blocked].
             *
             * Unlike [blocked], this method doesn't throw if the JSON field has an unexpected type.
             */
            @JsonProperty("blocked")
            @ExcludeMissing
            fun _blocked(): JsonField<List<Blocked>> = blocked

            @JsonAnySetter
            private fun putAdditionalProperty(key: String, value: JsonValue) {
                additionalProperties.put(key, value)
            }

            @JsonAnyGetter
            @ExcludeMissing
            fun _additionalProperties(): Map<String, JsonValue> =
                Collections.unmodifiableMap(additionalProperties)

            fun toBuilder() = Builder().from(this)

            companion object {

                /**
                 * Returns a mutable builder for constructing an instance of [MerchantCategoryCode].
                 *
                 * The following fields are required:
                 * ```java
                 * .allowed()
                 * .blocked()
                 * ```
                 */
                @JvmStatic fun builder() = Builder()
            }

            /** A builder for [MerchantCategoryCode]. */
            class Builder internal constructor() {

                private var allowed: JsonField<MutableList<Allowed>>? = null
                private var blocked: JsonField<MutableList<Blocked>>? = null
                private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                @JvmSynthetic
                internal fun from(merchantCategoryCode: MerchantCategoryCode) = apply {
                    allowed = merchantCategoryCode.allowed.map { it.toMutableList() }
                    blocked = merchantCategoryCode.blocked.map { it.toMutableList() }
                    additionalProperties = merchantCategoryCode.additionalProperties.toMutableMap()
                }

                /** The Merchant Category Codes that are allowed for authorizations on this card. */
                fun allowed(allowed: List<Allowed>?) = allowed(JsonField.ofNullable(allowed))

                /** Alias for calling [Builder.allowed] with `allowed.orElse(null)`. */
                fun allowed(allowed: Optional<List<Allowed>>) = allowed(allowed.getOrNull())

                /**
                 * Sets [Builder.allowed] to an arbitrary JSON value.
                 *
                 * You should usually call [Builder.allowed] with a well-typed `List<Allowed>` value
                 * instead. This method is primarily for setting the field to an undocumented or not
                 * yet supported value.
                 */
                fun allowed(allowed: JsonField<List<Allowed>>) = apply {
                    this.allowed = allowed.map { it.toMutableList() }
                }

                /**
                 * Adds a single [Allowed] to [Builder.allowed].
                 *
                 * @throws IllegalStateException if the field was previously set to a non-list.
                 */
                fun addAllowed(allowed: Allowed) = apply {
                    this.allowed =
                        (this.allowed ?: JsonField.of(mutableListOf())).also {
                            checkKnown("allowed", it).add(allowed)
                        }
                }

                /** The Merchant Category Codes that are blocked for authorizations on this card. */
                fun blocked(blocked: List<Blocked>?) = blocked(JsonField.ofNullable(blocked))

                /** Alias for calling [Builder.blocked] with `blocked.orElse(null)`. */
                fun blocked(blocked: Optional<List<Blocked>>) = blocked(blocked.getOrNull())

                /**
                 * Sets [Builder.blocked] to an arbitrary JSON value.
                 *
                 * You should usually call [Builder.blocked] with a well-typed `List<Blocked>` value
                 * instead. This method is primarily for setting the field to an undocumented or not
                 * yet supported value.
                 */
                fun blocked(blocked: JsonField<List<Blocked>>) = apply {
                    this.blocked = blocked.map { it.toMutableList() }
                }

                /**
                 * Adds a single [Blocked] to [Builder.blocked].
                 *
                 * @throws IllegalStateException if the field was previously set to a non-list.
                 */
                fun addBlocked(blocked: Blocked) = apply {
                    this.blocked =
                        (this.blocked ?: JsonField.of(mutableListOf())).also {
                            checkKnown("blocked", it).add(blocked)
                        }
                }

                fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                    this.additionalProperties.clear()
                    putAllAdditionalProperties(additionalProperties)
                }

                fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                    additionalProperties.put(key, value)
                }

                fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                    apply {
                        this.additionalProperties.putAll(additionalProperties)
                    }

                fun removeAdditionalProperty(key: String) = apply {
                    additionalProperties.remove(key)
                }

                fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                    keys.forEach(::removeAdditionalProperty)
                }

                /**
                 * Returns an immutable instance of [MerchantCategoryCode].
                 *
                 * Further updates to this [Builder] will not mutate the returned instance.
                 *
                 * The following fields are required:
                 * ```java
                 * .allowed()
                 * .blocked()
                 * ```
                 *
                 * @throws IllegalStateException if any required field is unset.
                 */
                fun build(): MerchantCategoryCode =
                    MerchantCategoryCode(
                        checkRequired("allowed", allowed).map { it.toImmutable() },
                        checkRequired("blocked", blocked).map { it.toImmutable() },
                        additionalProperties.toMutableMap(),
                    )
            }

            private var validated: Boolean = false

            /**
             * Validates that the types of all values in this object match their expected types
             * recursively.
             *
             * This method is _not_ forwards compatible with new types from the API for existing
             * fields.
             *
             * @throws IncreaseInvalidDataException if any value type in this object doesn't match
             *   its expected type.
             */
            fun validate(): MerchantCategoryCode = apply {
                if (validated) {
                    return@apply
                }

                allowed().ifPresent { it.forEach { it.validate() } }
                blocked().ifPresent { it.forEach { it.validate() } }
                validated = true
            }

            fun isValid(): Boolean =
                try {
                    validate()
                    true
                } catch (e: IncreaseInvalidDataException) {
                    false
                }

            /**
             * Returns a score indicating how many valid values are contained in this object
             * recursively.
             *
             * Used for best match union deserialization.
             */
            @JvmSynthetic
            internal fun validity(): Int =
                (allowed.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
                    (blocked.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0)

            class Allowed
            @JsonCreator(mode = JsonCreator.Mode.DISABLED)
            private constructor(
                private val code: JsonField<String>,
                private val additionalProperties: MutableMap<String, JsonValue>,
            ) {

                @JsonCreator
                private constructor(
                    @JsonProperty("code") @ExcludeMissing code: JsonField<String> = JsonMissing.of()
                ) : this(code, mutableMapOf())

                /**
                 * The Merchant Category Code (MCC).
                 *
                 * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or
                 *   is unexpectedly missing or null (e.g. if the server responded with an
                 *   unexpected value).
                 */
                fun code(): String = code.getRequired("code")

                /**
                 * Returns the raw JSON value of [code].
                 *
                 * Unlike [code], this method doesn't throw if the JSON field has an unexpected
                 * type.
                 */
                @JsonProperty("code") @ExcludeMissing fun _code(): JsonField<String> = code

                @JsonAnySetter
                private fun putAdditionalProperty(key: String, value: JsonValue) {
                    additionalProperties.put(key, value)
                }

                @JsonAnyGetter
                @ExcludeMissing
                fun _additionalProperties(): Map<String, JsonValue> =
                    Collections.unmodifiableMap(additionalProperties)

                fun toBuilder() = Builder().from(this)

                companion object {

                    /**
                     * Returns a mutable builder for constructing an instance of [Allowed].
                     *
                     * The following fields are required:
                     * ```java
                     * .code()
                     * ```
                     */
                    @JvmStatic fun builder() = Builder()
                }

                /** A builder for [Allowed]. */
                class Builder internal constructor() {

                    private var code: JsonField<String>? = null
                    private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                    @JvmSynthetic
                    internal fun from(allowed: Allowed) = apply {
                        code = allowed.code
                        additionalProperties = allowed.additionalProperties.toMutableMap()
                    }

                    /** The Merchant Category Code (MCC). */
                    fun code(code: String) = code(JsonField.of(code))

                    /**
                     * Sets [Builder.code] to an arbitrary JSON value.
                     *
                     * You should usually call [Builder.code] with a well-typed [String] value
                     * instead. This method is primarily for setting the field to an undocumented or
                     * not yet supported value.
                     */
                    fun code(code: JsonField<String>) = apply { this.code = code }

                    fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                        this.additionalProperties.clear()
                        putAllAdditionalProperties(additionalProperties)
                    }

                    fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                        additionalProperties.put(key, value)
                    }

                    fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                        apply {
                            this.additionalProperties.putAll(additionalProperties)
                        }

                    fun removeAdditionalProperty(key: String) = apply {
                        additionalProperties.remove(key)
                    }

                    fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                        keys.forEach(::removeAdditionalProperty)
                    }

                    /**
                     * Returns an immutable instance of [Allowed].
                     *
                     * Further updates to this [Builder] will not mutate the returned instance.
                     *
                     * The following fields are required:
                     * ```java
                     * .code()
                     * ```
                     *
                     * @throws IllegalStateException if any required field is unset.
                     */
                    fun build(): Allowed =
                        Allowed(checkRequired("code", code), additionalProperties.toMutableMap())
                }

                private var validated: Boolean = false

                /**
                 * Validates that the types of all values in this object match their expected types
                 * recursively.
                 *
                 * This method is _not_ forwards compatible with new types from the API for existing
                 * fields.
                 *
                 * @throws IncreaseInvalidDataException if any value type in this object doesn't
                 *   match its expected type.
                 */
                fun validate(): Allowed = apply {
                    if (validated) {
                        return@apply
                    }

                    code()
                    validated = true
                }

                fun isValid(): Boolean =
                    try {
                        validate()
                        true
                    } catch (e: IncreaseInvalidDataException) {
                        false
                    }

                /**
                 * Returns a score indicating how many valid values are contained in this object
                 * recursively.
                 *
                 * Used for best match union deserialization.
                 */
                @JvmSynthetic
                internal fun validity(): Int = (if (code.asKnown().isPresent) 1 else 0)

                override fun equals(other: Any?): Boolean {
                    if (this === other) {
                        return true
                    }

                    return other is Allowed &&
                        code == other.code &&
                        additionalProperties == other.additionalProperties
                }

                private val hashCode: Int by lazy { Objects.hash(code, additionalProperties) }

                override fun hashCode(): Int = hashCode

                override fun toString() =
                    "Allowed{code=$code, additionalProperties=$additionalProperties}"
            }

            class Blocked
            @JsonCreator(mode = JsonCreator.Mode.DISABLED)
            private constructor(
                private val code: JsonField<String>,
                private val additionalProperties: MutableMap<String, JsonValue>,
            ) {

                @JsonCreator
                private constructor(
                    @JsonProperty("code") @ExcludeMissing code: JsonField<String> = JsonMissing.of()
                ) : this(code, mutableMapOf())

                /**
                 * The Merchant Category Code (MCC).
                 *
                 * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or
                 *   is unexpectedly missing or null (e.g. if the server responded with an
                 *   unexpected value).
                 */
                fun code(): String = code.getRequired("code")

                /**
                 * Returns the raw JSON value of [code].
                 *
                 * Unlike [code], this method doesn't throw if the JSON field has an unexpected
                 * type.
                 */
                @JsonProperty("code") @ExcludeMissing fun _code(): JsonField<String> = code

                @JsonAnySetter
                private fun putAdditionalProperty(key: String, value: JsonValue) {
                    additionalProperties.put(key, value)
                }

                @JsonAnyGetter
                @ExcludeMissing
                fun _additionalProperties(): Map<String, JsonValue> =
                    Collections.unmodifiableMap(additionalProperties)

                fun toBuilder() = Builder().from(this)

                companion object {

                    /**
                     * Returns a mutable builder for constructing an instance of [Blocked].
                     *
                     * The following fields are required:
                     * ```java
                     * .code()
                     * ```
                     */
                    @JvmStatic fun builder() = Builder()
                }

                /** A builder for [Blocked]. */
                class Builder internal constructor() {

                    private var code: JsonField<String>? = null
                    private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                    @JvmSynthetic
                    internal fun from(blocked: Blocked) = apply {
                        code = blocked.code
                        additionalProperties = blocked.additionalProperties.toMutableMap()
                    }

                    /** The Merchant Category Code (MCC). */
                    fun code(code: String) = code(JsonField.of(code))

                    /**
                     * Sets [Builder.code] to an arbitrary JSON value.
                     *
                     * You should usually call [Builder.code] with a well-typed [String] value
                     * instead. This method is primarily for setting the field to an undocumented or
                     * not yet supported value.
                     */
                    fun code(code: JsonField<String>) = apply { this.code = code }

                    fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                        this.additionalProperties.clear()
                        putAllAdditionalProperties(additionalProperties)
                    }

                    fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                        additionalProperties.put(key, value)
                    }

                    fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                        apply {
                            this.additionalProperties.putAll(additionalProperties)
                        }

                    fun removeAdditionalProperty(key: String) = apply {
                        additionalProperties.remove(key)
                    }

                    fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                        keys.forEach(::removeAdditionalProperty)
                    }

                    /**
                     * Returns an immutable instance of [Blocked].
                     *
                     * Further updates to this [Builder] will not mutate the returned instance.
                     *
                     * The following fields are required:
                     * ```java
                     * .code()
                     * ```
                     *
                     * @throws IllegalStateException if any required field is unset.
                     */
                    fun build(): Blocked =
                        Blocked(checkRequired("code", code), additionalProperties.toMutableMap())
                }

                private var validated: Boolean = false

                /**
                 * Validates that the types of all values in this object match their expected types
                 * recursively.
                 *
                 * This method is _not_ forwards compatible with new types from the API for existing
                 * fields.
                 *
                 * @throws IncreaseInvalidDataException if any value type in this object doesn't
                 *   match its expected type.
                 */
                fun validate(): Blocked = apply {
                    if (validated) {
                        return@apply
                    }

                    code()
                    validated = true
                }

                fun isValid(): Boolean =
                    try {
                        validate()
                        true
                    } catch (e: IncreaseInvalidDataException) {
                        false
                    }

                /**
                 * Returns a score indicating how many valid values are contained in this object
                 * recursively.
                 *
                 * Used for best match union deserialization.
                 */
                @JvmSynthetic
                internal fun validity(): Int = (if (code.asKnown().isPresent) 1 else 0)

                override fun equals(other: Any?): Boolean {
                    if (this === other) {
                        return true
                    }

                    return other is Blocked &&
                        code == other.code &&
                        additionalProperties == other.additionalProperties
                }

                private val hashCode: Int by lazy { Objects.hash(code, additionalProperties) }

                override fun hashCode(): Int = hashCode

                override fun toString() =
                    "Blocked{code=$code, additionalProperties=$additionalProperties}"
            }

            override fun equals(other: Any?): Boolean {
                if (this === other) {
                    return true
                }

                return other is MerchantCategoryCode &&
                    allowed == other.allowed &&
                    blocked == other.blocked &&
                    additionalProperties == other.additionalProperties
            }

            private val hashCode: Int by lazy {
                Objects.hash(allowed, blocked, additionalProperties)
            }

            override fun hashCode(): Int = hashCode

            override fun toString() =
                "MerchantCategoryCode{allowed=$allowed, blocked=$blocked, additionalProperties=$additionalProperties}"
        }

        /**
         * Restricts which merchant countries are allowed or blocked for authorizations on this
         * card.
         */
        class MerchantCountry
        @JsonCreator(mode = JsonCreator.Mode.DISABLED)
        private constructor(
            private val allowed: JsonField<List<Allowed>>,
            private val blocked: JsonField<List<Blocked>>,
            private val additionalProperties: MutableMap<String, JsonValue>,
        ) {

            @JsonCreator
            private constructor(
                @JsonProperty("allowed")
                @ExcludeMissing
                allowed: JsonField<List<Allowed>> = JsonMissing.of(),
                @JsonProperty("blocked")
                @ExcludeMissing
                blocked: JsonField<List<Blocked>> = JsonMissing.of(),
            ) : this(allowed, blocked, mutableMapOf())

            /**
             * The merchant countries that are allowed for authorizations on this card.
             *
             * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g.
             *   if the server responded with an unexpected value).
             */
            fun allowed(): Optional<List<Allowed>> = allowed.getOptional("allowed")

            /**
             * The merchant countries that are blocked for authorizations on this card.
             *
             * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g.
             *   if the server responded with an unexpected value).
             */
            fun blocked(): Optional<List<Blocked>> = blocked.getOptional("blocked")

            /**
             * Returns the raw JSON value of [allowed].
             *
             * Unlike [allowed], this method doesn't throw if the JSON field has an unexpected type.
             */
            @JsonProperty("allowed")
            @ExcludeMissing
            fun _allowed(): JsonField<List<Allowed>> = allowed

            /**
             * Returns the raw JSON value of [blocked].
             *
             * Unlike [blocked], this method doesn't throw if the JSON field has an unexpected type.
             */
            @JsonProperty("blocked")
            @ExcludeMissing
            fun _blocked(): JsonField<List<Blocked>> = blocked

            @JsonAnySetter
            private fun putAdditionalProperty(key: String, value: JsonValue) {
                additionalProperties.put(key, value)
            }

            @JsonAnyGetter
            @ExcludeMissing
            fun _additionalProperties(): Map<String, JsonValue> =
                Collections.unmodifiableMap(additionalProperties)

            fun toBuilder() = Builder().from(this)

            companion object {

                /**
                 * Returns a mutable builder for constructing an instance of [MerchantCountry].
                 *
                 * The following fields are required:
                 * ```java
                 * .allowed()
                 * .blocked()
                 * ```
                 */
                @JvmStatic fun builder() = Builder()
            }

            /** A builder for [MerchantCountry]. */
            class Builder internal constructor() {

                private var allowed: JsonField<MutableList<Allowed>>? = null
                private var blocked: JsonField<MutableList<Blocked>>? = null
                private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                @JvmSynthetic
                internal fun from(merchantCountry: MerchantCountry) = apply {
                    allowed = merchantCountry.allowed.map { it.toMutableList() }
                    blocked = merchantCountry.blocked.map { it.toMutableList() }
                    additionalProperties = merchantCountry.additionalProperties.toMutableMap()
                }

                /** The merchant countries that are allowed for authorizations on this card. */
                fun allowed(allowed: List<Allowed>?) = allowed(JsonField.ofNullable(allowed))

                /** Alias for calling [Builder.allowed] with `allowed.orElse(null)`. */
                fun allowed(allowed: Optional<List<Allowed>>) = allowed(allowed.getOrNull())

                /**
                 * Sets [Builder.allowed] to an arbitrary JSON value.
                 *
                 * You should usually call [Builder.allowed] with a well-typed `List<Allowed>` value
                 * instead. This method is primarily for setting the field to an undocumented or not
                 * yet supported value.
                 */
                fun allowed(allowed: JsonField<List<Allowed>>) = apply {
                    this.allowed = allowed.map { it.toMutableList() }
                }

                /**
                 * Adds a single [Allowed] to [Builder.allowed].
                 *
                 * @throws IllegalStateException if the field was previously set to a non-list.
                 */
                fun addAllowed(allowed: Allowed) = apply {
                    this.allowed =
                        (this.allowed ?: JsonField.of(mutableListOf())).also {
                            checkKnown("allowed", it).add(allowed)
                        }
                }

                /** The merchant countries that are blocked for authorizations on this card. */
                fun blocked(blocked: List<Blocked>?) = blocked(JsonField.ofNullable(blocked))

                /** Alias for calling [Builder.blocked] with `blocked.orElse(null)`. */
                fun blocked(blocked: Optional<List<Blocked>>) = blocked(blocked.getOrNull())

                /**
                 * Sets [Builder.blocked] to an arbitrary JSON value.
                 *
                 * You should usually call [Builder.blocked] with a well-typed `List<Blocked>` value
                 * instead. This method is primarily for setting the field to an undocumented or not
                 * yet supported value.
                 */
                fun blocked(blocked: JsonField<List<Blocked>>) = apply {
                    this.blocked = blocked.map { it.toMutableList() }
                }

                /**
                 * Adds a single [Blocked] to [Builder.blocked].
                 *
                 * @throws IllegalStateException if the field was previously set to a non-list.
                 */
                fun addBlocked(blocked: Blocked) = apply {
                    this.blocked =
                        (this.blocked ?: JsonField.of(mutableListOf())).also {
                            checkKnown("blocked", it).add(blocked)
                        }
                }

                fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                    this.additionalProperties.clear()
                    putAllAdditionalProperties(additionalProperties)
                }

                fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                    additionalProperties.put(key, value)
                }

                fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                    apply {
                        this.additionalProperties.putAll(additionalProperties)
                    }

                fun removeAdditionalProperty(key: String) = apply {
                    additionalProperties.remove(key)
                }

                fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                    keys.forEach(::removeAdditionalProperty)
                }

                /**
                 * Returns an immutable instance of [MerchantCountry].
                 *
                 * Further updates to this [Builder] will not mutate the returned instance.
                 *
                 * The following fields are required:
                 * ```java
                 * .allowed()
                 * .blocked()
                 * ```
                 *
                 * @throws IllegalStateException if any required field is unset.
                 */
                fun build(): MerchantCountry =
                    MerchantCountry(
                        checkRequired("allowed", allowed).map { it.toImmutable() },
                        checkRequired("blocked", blocked).map { it.toImmutable() },
                        additionalProperties.toMutableMap(),
                    )
            }

            private var validated: Boolean = false

            /**
             * Validates that the types of all values in this object match their expected types
             * recursively.
             *
             * This method is _not_ forwards compatible with new types from the API for existing
             * fields.
             *
             * @throws IncreaseInvalidDataException if any value type in this object doesn't match
             *   its expected type.
             */
            fun validate(): MerchantCountry = apply {
                if (validated) {
                    return@apply
                }

                allowed().ifPresent { it.forEach { it.validate() } }
                blocked().ifPresent { it.forEach { it.validate() } }
                validated = true
            }

            fun isValid(): Boolean =
                try {
                    validate()
                    true
                } catch (e: IncreaseInvalidDataException) {
                    false
                }

            /**
             * Returns a score indicating how many valid values are contained in this object
             * recursively.
             *
             * Used for best match union deserialization.
             */
            @JvmSynthetic
            internal fun validity(): Int =
                (allowed.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
                    (blocked.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0)

            class Allowed
            @JsonCreator(mode = JsonCreator.Mode.DISABLED)
            private constructor(
                private val country: JsonField<String>,
                private val additionalProperties: MutableMap<String, JsonValue>,
            ) {

                @JsonCreator
                private constructor(
                    @JsonProperty("country")
                    @ExcludeMissing
                    country: JsonField<String> = JsonMissing.of()
                ) : this(country, mutableMapOf())

                /**
                 * The ISO 3166-1 alpha-2 country code.
                 *
                 * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or
                 *   is unexpectedly missing or null (e.g. if the server responded with an
                 *   unexpected value).
                 */
                fun country(): String = country.getRequired("country")

                /**
                 * Returns the raw JSON value of [country].
                 *
                 * Unlike [country], this method doesn't throw if the JSON field has an unexpected
                 * type.
                 */
                @JsonProperty("country") @ExcludeMissing fun _country(): JsonField<String> = country

                @JsonAnySetter
                private fun putAdditionalProperty(key: String, value: JsonValue) {
                    additionalProperties.put(key, value)
                }

                @JsonAnyGetter
                @ExcludeMissing
                fun _additionalProperties(): Map<String, JsonValue> =
                    Collections.unmodifiableMap(additionalProperties)

                fun toBuilder() = Builder().from(this)

                companion object {

                    /**
                     * Returns a mutable builder for constructing an instance of [Allowed].
                     *
                     * The following fields are required:
                     * ```java
                     * .country()
                     * ```
                     */
                    @JvmStatic fun builder() = Builder()
                }

                /** A builder for [Allowed]. */
                class Builder internal constructor() {

                    private var country: JsonField<String>? = null
                    private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                    @JvmSynthetic
                    internal fun from(allowed: Allowed) = apply {
                        country = allowed.country
                        additionalProperties = allowed.additionalProperties.toMutableMap()
                    }

                    /** The ISO 3166-1 alpha-2 country code. */
                    fun country(country: String) = country(JsonField.of(country))

                    /**
                     * Sets [Builder.country] to an arbitrary JSON value.
                     *
                     * You should usually call [Builder.country] with a well-typed [String] value
                     * instead. This method is primarily for setting the field to an undocumented or
                     * not yet supported value.
                     */
                    fun country(country: JsonField<String>) = apply { this.country = country }

                    fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                        this.additionalProperties.clear()
                        putAllAdditionalProperties(additionalProperties)
                    }

                    fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                        additionalProperties.put(key, value)
                    }

                    fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                        apply {
                            this.additionalProperties.putAll(additionalProperties)
                        }

                    fun removeAdditionalProperty(key: String) = apply {
                        additionalProperties.remove(key)
                    }

                    fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                        keys.forEach(::removeAdditionalProperty)
                    }

                    /**
                     * Returns an immutable instance of [Allowed].
                     *
                     * Further updates to this [Builder] will not mutate the returned instance.
                     *
                     * The following fields are required:
                     * ```java
                     * .country()
                     * ```
                     *
                     * @throws IllegalStateException if any required field is unset.
                     */
                    fun build(): Allowed =
                        Allowed(
                            checkRequired("country", country),
                            additionalProperties.toMutableMap(),
                        )
                }

                private var validated: Boolean = false

                /**
                 * Validates that the types of all values in this object match their expected types
                 * recursively.
                 *
                 * This method is _not_ forwards compatible with new types from the API for existing
                 * fields.
                 *
                 * @throws IncreaseInvalidDataException if any value type in this object doesn't
                 *   match its expected type.
                 */
                fun validate(): Allowed = apply {
                    if (validated) {
                        return@apply
                    }

                    country()
                    validated = true
                }

                fun isValid(): Boolean =
                    try {
                        validate()
                        true
                    } catch (e: IncreaseInvalidDataException) {
                        false
                    }

                /**
                 * Returns a score indicating how many valid values are contained in this object
                 * recursively.
                 *
                 * Used for best match union deserialization.
                 */
                @JvmSynthetic
                internal fun validity(): Int = (if (country.asKnown().isPresent) 1 else 0)

                override fun equals(other: Any?): Boolean {
                    if (this === other) {
                        return true
                    }

                    return other is Allowed &&
                        country == other.country &&
                        additionalProperties == other.additionalProperties
                }

                private val hashCode: Int by lazy { Objects.hash(country, additionalProperties) }

                override fun hashCode(): Int = hashCode

                override fun toString() =
                    "Allowed{country=$country, additionalProperties=$additionalProperties}"
            }

            class Blocked
            @JsonCreator(mode = JsonCreator.Mode.DISABLED)
            private constructor(
                private val country: JsonField<String>,
                private val additionalProperties: MutableMap<String, JsonValue>,
            ) {

                @JsonCreator
                private constructor(
                    @JsonProperty("country")
                    @ExcludeMissing
                    country: JsonField<String> = JsonMissing.of()
                ) : this(country, mutableMapOf())

                /**
                 * The ISO 3166-1 alpha-2 country code.
                 *
                 * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or
                 *   is unexpectedly missing or null (e.g. if the server responded with an
                 *   unexpected value).
                 */
                fun country(): String = country.getRequired("country")

                /**
                 * Returns the raw JSON value of [country].
                 *
                 * Unlike [country], this method doesn't throw if the JSON field has an unexpected
                 * type.
                 */
                @JsonProperty("country") @ExcludeMissing fun _country(): JsonField<String> = country

                @JsonAnySetter
                private fun putAdditionalProperty(key: String, value: JsonValue) {
                    additionalProperties.put(key, value)
                }

                @JsonAnyGetter
                @ExcludeMissing
                fun _additionalProperties(): Map<String, JsonValue> =
                    Collections.unmodifiableMap(additionalProperties)

                fun toBuilder() = Builder().from(this)

                companion object {

                    /**
                     * Returns a mutable builder for constructing an instance of [Blocked].
                     *
                     * The following fields are required:
                     * ```java
                     * .country()
                     * ```
                     */
                    @JvmStatic fun builder() = Builder()
                }

                /** A builder for [Blocked]. */
                class Builder internal constructor() {

                    private var country: JsonField<String>? = null
                    private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                    @JvmSynthetic
                    internal fun from(blocked: Blocked) = apply {
                        country = blocked.country
                        additionalProperties = blocked.additionalProperties.toMutableMap()
                    }

                    /** The ISO 3166-1 alpha-2 country code. */
                    fun country(country: String) = country(JsonField.of(country))

                    /**
                     * Sets [Builder.country] to an arbitrary JSON value.
                     *
                     * You should usually call [Builder.country] with a well-typed [String] value
                     * instead. This method is primarily for setting the field to an undocumented or
                     * not yet supported value.
                     */
                    fun country(country: JsonField<String>) = apply { this.country = country }

                    fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                        this.additionalProperties.clear()
                        putAllAdditionalProperties(additionalProperties)
                    }

                    fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                        additionalProperties.put(key, value)
                    }

                    fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                        apply {
                            this.additionalProperties.putAll(additionalProperties)
                        }

                    fun removeAdditionalProperty(key: String) = apply {
                        additionalProperties.remove(key)
                    }

                    fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                        keys.forEach(::removeAdditionalProperty)
                    }

                    /**
                     * Returns an immutable instance of [Blocked].
                     *
                     * Further updates to this [Builder] will not mutate the returned instance.
                     *
                     * The following fields are required:
                     * ```java
                     * .country()
                     * ```
                     *
                     * @throws IllegalStateException if any required field is unset.
                     */
                    fun build(): Blocked =
                        Blocked(
                            checkRequired("country", country),
                            additionalProperties.toMutableMap(),
                        )
                }

                private var validated: Boolean = false

                /**
                 * Validates that the types of all values in this object match their expected types
                 * recursively.
                 *
                 * This method is _not_ forwards compatible with new types from the API for existing
                 * fields.
                 *
                 * @throws IncreaseInvalidDataException if any value type in this object doesn't
                 *   match its expected type.
                 */
                fun validate(): Blocked = apply {
                    if (validated) {
                        return@apply
                    }

                    country()
                    validated = true
                }

                fun isValid(): Boolean =
                    try {
                        validate()
                        true
                    } catch (e: IncreaseInvalidDataException) {
                        false
                    }

                /**
                 * Returns a score indicating how many valid values are contained in this object
                 * recursively.
                 *
                 * Used for best match union deserialization.
                 */
                @JvmSynthetic
                internal fun validity(): Int = (if (country.asKnown().isPresent) 1 else 0)

                override fun equals(other: Any?): Boolean {
                    if (this === other) {
                        return true
                    }

                    return other is Blocked &&
                        country == other.country &&
                        additionalProperties == other.additionalProperties
                }

                private val hashCode: Int by lazy { Objects.hash(country, additionalProperties) }

                override fun hashCode(): Int = hashCode

                override fun toString() =
                    "Blocked{country=$country, additionalProperties=$additionalProperties}"
            }

            override fun equals(other: Any?): Boolean {
                if (this === other) {
                    return true
                }

                return other is MerchantCountry &&
                    allowed == other.allowed &&
                    blocked == other.blocked &&
                    additionalProperties == other.additionalProperties
            }

            private val hashCode: Int by lazy {
                Objects.hash(allowed, blocked, additionalProperties)
            }

            override fun hashCode(): Int = hashCode

            override fun toString() =
                "MerchantCountry{allowed=$allowed, blocked=$blocked, additionalProperties=$additionalProperties}"
        }

        /** Controls how many times this card can be used. */
        class Usage
        @JsonCreator(mode = JsonCreator.Mode.DISABLED)
        private constructor(
            private val category: JsonField<Category>,
            private val multiUse: JsonField<MultiUse>,
            private val singleUse: JsonField<SingleUse>,
            private val additionalProperties: MutableMap<String, JsonValue>,
        ) {

            @JsonCreator
            private constructor(
                @JsonProperty("category")
                @ExcludeMissing
                category: JsonField<Category> = JsonMissing.of(),
                @JsonProperty("multi_use")
                @ExcludeMissing
                multiUse: JsonField<MultiUse> = JsonMissing.of(),
                @JsonProperty("single_use")
                @ExcludeMissing
                singleUse: JsonField<SingleUse> = JsonMissing.of(),
            ) : this(category, multiUse, singleUse, mutableMapOf())

            /**
             * Whether the card is for a single use or multiple uses.
             *
             * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or is
             *   unexpectedly missing or null (e.g. if the server responded with an unexpected
             *   value).
             */
            fun category(): Category = category.getRequired("category")

            /**
             * Controls for multi-use cards. Required if and only if `category` is `multi_use`.
             *
             * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g.
             *   if the server responded with an unexpected value).
             */
            fun multiUse(): Optional<MultiUse> = multiUse.getOptional("multi_use")

            /**
             * Controls for single-use cards. Required if and only if `category` is `single_use`.
             *
             * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g.
             *   if the server responded with an unexpected value).
             */
            fun singleUse(): Optional<SingleUse> = singleUse.getOptional("single_use")

            /**
             * Returns the raw JSON value of [category].
             *
             * Unlike [category], this method doesn't throw if the JSON field has an unexpected
             * type.
             */
            @JsonProperty("category")
            @ExcludeMissing
            fun _category(): JsonField<Category> = category

            /**
             * Returns the raw JSON value of [multiUse].
             *
             * Unlike [multiUse], this method doesn't throw if the JSON field has an unexpected
             * type.
             */
            @JsonProperty("multi_use")
            @ExcludeMissing
            fun _multiUse(): JsonField<MultiUse> = multiUse

            /**
             * Returns the raw JSON value of [singleUse].
             *
             * Unlike [singleUse], this method doesn't throw if the JSON field has an unexpected
             * type.
             */
            @JsonProperty("single_use")
            @ExcludeMissing
            fun _singleUse(): JsonField<SingleUse> = singleUse

            @JsonAnySetter
            private fun putAdditionalProperty(key: String, value: JsonValue) {
                additionalProperties.put(key, value)
            }

            @JsonAnyGetter
            @ExcludeMissing
            fun _additionalProperties(): Map<String, JsonValue> =
                Collections.unmodifiableMap(additionalProperties)

            fun toBuilder() = Builder().from(this)

            companion object {

                /**
                 * Returns a mutable builder for constructing an instance of [Usage].
                 *
                 * The following fields are required:
                 * ```java
                 * .category()
                 * .multiUse()
                 * .singleUse()
                 * ```
                 */
                @JvmStatic fun builder() = Builder()
            }

            /** A builder for [Usage]. */
            class Builder internal constructor() {

                private var category: JsonField<Category>? = null
                private var multiUse: JsonField<MultiUse>? = null
                private var singleUse: JsonField<SingleUse>? = null
                private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                @JvmSynthetic
                internal fun from(usage: Usage) = apply {
                    category = usage.category
                    multiUse = usage.multiUse
                    singleUse = usage.singleUse
                    additionalProperties = usage.additionalProperties.toMutableMap()
                }

                /** Whether the card is for a single use or multiple uses. */
                fun category(category: Category) = category(JsonField.of(category))

                /**
                 * Sets [Builder.category] to an arbitrary JSON value.
                 *
                 * You should usually call [Builder.category] with a well-typed [Category] value
                 * instead. This method is primarily for setting the field to an undocumented or not
                 * yet supported value.
                 */
                fun category(category: JsonField<Category>) = apply { this.category = category }

                /**
                 * Controls for multi-use cards. Required if and only if `category` is `multi_use`.
                 */
                fun multiUse(multiUse: MultiUse?) = multiUse(JsonField.ofNullable(multiUse))

                /** Alias for calling [Builder.multiUse] with `multiUse.orElse(null)`. */
                fun multiUse(multiUse: Optional<MultiUse>) = multiUse(multiUse.getOrNull())

                /**
                 * Sets [Builder.multiUse] to an arbitrary JSON value.
                 *
                 * You should usually call [Builder.multiUse] with a well-typed [MultiUse] value
                 * instead. This method is primarily for setting the field to an undocumented or not
                 * yet supported value.
                 */
                fun multiUse(multiUse: JsonField<MultiUse>) = apply { this.multiUse = multiUse }

                /**
                 * Controls for single-use cards. Required if and only if `category` is
                 * `single_use`.
                 */
                fun singleUse(singleUse: SingleUse?) = singleUse(JsonField.ofNullable(singleUse))

                /** Alias for calling [Builder.singleUse] with `singleUse.orElse(null)`. */
                fun singleUse(singleUse: Optional<SingleUse>) = singleUse(singleUse.getOrNull())

                /**
                 * Sets [Builder.singleUse] to an arbitrary JSON value.
                 *
                 * You should usually call [Builder.singleUse] with a well-typed [SingleUse] value
                 * instead. This method is primarily for setting the field to an undocumented or not
                 * yet supported value.
                 */
                fun singleUse(singleUse: JsonField<SingleUse>) = apply {
                    this.singleUse = singleUse
                }

                fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                    this.additionalProperties.clear()
                    putAllAdditionalProperties(additionalProperties)
                }

                fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                    additionalProperties.put(key, value)
                }

                fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                    apply {
                        this.additionalProperties.putAll(additionalProperties)
                    }

                fun removeAdditionalProperty(key: String) = apply {
                    additionalProperties.remove(key)
                }

                fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                    keys.forEach(::removeAdditionalProperty)
                }

                /**
                 * Returns an immutable instance of [Usage].
                 *
                 * Further updates to this [Builder] will not mutate the returned instance.
                 *
                 * The following fields are required:
                 * ```java
                 * .category()
                 * .multiUse()
                 * .singleUse()
                 * ```
                 *
                 * @throws IllegalStateException if any required field is unset.
                 */
                fun build(): Usage =
                    Usage(
                        checkRequired("category", category),
                        checkRequired("multiUse", multiUse),
                        checkRequired("singleUse", singleUse),
                        additionalProperties.toMutableMap(),
                    )
            }

            private var validated: Boolean = false

            /**
             * Validates that the types of all values in this object match their expected types
             * recursively.
             *
             * This method is _not_ forwards compatible with new types from the API for existing
             * fields.
             *
             * @throws IncreaseInvalidDataException if any value type in this object doesn't match
             *   its expected type.
             */
            fun validate(): Usage = apply {
                if (validated) {
                    return@apply
                }

                category().validate()
                multiUse().ifPresent { it.validate() }
                singleUse().ifPresent { it.validate() }
                validated = true
            }

            fun isValid(): Boolean =
                try {
                    validate()
                    true
                } catch (e: IncreaseInvalidDataException) {
                    false
                }

            /**
             * Returns a score indicating how many valid values are contained in this object
             * recursively.
             *
             * Used for best match union deserialization.
             */
            @JvmSynthetic
            internal fun validity(): Int =
                (category.asKnown().getOrNull()?.validity() ?: 0) +
                    (multiUse.asKnown().getOrNull()?.validity() ?: 0) +
                    (singleUse.asKnown().getOrNull()?.validity() ?: 0)

            /** Whether the card is for a single use or multiple uses. */
            class Category @JsonCreator private constructor(private val value: JsonField<String>) :
                Enum {

                /**
                 * Returns this class instance's raw value.
                 *
                 * This is usually only useful if this instance was deserialized from data that
                 * doesn't match any known member, and you want to know that value. For example, if
                 * the SDK is on an older version than the API, then the API may respond with new
                 * members that the SDK is unaware of.
                 */
                @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value

                companion object {

                    /** The card can only be used for a single authorization. */
                    @JvmField val SINGLE_USE = of("single_use")

                    /** The card can be used for multiple authorizations. */
                    @JvmField val MULTI_USE = of("multi_use")

                    @JvmStatic fun of(value: String) = Category(JsonField.of(value))
                }

                /** An enum containing [Category]'s known values. */
                enum class Known {
                    /** The card can only be used for a single authorization. */
                    SINGLE_USE,
                    /** The card can be used for multiple authorizations. */
                    MULTI_USE,
                }

                /**
                 * An enum containing [Category]'s known values, as well as an [_UNKNOWN] member.
                 *
                 * An instance of [Category] can contain an unknown value in a couple of cases:
                 * - It was deserialized from data that doesn't match any known member. For example,
                 *   if the SDK is on an older version than the API, then the API may respond with
                 *   new members that the SDK is unaware of.
                 * - It was constructed with an arbitrary value using the [of] method.
                 */
                enum class Value {
                    /** The card can only be used for a single authorization. */
                    SINGLE_USE,
                    /** The card can be used for multiple authorizations. */
                    MULTI_USE,
                    /**
                     * An enum member indicating that [Category] was instantiated with an unknown
                     * value.
                     */
                    _UNKNOWN,
                }

                /**
                 * Returns an enum member corresponding to this class instance's value, or
                 * [Value._UNKNOWN] if the class was instantiated with an unknown value.
                 *
                 * Use the [known] method instead if you're certain the value is always known or if
                 * you want to throw for the unknown case.
                 */
                fun value(): Value =
                    when (this) {
                        SINGLE_USE -> Value.SINGLE_USE
                        MULTI_USE -> Value.MULTI_USE
                        else -> Value._UNKNOWN
                    }

                /**
                 * Returns an enum member corresponding to this class instance's value.
                 *
                 * Use the [value] method instead if you're uncertain the value is always known and
                 * don't want to throw for the unknown case.
                 *
                 * @throws IncreaseInvalidDataException if this class instance's value is a not a
                 *   known member.
                 */
                fun known(): Known =
                    when (this) {
                        SINGLE_USE -> Known.SINGLE_USE
                        MULTI_USE -> Known.MULTI_USE
                        else -> throw IncreaseInvalidDataException("Unknown Category: $value")
                    }

                /**
                 * Returns this class instance's primitive wire representation.
                 *
                 * This differs from the [toString] method because that method is primarily for
                 * debugging and generally doesn't throw.
                 *
                 * @throws IncreaseInvalidDataException if this class instance's value does not have
                 *   the expected primitive type.
                 */
                fun asString(): String =
                    _value().asString().orElseThrow {
                        IncreaseInvalidDataException("Value is not a String")
                    }

                private var validated: Boolean = false

                /**
                 * Validates that the types of all values in this object match their expected types
                 * recursively.
                 *
                 * This method is _not_ forwards compatible with new types from the API for existing
                 * fields.
                 *
                 * @throws IncreaseInvalidDataException if any value type in this object doesn't
                 *   match its expected type.
                 */
                fun validate(): Category = apply {
                    if (validated) {
                        return@apply
                    }

                    known()
                    validated = true
                }

                fun isValid(): Boolean =
                    try {
                        validate()
                        true
                    } catch (e: IncreaseInvalidDataException) {
                        false
                    }

                /**
                 * Returns a score indicating how many valid values are contained in this object
                 * recursively.
                 *
                 * Used for best match union deserialization.
                 */
                @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1

                override fun equals(other: Any?): Boolean {
                    if (this === other) {
                        return true
                    }

                    return other is Category && value == other.value
                }

                override fun hashCode() = value.hashCode()

                override fun toString() = value.toString()
            }

            /** Controls for multi-use cards. Required if and only if `category` is `multi_use`. */
            class MultiUse
            @JsonCreator(mode = JsonCreator.Mode.DISABLED)
            private constructor(
                private val spendingLimits: JsonField<List<SpendingLimit>>,
                private val additionalProperties: MutableMap<String, JsonValue>,
            ) {

                @JsonCreator
                private constructor(
                    @JsonProperty("spending_limits")
                    @ExcludeMissing
                    spendingLimits: JsonField<List<SpendingLimit>> = JsonMissing.of()
                ) : this(spendingLimits, mutableMapOf())

                /**
                 * Spending limits for this card. The most restrictive limit applies if multiple
                 * limits match.
                 *
                 * @throws IncreaseInvalidDataException if the JSON field has an unexpected type
                 *   (e.g. if the server responded with an unexpected value).
                 */
                fun spendingLimits(): Optional<List<SpendingLimit>> =
                    spendingLimits.getOptional("spending_limits")

                /**
                 * Returns the raw JSON value of [spendingLimits].
                 *
                 * Unlike [spendingLimits], this method doesn't throw if the JSON field has an
                 * unexpected type.
                 */
                @JsonProperty("spending_limits")
                @ExcludeMissing
                fun _spendingLimits(): JsonField<List<SpendingLimit>> = spendingLimits

                @JsonAnySetter
                private fun putAdditionalProperty(key: String, value: JsonValue) {
                    additionalProperties.put(key, value)
                }

                @JsonAnyGetter
                @ExcludeMissing
                fun _additionalProperties(): Map<String, JsonValue> =
                    Collections.unmodifiableMap(additionalProperties)

                fun toBuilder() = Builder().from(this)

                companion object {

                    /**
                     * Returns a mutable builder for constructing an instance of [MultiUse].
                     *
                     * The following fields are required:
                     * ```java
                     * .spendingLimits()
                     * ```
                     */
                    @JvmStatic fun builder() = Builder()
                }

                /** A builder for [MultiUse]. */
                class Builder internal constructor() {

                    private var spendingLimits: JsonField<MutableList<SpendingLimit>>? = null
                    private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                    @JvmSynthetic
                    internal fun from(multiUse: MultiUse) = apply {
                        spendingLimits = multiUse.spendingLimits.map { it.toMutableList() }
                        additionalProperties = multiUse.additionalProperties.toMutableMap()
                    }

                    /**
                     * Spending limits for this card. The most restrictive limit applies if multiple
                     * limits match.
                     */
                    fun spendingLimits(spendingLimits: List<SpendingLimit>?) =
                        spendingLimits(JsonField.ofNullable(spendingLimits))

                    /**
                     * Alias for calling [Builder.spendingLimits] with
                     * `spendingLimits.orElse(null)`.
                     */
                    fun spendingLimits(spendingLimits: Optional<List<SpendingLimit>>) =
                        spendingLimits(spendingLimits.getOrNull())

                    /**
                     * Sets [Builder.spendingLimits] to an arbitrary JSON value.
                     *
                     * You should usually call [Builder.spendingLimits] with a well-typed
                     * `List<SpendingLimit>` value instead. This method is primarily for setting the
                     * field to an undocumented or not yet supported value.
                     */
                    fun spendingLimits(spendingLimits: JsonField<List<SpendingLimit>>) = apply {
                        this.spendingLimits = spendingLimits.map { it.toMutableList() }
                    }

                    /**
                     * Adds a single [SpendingLimit] to [spendingLimits].
                     *
                     * @throws IllegalStateException if the field was previously set to a non-list.
                     */
                    fun addSpendingLimit(spendingLimit: SpendingLimit) = apply {
                        spendingLimits =
                            (spendingLimits ?: JsonField.of(mutableListOf())).also {
                                checkKnown("spendingLimits", it).add(spendingLimit)
                            }
                    }

                    fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                        this.additionalProperties.clear()
                        putAllAdditionalProperties(additionalProperties)
                    }

                    fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                        additionalProperties.put(key, value)
                    }

                    fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                        apply {
                            this.additionalProperties.putAll(additionalProperties)
                        }

                    fun removeAdditionalProperty(key: String) = apply {
                        additionalProperties.remove(key)
                    }

                    fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                        keys.forEach(::removeAdditionalProperty)
                    }

                    /**
                     * Returns an immutable instance of [MultiUse].
                     *
                     * Further updates to this [Builder] will not mutate the returned instance.
                     *
                     * The following fields are required:
                     * ```java
                     * .spendingLimits()
                     * ```
                     *
                     * @throws IllegalStateException if any required field is unset.
                     */
                    fun build(): MultiUse =
                        MultiUse(
                            checkRequired("spendingLimits", spendingLimits).map {
                                it.toImmutable()
                            },
                            additionalProperties.toMutableMap(),
                        )
                }

                private var validated: Boolean = false

                /**
                 * Validates that the types of all values in this object match their expected types
                 * recursively.
                 *
                 * This method is _not_ forwards compatible with new types from the API for existing
                 * fields.
                 *
                 * @throws IncreaseInvalidDataException if any value type in this object doesn't
                 *   match its expected type.
                 */
                fun validate(): MultiUse = apply {
                    if (validated) {
                        return@apply
                    }

                    spendingLimits().ifPresent { it.forEach { it.validate() } }
                    validated = true
                }

                fun isValid(): Boolean =
                    try {
                        validate()
                        true
                    } catch (e: IncreaseInvalidDataException) {
                        false
                    }

                /**
                 * Returns a score indicating how many valid values are contained in this object
                 * recursively.
                 *
                 * Used for best match union deserialization.
                 */
                @JvmSynthetic
                internal fun validity(): Int =
                    (spendingLimits.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0)

                class SpendingLimit
                @JsonCreator(mode = JsonCreator.Mode.DISABLED)
                private constructor(
                    private val interval: JsonField<Interval>,
                    private val merchantCategoryCodes: JsonField<List<MerchantCategoryCode>>,
                    private val settlementAmount: JsonField<Long>,
                    private val additionalProperties: MutableMap<String, JsonValue>,
                ) {

                    @JsonCreator
                    private constructor(
                        @JsonProperty("interval")
                        @ExcludeMissing
                        interval: JsonField<Interval> = JsonMissing.of(),
                        @JsonProperty("merchant_category_codes")
                        @ExcludeMissing
                        merchantCategoryCodes: JsonField<List<MerchantCategoryCode>> =
                            JsonMissing.of(),
                        @JsonProperty("settlement_amount")
                        @ExcludeMissing
                        settlementAmount: JsonField<Long> = JsonMissing.of(),
                    ) : this(interval, merchantCategoryCodes, settlementAmount, mutableMapOf())

                    /**
                     * The interval at which the spending limit is enforced.
                     *
                     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type
                     *   or is unexpectedly missing or null (e.g. if the server responded with an
                     *   unexpected value).
                     */
                    fun interval(): Interval = interval.getRequired("interval")

                    /**
                     * The Merchant Category Codes (MCCs) this spending limit applies to. If not
                     * set, the limit applies to all transactions.
                     *
                     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type
                     *   (e.g. if the server responded with an unexpected value).
                     */
                    fun merchantCategoryCodes(): Optional<List<MerchantCategoryCode>> =
                        merchantCategoryCodes.getOptional("merchant_category_codes")

                    /**
                     * The maximum settlement amount permitted in the given interval.
                     *
                     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type
                     *   or is unexpectedly missing or null (e.g. if the server responded with an
                     *   unexpected value).
                     */
                    fun settlementAmount(): Long = settlementAmount.getRequired("settlement_amount")

                    /**
                     * Returns the raw JSON value of [interval].
                     *
                     * Unlike [interval], this method doesn't throw if the JSON field has an
                     * unexpected type.
                     */
                    @JsonProperty("interval")
                    @ExcludeMissing
                    fun _interval(): JsonField<Interval> = interval

                    /**
                     * Returns the raw JSON value of [merchantCategoryCodes].
                     *
                     * Unlike [merchantCategoryCodes], this method doesn't throw if the JSON field
                     * has an unexpected type.
                     */
                    @JsonProperty("merchant_category_codes")
                    @ExcludeMissing
                    fun _merchantCategoryCodes(): JsonField<List<MerchantCategoryCode>> =
                        merchantCategoryCodes

                    /**
                     * Returns the raw JSON value of [settlementAmount].
                     *
                     * Unlike [settlementAmount], this method doesn't throw if the JSON field has an
                     * unexpected type.
                     */
                    @JsonProperty("settlement_amount")
                    @ExcludeMissing
                    fun _settlementAmount(): JsonField<Long> = settlementAmount

                    @JsonAnySetter
                    private fun putAdditionalProperty(key: String, value: JsonValue) {
                        additionalProperties.put(key, value)
                    }

                    @JsonAnyGetter
                    @ExcludeMissing
                    fun _additionalProperties(): Map<String, JsonValue> =
                        Collections.unmodifiableMap(additionalProperties)

                    fun toBuilder() = Builder().from(this)

                    companion object {

                        /**
                         * Returns a mutable builder for constructing an instance of
                         * [SpendingLimit].
                         *
                         * The following fields are required:
                         * ```java
                         * .interval()
                         * .merchantCategoryCodes()
                         * .settlementAmount()
                         * ```
                         */
                        @JvmStatic fun builder() = Builder()
                    }

                    /** A builder for [SpendingLimit]. */
                    class Builder internal constructor() {

                        private var interval: JsonField<Interval>? = null
                        private var merchantCategoryCodes:
                            JsonField<MutableList<MerchantCategoryCode>>? =
                            null
                        private var settlementAmount: JsonField<Long>? = null
                        private var additionalProperties: MutableMap<String, JsonValue> =
                            mutableMapOf()

                        @JvmSynthetic
                        internal fun from(spendingLimit: SpendingLimit) = apply {
                            interval = spendingLimit.interval
                            merchantCategoryCodes =
                                spendingLimit.merchantCategoryCodes.map { it.toMutableList() }
                            settlementAmount = spendingLimit.settlementAmount
                            additionalProperties = spendingLimit.additionalProperties.toMutableMap()
                        }

                        /** The interval at which the spending limit is enforced. */
                        fun interval(interval: Interval) = interval(JsonField.of(interval))

                        /**
                         * Sets [Builder.interval] to an arbitrary JSON value.
                         *
                         * You should usually call [Builder.interval] with a well-typed [Interval]
                         * value instead. This method is primarily for setting the field to an
                         * undocumented or not yet supported value.
                         */
                        fun interval(interval: JsonField<Interval>) = apply {
                            this.interval = interval
                        }

                        /**
                         * The Merchant Category Codes (MCCs) this spending limit applies to. If not
                         * set, the limit applies to all transactions.
                         */
                        fun merchantCategoryCodes(
                            merchantCategoryCodes: List<MerchantCategoryCode>?
                        ) = merchantCategoryCodes(JsonField.ofNullable(merchantCategoryCodes))

                        /**
                         * Alias for calling [Builder.merchantCategoryCodes] with
                         * `merchantCategoryCodes.orElse(null)`.
                         */
                        fun merchantCategoryCodes(
                            merchantCategoryCodes: Optional<List<MerchantCategoryCode>>
                        ) = merchantCategoryCodes(merchantCategoryCodes.getOrNull())

                        /**
                         * Sets [Builder.merchantCategoryCodes] to an arbitrary JSON value.
                         *
                         * You should usually call [Builder.merchantCategoryCodes] with a well-typed
                         * `List<MerchantCategoryCode>` value instead. This method is primarily for
                         * setting the field to an undocumented or not yet supported value.
                         */
                        fun merchantCategoryCodes(
                            merchantCategoryCodes: JsonField<List<MerchantCategoryCode>>
                        ) = apply {
                            this.merchantCategoryCodes =
                                merchantCategoryCodes.map { it.toMutableList() }
                        }

                        /**
                         * Adds a single [MerchantCategoryCode] to [merchantCategoryCodes].
                         *
                         * @throws IllegalStateException if the field was previously set to a
                         *   non-list.
                         */
                        fun addMerchantCategoryCode(merchantCategoryCode: MerchantCategoryCode) =
                            apply {
                                merchantCategoryCodes =
                                    (merchantCategoryCodes ?: JsonField.of(mutableListOf())).also {
                                        checkKnown("merchantCategoryCodes", it)
                                            .add(merchantCategoryCode)
                                    }
                            }

                        /** The maximum settlement amount permitted in the given interval. */
                        fun settlementAmount(settlementAmount: Long) =
                            settlementAmount(JsonField.of(settlementAmount))

                        /**
                         * Sets [Builder.settlementAmount] to an arbitrary JSON value.
                         *
                         * You should usually call [Builder.settlementAmount] with a well-typed
                         * [Long] value instead. This method is primarily for setting the field to
                         * an undocumented or not yet supported value.
                         */
                        fun settlementAmount(settlementAmount: JsonField<Long>) = apply {
                            this.settlementAmount = settlementAmount
                        }

                        fun additionalProperties(additionalProperties: Map<String, JsonValue>) =
                            apply {
                                this.additionalProperties.clear()
                                putAllAdditionalProperties(additionalProperties)
                            }

                        fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                            additionalProperties.put(key, value)
                        }

                        fun putAllAdditionalProperties(
                            additionalProperties: Map<String, JsonValue>
                        ) = apply { this.additionalProperties.putAll(additionalProperties) }

                        fun removeAdditionalProperty(key: String) = apply {
                            additionalProperties.remove(key)
                        }

                        fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                            keys.forEach(::removeAdditionalProperty)
                        }

                        /**
                         * Returns an immutable instance of [SpendingLimit].
                         *
                         * Further updates to this [Builder] will not mutate the returned instance.
                         *
                         * The following fields are required:
                         * ```java
                         * .interval()
                         * .merchantCategoryCodes()
                         * .settlementAmount()
                         * ```
                         *
                         * @throws IllegalStateException if any required field is unset.
                         */
                        fun build(): SpendingLimit =
                            SpendingLimit(
                                checkRequired("interval", interval),
                                checkRequired("merchantCategoryCodes", merchantCategoryCodes).map {
                                    it.toImmutable()
                                },
                                checkRequired("settlementAmount", settlementAmount),
                                additionalProperties.toMutableMap(),
                            )
                    }

                    private var validated: Boolean = false

                    /**
                     * Validates that the types of all values in this object match their expected
                     * types recursively.
                     *
                     * This method is _not_ forwards compatible with new types from the API for
                     * existing fields.
                     *
                     * @throws IncreaseInvalidDataException if any value type in this object doesn't
                     *   match its expected type.
                     */
                    fun validate(): SpendingLimit = apply {
                        if (validated) {
                            return@apply
                        }

                        interval().validate()
                        merchantCategoryCodes().ifPresent { it.forEach { it.validate() } }
                        settlementAmount()
                        validated = true
                    }

                    fun isValid(): Boolean =
                        try {
                            validate()
                            true
                        } catch (e: IncreaseInvalidDataException) {
                            false
                        }

                    /**
                     * Returns a score indicating how many valid values are contained in this object
                     * recursively.
                     *
                     * Used for best match union deserialization.
                     */
                    @JvmSynthetic
                    internal fun validity(): Int =
                        (interval.asKnown().getOrNull()?.validity() ?: 0) +
                            (merchantCategoryCodes.asKnown().getOrNull()?.sumOf {
                                it.validity().toInt()
                            } ?: 0) +
                            (if (settlementAmount.asKnown().isPresent) 1 else 0)

                    /** The interval at which the spending limit is enforced. */
                    class Interval
                    @JsonCreator
                    private constructor(private val value: JsonField<String>) : Enum {

                        /**
                         * Returns this class instance's raw value.
                         *
                         * This is usually only useful if this instance was deserialized from data
                         * that doesn't match any known member, and you want to know that value. For
                         * example, if the SDK is on an older version than the API, then the API may
                         * respond with new members that the SDK is unaware of.
                         */
                        @com.fasterxml.jackson.annotation.JsonValue
                        fun _value(): JsonField<String> = value

                        companion object {

                            /** The spending limit applies over the lifetime of the card. */
                            @JvmField val ALL_TIME = of("all_time")

                            /** The spending limit applies per transaction. */
                            @JvmField val PER_TRANSACTION = of("per_transaction")

                            /**
                             * The spending limit applies per day. Resets nightly at midnight UTC.
                             */
                            @JvmField val PER_DAY = of("per_day")

                            /**
                             * The spending limit applies per week. Resets weekly on Mondays at
                             * midnight UTC.
                             */
                            @JvmField val PER_WEEK = of("per_week")

                            /**
                             * The spending limit applies per month. Resets on the first of the
                             * month, midnight UTC.
                             */
                            @JvmField val PER_MONTH = of("per_month")

                            @JvmStatic fun of(value: String) = Interval(JsonField.of(value))
                        }

                        /** An enum containing [Interval]'s known values. */
                        enum class Known {
                            /** The spending limit applies over the lifetime of the card. */
                            ALL_TIME,
                            /** The spending limit applies per transaction. */
                            PER_TRANSACTION,
                            /**
                             * The spending limit applies per day. Resets nightly at midnight UTC.
                             */
                            PER_DAY,
                            /**
                             * The spending limit applies per week. Resets weekly on Mondays at
                             * midnight UTC.
                             */
                            PER_WEEK,
                            /**
                             * The spending limit applies per month. Resets on the first of the
                             * month, midnight UTC.
                             */
                            PER_MONTH,
                        }

                        /**
                         * An enum containing [Interval]'s known values, as well as an [_UNKNOWN]
                         * member.
                         *
                         * An instance of [Interval] can contain an unknown value in a couple of
                         * cases:
                         * - It was deserialized from data that doesn't match any known member. For
                         *   example, if the SDK is on an older version than the API, then the API
                         *   may respond with new members that the SDK is unaware of.
                         * - It was constructed with an arbitrary value using the [of] method.
                         */
                        enum class Value {
                            /** The spending limit applies over the lifetime of the card. */
                            ALL_TIME,
                            /** The spending limit applies per transaction. */
                            PER_TRANSACTION,
                            /**
                             * The spending limit applies per day. Resets nightly at midnight UTC.
                             */
                            PER_DAY,
                            /**
                             * The spending limit applies per week. Resets weekly on Mondays at
                             * midnight UTC.
                             */
                            PER_WEEK,
                            /**
                             * The spending limit applies per month. Resets on the first of the
                             * month, midnight UTC.
                             */
                            PER_MONTH,
                            /**
                             * An enum member indicating that [Interval] was instantiated with an
                             * unknown value.
                             */
                            _UNKNOWN,
                        }

                        /**
                         * Returns an enum member corresponding to this class instance's value, or
                         * [Value._UNKNOWN] if the class was instantiated with an unknown value.
                         *
                         * Use the [known] method instead if you're certain the value is always
                         * known or if you want to throw for the unknown case.
                         */
                        fun value(): Value =
                            when (this) {
                                ALL_TIME -> Value.ALL_TIME
                                PER_TRANSACTION -> Value.PER_TRANSACTION
                                PER_DAY -> Value.PER_DAY
                                PER_WEEK -> Value.PER_WEEK
                                PER_MONTH -> Value.PER_MONTH
                                else -> Value._UNKNOWN
                            }

                        /**
                         * Returns an enum member corresponding to this class instance's value.
                         *
                         * Use the [value] method instead if you're uncertain the value is always
                         * known and don't want to throw for the unknown case.
                         *
                         * @throws IncreaseInvalidDataException if this class instance's value is a
                         *   not a known member.
                         */
                        fun known(): Known =
                            when (this) {
                                ALL_TIME -> Known.ALL_TIME
                                PER_TRANSACTION -> Known.PER_TRANSACTION
                                PER_DAY -> Known.PER_DAY
                                PER_WEEK -> Known.PER_WEEK
                                PER_MONTH -> Known.PER_MONTH
                                else ->
                                    throw IncreaseInvalidDataException("Unknown Interval: $value")
                            }

                        /**
                         * Returns this class instance's primitive wire representation.
                         *
                         * This differs from the [toString] method because that method is primarily
                         * for debugging and generally doesn't throw.
                         *
                         * @throws IncreaseInvalidDataException if this class instance's value does
                         *   not have the expected primitive type.
                         */
                        fun asString(): String =
                            _value().asString().orElseThrow {
                                IncreaseInvalidDataException("Value is not a String")
                            }

                        private var validated: Boolean = false

                        /**
                         * Validates that the types of all values in this object match their
                         * expected types recursively.
                         *
                         * This method is _not_ forwards compatible with new types from the API for
                         * existing fields.
                         *
                         * @throws IncreaseInvalidDataException if any value type in this object
                         *   doesn't match its expected type.
                         */
                        fun validate(): Interval = apply {
                            if (validated) {
                                return@apply
                            }

                            known()
                            validated = true
                        }

                        fun isValid(): Boolean =
                            try {
                                validate()
                                true
                            } catch (e: IncreaseInvalidDataException) {
                                false
                            }

                        /**
                         * Returns a score indicating how many valid values are contained in this
                         * object recursively.
                         *
                         * Used for best match union deserialization.
                         */
                        @JvmSynthetic
                        internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1

                        override fun equals(other: Any?): Boolean {
                            if (this === other) {
                                return true
                            }

                            return other is Interval && value == other.value
                        }

                        override fun hashCode() = value.hashCode()

                        override fun toString() = value.toString()
                    }

                    class MerchantCategoryCode
                    @JsonCreator(mode = JsonCreator.Mode.DISABLED)
                    private constructor(
                        private val code: JsonField<String>,
                        private val additionalProperties: MutableMap<String, JsonValue>,
                    ) {

                        @JsonCreator
                        private constructor(
                            @JsonProperty("code")
                            @ExcludeMissing
                            code: JsonField<String> = JsonMissing.of()
                        ) : this(code, mutableMapOf())

                        /**
                         * The Merchant Category Code (MCC).
                         *
                         * @throws IncreaseInvalidDataException if the JSON field has an unexpected
                         *   type or is unexpectedly missing or null (e.g. if the server responded
                         *   with an unexpected value).
                         */
                        fun code(): String = code.getRequired("code")

                        /**
                         * Returns the raw JSON value of [code].
                         *
                         * Unlike [code], this method doesn't throw if the JSON field has an
                         * unexpected type.
                         */
                        @JsonProperty("code") @ExcludeMissing fun _code(): JsonField<String> = code

                        @JsonAnySetter
                        private fun putAdditionalProperty(key: String, value: JsonValue) {
                            additionalProperties.put(key, value)
                        }

                        @JsonAnyGetter
                        @ExcludeMissing
                        fun _additionalProperties(): Map<String, JsonValue> =
                            Collections.unmodifiableMap(additionalProperties)

                        fun toBuilder() = Builder().from(this)

                        companion object {

                            /**
                             * Returns a mutable builder for constructing an instance of
                             * [MerchantCategoryCode].
                             *
                             * The following fields are required:
                             * ```java
                             * .code()
                             * ```
                             */
                            @JvmStatic fun builder() = Builder()
                        }

                        /** A builder for [MerchantCategoryCode]. */
                        class Builder internal constructor() {

                            private var code: JsonField<String>? = null
                            private var additionalProperties: MutableMap<String, JsonValue> =
                                mutableMapOf()

                            @JvmSynthetic
                            internal fun from(merchantCategoryCode: MerchantCategoryCode) = apply {
                                code = merchantCategoryCode.code
                                additionalProperties =
                                    merchantCategoryCode.additionalProperties.toMutableMap()
                            }

                            /** The Merchant Category Code (MCC). */
                            fun code(code: String) = code(JsonField.of(code))

                            /**
                             * Sets [Builder.code] to an arbitrary JSON value.
                             *
                             * You should usually call [Builder.code] with a well-typed [String]
                             * value instead. This method is primarily for setting the field to an
                             * undocumented or not yet supported value.
                             */
                            fun code(code: JsonField<String>) = apply { this.code = code }

                            fun additionalProperties(additionalProperties: Map<String, JsonValue>) =
                                apply {
                                    this.additionalProperties.clear()
                                    putAllAdditionalProperties(additionalProperties)
                                }

                            fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                                additionalProperties.put(key, value)
                            }

                            fun putAllAdditionalProperties(
                                additionalProperties: Map<String, JsonValue>
                            ) = apply { this.additionalProperties.putAll(additionalProperties) }

                            fun removeAdditionalProperty(key: String) = apply {
                                additionalProperties.remove(key)
                            }

                            fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                                keys.forEach(::removeAdditionalProperty)
                            }

                            /**
                             * Returns an immutable instance of [MerchantCategoryCode].
                             *
                             * Further updates to this [Builder] will not mutate the returned
                             * instance.
                             *
                             * The following fields are required:
                             * ```java
                             * .code()
                             * ```
                             *
                             * @throws IllegalStateException if any required field is unset.
                             */
                            fun build(): MerchantCategoryCode =
                                MerchantCategoryCode(
                                    checkRequired("code", code),
                                    additionalProperties.toMutableMap(),
                                )
                        }

                        private var validated: Boolean = false

                        /**
                         * Validates that the types of all values in this object match their
                         * expected types recursively.
                         *
                         * This method is _not_ forwards compatible with new types from the API for
                         * existing fields.
                         *
                         * @throws IncreaseInvalidDataException if any value type in this object
                         *   doesn't match its expected type.
                         */
                        fun validate(): MerchantCategoryCode = apply {
                            if (validated) {
                                return@apply
                            }

                            code()
                            validated = true
                        }

                        fun isValid(): Boolean =
                            try {
                                validate()
                                true
                            } catch (e: IncreaseInvalidDataException) {
                                false
                            }

                        /**
                         * Returns a score indicating how many valid values are contained in this
                         * object recursively.
                         *
                         * Used for best match union deserialization.
                         */
                        @JvmSynthetic
                        internal fun validity(): Int = (if (code.asKnown().isPresent) 1 else 0)

                        override fun equals(other: Any?): Boolean {
                            if (this === other) {
                                return true
                            }

                            return other is MerchantCategoryCode &&
                                code == other.code &&
                                additionalProperties == other.additionalProperties
                        }

                        private val hashCode: Int by lazy {
                            Objects.hash(code, additionalProperties)
                        }

                        override fun hashCode(): Int = hashCode

                        override fun toString() =
                            "MerchantCategoryCode{code=$code, additionalProperties=$additionalProperties}"
                    }

                    override fun equals(other: Any?): Boolean {
                        if (this === other) {
                            return true
                        }

                        return other is SpendingLimit &&
                            interval == other.interval &&
                            merchantCategoryCodes == other.merchantCategoryCodes &&
                            settlementAmount == other.settlementAmount &&
                            additionalProperties == other.additionalProperties
                    }

                    private val hashCode: Int by lazy {
                        Objects.hash(
                            interval,
                            merchantCategoryCodes,
                            settlementAmount,
                            additionalProperties,
                        )
                    }

                    override fun hashCode(): Int = hashCode

                    override fun toString() =
                        "SpendingLimit{interval=$interval, merchantCategoryCodes=$merchantCategoryCodes, settlementAmount=$settlementAmount, additionalProperties=$additionalProperties}"
                }

                override fun equals(other: Any?): Boolean {
                    if (this === other) {
                        return true
                    }

                    return other is MultiUse &&
                        spendingLimits == other.spendingLimits &&
                        additionalProperties == other.additionalProperties
                }

                private val hashCode: Int by lazy {
                    Objects.hash(spendingLimits, additionalProperties)
                }

                override fun hashCode(): Int = hashCode

                override fun toString() =
                    "MultiUse{spendingLimits=$spendingLimits, additionalProperties=$additionalProperties}"
            }

            /**
             * Controls for single-use cards. Required if and only if `category` is `single_use`.
             */
            class SingleUse
            @JsonCreator(mode = JsonCreator.Mode.DISABLED)
            private constructor(
                private val settlementAmount: JsonField<SettlementAmount>,
                private val additionalProperties: MutableMap<String, JsonValue>,
            ) {

                @JsonCreator
                private constructor(
                    @JsonProperty("settlement_amount")
                    @ExcludeMissing
                    settlementAmount: JsonField<SettlementAmount> = JsonMissing.of()
                ) : this(settlementAmount, mutableMapOf())

                /**
                 * The settlement amount constraint for this single-use card.
                 *
                 * @throws IncreaseInvalidDataException if the JSON field has an unexpected type or
                 *   is unexpectedly missing or null (e.g. if the server responded with an
                 *   unexpected value).
                 */
                fun settlementAmount(): SettlementAmount =
                    settlementAmount.getRequired("settlement_amount")

                /**
                 * Returns the raw JSON value of [settlementAmount].
                 *
                 * Unlike [settlementAmount], this method doesn't throw if the JSON field has an
                 * unexpected type.
                 */
                @JsonProperty("settlement_amount")
                @ExcludeMissing
                fun _settlementAmount(): JsonField<SettlementAmount> = settlementAmount

                @JsonAnySetter
                private fun putAdditionalProperty(key: String, value: JsonValue) {
                    additionalProperties.put(key, value)
                }

                @JsonAnyGetter
                @ExcludeMissing
                fun _additionalProperties(): Map<String, JsonValue> =
                    Collections.unmodifiableMap(additionalProperties)

                fun toBuilder() = Builder().from(this)

                companion object {

                    /**
                     * Returns a mutable builder for constructing an instance of [SingleUse].
                     *
                     * The following fields are required:
                     * ```java
                     * .settlementAmount()
                     * ```
                     */
                    @JvmStatic fun builder() = Builder()
                }

                /** A builder for [SingleUse]. */
                class Builder internal constructor() {

                    private var settlementAmount: JsonField<SettlementAmount>? = null
                    private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

                    @JvmSynthetic
                    internal fun from(singleUse: SingleUse) = apply {
                        settlementAmount = singleUse.settlementAmount
                        additionalProperties = singleUse.additionalProperties.toMutableMap()
                    }

                    /** The settlement amount constraint for this single-use card. */
                    fun settlementAmount(settlementAmount: SettlementAmount) =
                        settlementAmount(JsonField.of(settlementAmount))

                    /**
                     * Sets [Builder.settlementAmount] to an arbitrary JSON value.
                     *
                     * You should usually call [Builder.settlementAmount] with a well-typed
                     * [SettlementAmount] value instead. This method is primarily for setting the
                     * field to an undocumented or not yet supported value.
                     */
                    fun settlementAmount(settlementAmount: JsonField<SettlementAmount>) = apply {
                        this.settlementAmount = settlementAmount
                    }

                    fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                        this.additionalProperties.clear()
                        putAllAdditionalProperties(additionalProperties)
                    }

                    fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                        additionalProperties.put(key, value)
                    }

                    fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) =
                        apply {
                            this.additionalProperties.putAll(additionalProperties)
                        }

                    fun removeAdditionalProperty(key: String) = apply {
                        additionalProperties.remove(key)
                    }

                    fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                        keys.forEach(::removeAdditionalProperty)
                    }

                    /**
                     * Returns an immutable instance of [SingleUse].
                     *
                     * Further updates to this [Builder] will not mutate the returned instance.
                     *
                     * The following fields are required:
                     * ```java
                     * .settlementAmount()
                     * ```
                     *
                     * @throws IllegalStateException if any required field is unset.
                     */
                    fun build(): SingleUse =
                        SingleUse(
                            checkRequired("settlementAmount", settlementAmount),
                            additionalProperties.toMutableMap(),
                        )
                }

                private var validated: Boolean = false

                /**
                 * Validates that the types of all values in this object match their expected types
                 * recursively.
                 *
                 * This method is _not_ forwards compatible with new types from the API for existing
                 * fields.
                 *
                 * @throws IncreaseInvalidDataException if any value type in this object doesn't
                 *   match its expected type.
                 */
                fun validate(): SingleUse = apply {
                    if (validated) {
                        return@apply
                    }

                    settlementAmount().validate()
                    validated = true
                }

                fun isValid(): Boolean =
                    try {
                        validate()
                        true
                    } catch (e: IncreaseInvalidDataException) {
                        false
                    }

                /**
                 * Returns a score indicating how many valid values are contained in this object
                 * recursively.
                 *
                 * Used for best match union deserialization.
                 */
                @JvmSynthetic
                internal fun validity(): Int =
                    (settlementAmount.asKnown().getOrNull()?.validity() ?: 0)

                /** The settlement amount constraint for this single-use card. */
                class SettlementAmount
                @JsonCreator(mode = JsonCreator.Mode.DISABLED)
                private constructor(
                    private val comparison: JsonField<Comparison>,
                    private val value: JsonField<Long>,
                    private val additionalProperties: MutableMap<String, JsonValue>,
                ) {

                    @JsonCreator
                    private constructor(
                        @JsonProperty("comparison")
                        @ExcludeMissing
                        comparison: JsonField<Comparison> = JsonMissing.of(),
                        @JsonProperty("value")
                        @ExcludeMissing
                        value: JsonField<Long> = JsonMissing.of(),
                    ) : this(comparison, value, mutableMapOf())

                    /**
                     * The operator used to compare the settlement amount.
                     *
                     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type
                     *   or is unexpectedly missing or null (e.g. if the server responded with an
                     *   unexpected value).
                     */
                    fun comparison(): Comparison = comparison.getRequired("comparison")

                    /**
                     * The settlement amount value.
                     *
                     * @throws IncreaseInvalidDataException if the JSON field has an unexpected type
                     *   or is unexpectedly missing or null (e.g. if the server responded with an
                     *   unexpected value).
                     */
                    fun value(): Long = value.getRequired("value")

                    /**
                     * Returns the raw JSON value of [comparison].
                     *
                     * Unlike [comparison], this method doesn't throw if the JSON field has an
                     * unexpected type.
                     */
                    @JsonProperty("comparison")
                    @ExcludeMissing
                    fun _comparison(): JsonField<Comparison> = comparison

                    /**
                     * Returns the raw JSON value of [value].
                     *
                     * Unlike [value], this method doesn't throw if the JSON field has an unexpected
                     * type.
                     */
                    @JsonProperty("value") @ExcludeMissing fun _value(): JsonField<Long> = value

                    @JsonAnySetter
                    private fun putAdditionalProperty(key: String, value: JsonValue) {
                        additionalProperties.put(key, value)
                    }

                    @JsonAnyGetter
                    @ExcludeMissing
                    fun _additionalProperties(): Map<String, JsonValue> =
                        Collections.unmodifiableMap(additionalProperties)

                    fun toBuilder() = Builder().from(this)

                    companion object {

                        /**
                         * Returns a mutable builder for constructing an instance of
                         * [SettlementAmount].
                         *
                         * The following fields are required:
                         * ```java
                         * .comparison()
                         * .value()
                         * ```
                         */
                        @JvmStatic fun builder() = Builder()
                    }

                    /** A builder for [SettlementAmount]. */
                    class Builder internal constructor() {

                        private var comparison: JsonField<Comparison>? = null
                        private var value: JsonField<Long>? = null
                        private var additionalProperties: MutableMap<String, JsonValue> =
                            mutableMapOf()

                        @JvmSynthetic
                        internal fun from(settlementAmount: SettlementAmount) = apply {
                            comparison = settlementAmount.comparison
                            value = settlementAmount.value
                            additionalProperties =
                                settlementAmount.additionalProperties.toMutableMap()
                        }

                        /** The operator used to compare the settlement amount. */
                        fun comparison(comparison: Comparison) =
                            comparison(JsonField.of(comparison))

                        /**
                         * Sets [Builder.comparison] to an arbitrary JSON value.
                         *
                         * You should usually call [Builder.comparison] with a well-typed
                         * [Comparison] value instead. This method is primarily for setting the
                         * field to an undocumented or not yet supported value.
                         */
                        fun comparison(comparison: JsonField<Comparison>) = apply {
                            this.comparison = comparison
                        }

                        /** The settlement amount value. */
                        fun value(value: Long) = value(JsonField.of(value))

                        /**
                         * Sets [Builder.value] to an arbitrary JSON value.
                         *
                         * You should usually call [Builder.value] with a well-typed [Long] value
                         * instead. This method is primarily for setting the field to an
                         * undocumented or not yet supported value.
                         */
                        fun value(value: JsonField<Long>) = apply { this.value = value }

                        fun additionalProperties(additionalProperties: Map<String, JsonValue>) =
                            apply {
                                this.additionalProperties.clear()
                                putAllAdditionalProperties(additionalProperties)
                            }

                        fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                            additionalProperties.put(key, value)
                        }

                        fun putAllAdditionalProperties(
                            additionalProperties: Map<String, JsonValue>
                        ) = apply { this.additionalProperties.putAll(additionalProperties) }

                        fun removeAdditionalProperty(key: String) = apply {
                            additionalProperties.remove(key)
                        }

                        fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                            keys.forEach(::removeAdditionalProperty)
                        }

                        /**
                         * Returns an immutable instance of [SettlementAmount].
                         *
                         * Further updates to this [Builder] will not mutate the returned instance.
                         *
                         * The following fields are required:
                         * ```java
                         * .comparison()
                         * .value()
                         * ```
                         *
                         * @throws IllegalStateException if any required field is unset.
                         */
                        fun build(): SettlementAmount =
                            SettlementAmount(
                                checkRequired("comparison", comparison),
                                checkRequired("value", value),
                                additionalProperties.toMutableMap(),
                            )
                    }

                    private var validated: Boolean = false

                    /**
                     * Validates that the types of all values in this object match their expected
                     * types recursively.
                     *
                     * This method is _not_ forwards compatible with new types from the API for
                     * existing fields.
                     *
                     * @throws IncreaseInvalidDataException if any value type in this object doesn't
                     *   match its expected type.
                     */
                    fun validate(): SettlementAmount = apply {
                        if (validated) {
                            return@apply
                        }

                        comparison().validate()
                        value()
                        validated = true
                    }

                    fun isValid(): Boolean =
                        try {
                            validate()
                            true
                        } catch (e: IncreaseInvalidDataException) {
                            false
                        }

                    /**
                     * Returns a score indicating how many valid values are contained in this object
                     * recursively.
                     *
                     * Used for best match union deserialization.
                     */
                    @JvmSynthetic
                    internal fun validity(): Int =
                        (comparison.asKnown().getOrNull()?.validity() ?: 0) +
                            (if (value.asKnown().isPresent) 1 else 0)

                    /** The operator used to compare the settlement amount. */
                    class Comparison
                    @JsonCreator
                    private constructor(private val value: JsonField<String>) : Enum {

                        /**
                         * Returns this class instance's raw value.
                         *
                         * This is usually only useful if this instance was deserialized from data
                         * that doesn't match any known member, and you want to know that value. For
                         * example, if the SDK is on an older version than the API, then the API may
                         * respond with new members that the SDK is unaware of.
                         */
                        @com.fasterxml.jackson.annotation.JsonValue
                        fun _value(): JsonField<String> = value

                        companion object {

                            /** The settlement amount must be exactly the specified value. */
                            @JvmField val EQUALS = of("equals")

                            /**
                             * The settlement amount must be less than or equal to the specified
                             * value.
                             */
                            @JvmField val LESS_THAN_OR_EQUALS = of("less_than_or_equals")

                            @JvmStatic fun of(value: String) = Comparison(JsonField.of(value))
                        }

                        /** An enum containing [Comparison]'s known values. */
                        enum class Known {
                            /** The settlement amount must be exactly the specified value. */
                            EQUALS,
                            /**
                             * The settlement amount must be less than or equal to the specified
                             * value.
                             */
                            LESS_THAN_OR_EQUALS,
                        }

                        /**
                         * An enum containing [Comparison]'s known values, as well as an [_UNKNOWN]
                         * member.
                         *
                         * An instance of [Comparison] can contain an unknown value in a couple of
                         * cases:
                         * - It was deserialized from data that doesn't match any known member. For
                         *   example, if the SDK is on an older version than the API, then the API
                         *   may respond with new members that the SDK is unaware of.
                         * - It was constructed with an arbitrary value using the [of] method.
                         */
                        enum class Value {
                            /** The settlement amount must be exactly the specified value. */
                            EQUALS,
                            /**
                             * The settlement amount must be less than or equal to the specified
                             * value.
                             */
                            LESS_THAN_OR_EQUALS,
                            /**
                             * An enum member indicating that [Comparison] was instantiated with an
                             * unknown value.
                             */
                            _UNKNOWN,
                        }

                        /**
                         * Returns an enum member corresponding to this class instance's value, or
                         * [Value._UNKNOWN] if the class was instantiated with an unknown value.
                         *
                         * Use the [known] method instead if you're certain the value is always
                         * known or if you want to throw for the unknown case.
                         */
                        fun value(): Value =
                            when (this) {
                                EQUALS -> Value.EQUALS
                                LESS_THAN_OR_EQUALS -> Value.LESS_THAN_OR_EQUALS
                                else -> Value._UNKNOWN
                            }

                        /**
                         * Returns an enum member corresponding to this class instance's value.
                         *
                         * Use the [value] method instead if you're uncertain the value is always
                         * known and don't want to throw for the unknown case.
                         *
                         * @throws IncreaseInvalidDataException if this class instance's value is a
                         *   not a known member.
                         */
                        fun known(): Known =
                            when (this) {
                                EQUALS -> Known.EQUALS
                                LESS_THAN_OR_EQUALS -> Known.LESS_THAN_OR_EQUALS
                                else ->
                                    throw IncreaseInvalidDataException("Unknown Comparison: $value")
                            }

                        /**
                         * Returns this class instance's primitive wire representation.
                         *
                         * This differs from the [toString] method because that method is primarily
                         * for debugging and generally doesn't throw.
                         *
                         * @throws IncreaseInvalidDataException if this class instance's value does
                         *   not have the expected primitive type.
                         */
                        fun asString(): String =
                            _value().asString().orElseThrow {
                                IncreaseInvalidDataException("Value is not a String")
                            }

                        private var validated: Boolean = false

                        /**
                         * Validates that the types of all values in this object match their
                         * expected types recursively.
                         *
                         * This method is _not_ forwards compatible with new types from the API for
                         * existing fields.
                         *
                         * @throws IncreaseInvalidDataException if any value type in this object
                         *   doesn't match its expected type.
                         */
                        fun validate(): Comparison = apply {
                            if (validated) {
                                return@apply
                            }

                            known()
                            validated = true
                        }

                        fun isValid(): Boolean =
                            try {
                                validate()
                                true
                            } catch (e: IncreaseInvalidDataException) {
                                false
                            }

                        /**
                         * Returns a score indicating how many valid values are contained in this
                         * object recursively.
                         *
                         * Used for best match union deserialization.
                         */
                        @JvmSynthetic
                        internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1

                        override fun equals(other: Any?): Boolean {
                            if (this === other) {
                                return true
                            }

                            return other is Comparison && value == other.value
                        }

                        override fun hashCode() = value.hashCode()

                        override fun toString() = value.toString()
                    }

                    override fun equals(other: Any?): Boolean {
                        if (this === other) {
                            return true
                        }

                        return other is SettlementAmount &&
                            comparison == other.comparison &&
                            value == other.value &&
                            additionalProperties == other.additionalProperties
                    }

                    private val hashCode: Int by lazy {
                        Objects.hash(comparison, value, additionalProperties)
                    }

                    override fun hashCode(): Int = hashCode

                    override fun toString() =
                        "SettlementAmount{comparison=$comparison, value=$value, additionalProperties=$additionalProperties}"
                }

                override fun equals(other: Any?): Boolean {
                    if (this === other) {
                        return true
                    }

                    return other is SingleUse &&
                        settlementAmount == other.settlementAmount &&
                        additionalProperties == other.additionalProperties
                }

                private val hashCode: Int by lazy {
                    Objects.hash(settlementAmount, additionalProperties)
                }

                override fun hashCode(): Int = hashCode

                override fun toString() =
                    "SingleUse{settlementAmount=$settlementAmount, additionalProperties=$additionalProperties}"
            }

            override fun equals(other: Any?): Boolean {
                if (this === other) {
                    return true
                }

                return other is Usage &&
                    category == other.category &&
                    multiUse == other.multiUse &&
                    singleUse == other.singleUse &&
                    additionalProperties == other.additionalProperties
            }

            private val hashCode: Int by lazy {
                Objects.hash(category, multiUse, singleUse, additionalProperties)
            }

            override fun hashCode(): Int = hashCode

            override fun toString() =
                "Usage{category=$category, multiUse=$multiUse, singleUse=$singleUse, additionalProperties=$additionalProperties}"
        }

        override fun equals(other: Any?): Boolean {
            if (this === other) {
                return true
            }

            return other is AuthorizationControls &&
                merchantAcceptorIdentifier == other.merchantAcceptorIdentifier &&
                merchantCategoryCode == other.merchantCategoryCode &&
                merchantCountry == other.merchantCountry &&
                usage == other.usage &&
                additionalProperties == other.additionalProperties
        }

        private val hashCode: Int by lazy {
            Objects.hash(
                merchantAcceptorIdentifier,
                merchantCategoryCode,
                merchantCountry,
                usage,
                additionalProperties,
            )
        }

        override fun hashCode(): Int = hashCode

        override fun toString() =
            "AuthorizationControls{merchantAcceptorIdentifier=$merchantAcceptorIdentifier, merchantCategoryCode=$merchantCategoryCode, merchantCountry=$merchantCountry, usage=$usage, additionalProperties=$additionalProperties}"
    }

    /** The Card's billing address. */
    class BillingAddress
    @JsonCreator(mode = JsonCreator.Mode.DISABLED)
    private constructor(
        private val city: JsonField<String>,
        private val line1: JsonField<String>,
        private val line2: JsonField<String>,
        private val postalCode: JsonField<String>,
        private val state: JsonField<String>,
        private val additionalProperties: MutableMap<String, JsonValue>,
    ) {

        @JsonCreator
        private constructor(
            @JsonProperty("city") @ExcludeMissing city: JsonField<String> = JsonMissing.of(),
            @JsonProperty("line1") @ExcludeMissing line1: JsonField<String> = JsonMissing.of(),
            @JsonProperty("line2") @ExcludeMissing line2: JsonField<String> = JsonMissing.of(),
            @JsonProperty("postal_code")
            @ExcludeMissing
            postalCode: JsonField<String> = JsonMissing.of(),
            @JsonProperty("state") @ExcludeMissing state: JsonField<String> = JsonMissing.of(),
        ) : this(city, line1, line2, postalCode, state, mutableMapOf())

        /**
         * The city of the billing address.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun city(): Optional<String> = city.getOptional("city")

        /**
         * The first line of the billing address.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun line1(): Optional<String> = line1.getOptional("line1")

        /**
         * The second line of the billing address.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun line2(): Optional<String> = line2.getOptional("line2")

        /**
         * The postal code of the billing address.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun postalCode(): Optional<String> = postalCode.getOptional("postal_code")

        /**
         * The US state of the billing address.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun state(): Optional<String> = state.getOptional("state")

        /**
         * Returns the raw JSON value of [city].
         *
         * Unlike [city], this method doesn't throw if the JSON field has an unexpected type.
         */
        @JsonProperty("city") @ExcludeMissing fun _city(): JsonField<String> = city

        /**
         * Returns the raw JSON value of [line1].
         *
         * Unlike [line1], this method doesn't throw if the JSON field has an unexpected type.
         */
        @JsonProperty("line1") @ExcludeMissing fun _line1(): JsonField<String> = line1

        /**
         * Returns the raw JSON value of [line2].
         *
         * Unlike [line2], this method doesn't throw if the JSON field has an unexpected type.
         */
        @JsonProperty("line2") @ExcludeMissing fun _line2(): JsonField<String> = line2

        /**
         * Returns the raw JSON value of [postalCode].
         *
         * Unlike [postalCode], this method doesn't throw if the JSON field has an unexpected type.
         */
        @JsonProperty("postal_code")
        @ExcludeMissing
        fun _postalCode(): JsonField<String> = postalCode

        /**
         * Returns the raw JSON value of [state].
         *
         * Unlike [state], this method doesn't throw if the JSON field has an unexpected type.
         */
        @JsonProperty("state") @ExcludeMissing fun _state(): JsonField<String> = state

        @JsonAnySetter
        private fun putAdditionalProperty(key: String, value: JsonValue) {
            additionalProperties.put(key, value)
        }

        @JsonAnyGetter
        @ExcludeMissing
        fun _additionalProperties(): Map<String, JsonValue> =
            Collections.unmodifiableMap(additionalProperties)

        fun toBuilder() = Builder().from(this)

        companion object {

            /**
             * Returns a mutable builder for constructing an instance of [BillingAddress].
             *
             * The following fields are required:
             * ```java
             * .city()
             * .line1()
             * .line2()
             * .postalCode()
             * .state()
             * ```
             */
            @JvmStatic fun builder() = Builder()
        }

        /** A builder for [BillingAddress]. */
        class Builder internal constructor() {

            private var city: JsonField<String>? = null
            private var line1: JsonField<String>? = null
            private var line2: JsonField<String>? = null
            private var postalCode: JsonField<String>? = null
            private var state: JsonField<String>? = null
            private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

            @JvmSynthetic
            internal fun from(billingAddress: BillingAddress) = apply {
                city = billingAddress.city
                line1 = billingAddress.line1
                line2 = billingAddress.line2
                postalCode = billingAddress.postalCode
                state = billingAddress.state
                additionalProperties = billingAddress.additionalProperties.toMutableMap()
            }

            /** The city of the billing address. */
            fun city(city: String?) = city(JsonField.ofNullable(city))

            /** Alias for calling [Builder.city] with `city.orElse(null)`. */
            fun city(city: Optional<String>) = city(city.getOrNull())

            /**
             * Sets [Builder.city] to an arbitrary JSON value.
             *
             * You should usually call [Builder.city] with a well-typed [String] value instead. This
             * method is primarily for setting the field to an undocumented or not yet supported
             * value.
             */
            fun city(city: JsonField<String>) = apply { this.city = city }

            /** The first line of the billing address. */
            fun line1(line1: String?) = line1(JsonField.ofNullable(line1))

            /** Alias for calling [Builder.line1] with `line1.orElse(null)`. */
            fun line1(line1: Optional<String>) = line1(line1.getOrNull())

            /**
             * Sets [Builder.line1] to an arbitrary JSON value.
             *
             * You should usually call [Builder.line1] with a well-typed [String] value instead.
             * This method is primarily for setting the field to an undocumented or not yet
             * supported value.
             */
            fun line1(line1: JsonField<String>) = apply { this.line1 = line1 }

            /** The second line of the billing address. */
            fun line2(line2: String?) = line2(JsonField.ofNullable(line2))

            /** Alias for calling [Builder.line2] with `line2.orElse(null)`. */
            fun line2(line2: Optional<String>) = line2(line2.getOrNull())

            /**
             * Sets [Builder.line2] to an arbitrary JSON value.
             *
             * You should usually call [Builder.line2] with a well-typed [String] value instead.
             * This method is primarily for setting the field to an undocumented or not yet
             * supported value.
             */
            fun line2(line2: JsonField<String>) = apply { this.line2 = line2 }

            /** The postal code of the billing address. */
            fun postalCode(postalCode: String?) = postalCode(JsonField.ofNullable(postalCode))

            /** Alias for calling [Builder.postalCode] with `postalCode.orElse(null)`. */
            fun postalCode(postalCode: Optional<String>) = postalCode(postalCode.getOrNull())

            /**
             * Sets [Builder.postalCode] to an arbitrary JSON value.
             *
             * You should usually call [Builder.postalCode] with a well-typed [String] value
             * instead. This method is primarily for setting the field to an undocumented or not yet
             * supported value.
             */
            fun postalCode(postalCode: JsonField<String>) = apply { this.postalCode = postalCode }

            /** The US state of the billing address. */
            fun state(state: String?) = state(JsonField.ofNullable(state))

            /** Alias for calling [Builder.state] with `state.orElse(null)`. */
            fun state(state: Optional<String>) = state(state.getOrNull())

            /**
             * Sets [Builder.state] to an arbitrary JSON value.
             *
             * You should usually call [Builder.state] with a well-typed [String] value instead.
             * This method is primarily for setting the field to an undocumented or not yet
             * supported value.
             */
            fun state(state: JsonField<String>) = apply { this.state = state }

            fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                this.additionalProperties.clear()
                putAllAdditionalProperties(additionalProperties)
            }

            fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                additionalProperties.put(key, value)
            }

            fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                this.additionalProperties.putAll(additionalProperties)
            }

            fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }

            fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                keys.forEach(::removeAdditionalProperty)
            }

            /**
             * Returns an immutable instance of [BillingAddress].
             *
             * Further updates to this [Builder] will not mutate the returned instance.
             *
             * The following fields are required:
             * ```java
             * .city()
             * .line1()
             * .line2()
             * .postalCode()
             * .state()
             * ```
             *
             * @throws IllegalStateException if any required field is unset.
             */
            fun build(): BillingAddress =
                BillingAddress(
                    checkRequired("city", city),
                    checkRequired("line1", line1),
                    checkRequired("line2", line2),
                    checkRequired("postalCode", postalCode),
                    checkRequired("state", state),
                    additionalProperties.toMutableMap(),
                )
        }

        private var validated: Boolean = false

        /**
         * Validates that the types of all values in this object match their expected types
         * recursively.
         *
         * This method is _not_ forwards compatible with new types from the API for existing fields.
         *
         * @throws IncreaseInvalidDataException if any value type in this object doesn't match its
         *   expected type.
         */
        fun validate(): BillingAddress = apply {
            if (validated) {
                return@apply
            }

            city()
            line1()
            line2()
            postalCode()
            state()
            validated = true
        }

        fun isValid(): Boolean =
            try {
                validate()
                true
            } catch (e: IncreaseInvalidDataException) {
                false
            }

        /**
         * Returns a score indicating how many valid values are contained in this object
         * recursively.
         *
         * Used for best match union deserialization.
         */
        @JvmSynthetic
        internal fun validity(): Int =
            (if (city.asKnown().isPresent) 1 else 0) +
                (if (line1.asKnown().isPresent) 1 else 0) +
                (if (line2.asKnown().isPresent) 1 else 0) +
                (if (postalCode.asKnown().isPresent) 1 else 0) +
                (if (state.asKnown().isPresent) 1 else 0)

        override fun equals(other: Any?): Boolean {
            if (this === other) {
                return true
            }

            return other is BillingAddress &&
                city == other.city &&
                line1 == other.line1 &&
                line2 == other.line2 &&
                postalCode == other.postalCode &&
                state == other.state &&
                additionalProperties == other.additionalProperties
        }

        private val hashCode: Int by lazy {
            Objects.hash(city, line1, line2, postalCode, state, additionalProperties)
        }

        override fun hashCode(): Int = hashCode

        override fun toString() =
            "BillingAddress{city=$city, line1=$line1, line2=$line2, postalCode=$postalCode, state=$state, additionalProperties=$additionalProperties}"
    }

    /**
     * The contact information used in the two-factor steps for digital wallet card creation. At
     * least one field must be present to complete the digital wallet steps.
     */
    class DigitalWallet
    @JsonCreator(mode = JsonCreator.Mode.DISABLED)
    private constructor(
        private val digitalCardProfileId: JsonField<String>,
        private val email: JsonField<String>,
        private val phone: JsonField<String>,
        private val additionalProperties: MutableMap<String, JsonValue>,
    ) {

        @JsonCreator
        private constructor(
            @JsonProperty("digital_card_profile_id")
            @ExcludeMissing
            digitalCardProfileId: JsonField<String> = JsonMissing.of(),
            @JsonProperty("email") @ExcludeMissing email: JsonField<String> = JsonMissing.of(),
            @JsonProperty("phone") @ExcludeMissing phone: JsonField<String> = JsonMissing.of(),
        ) : this(digitalCardProfileId, email, phone, mutableMapOf())

        /**
         * The digital card profile assigned to this digital card. Card profiles may also be
         * assigned at the program level.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun digitalCardProfileId(): Optional<String> =
            digitalCardProfileId.getOptional("digital_card_profile_id")

        /**
         * An email address that can be used to verify the cardholder via one-time passcode over
         * email.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun email(): Optional<String> = email.getOptional("email")

        /**
         * A phone number that can be used to verify the cardholder via one-time passcode over SMS.
         *
         * @throws IncreaseInvalidDataException if the JSON field has an unexpected type (e.g. if
         *   the server responded with an unexpected value).
         */
        fun phone(): Optional<String> = phone.getOptional("phone")

        /**
         * Returns the raw JSON value of [digitalCardProfileId].
         *
         * Unlike [digitalCardProfileId], this method doesn't throw if the JSON field has an
         * unexpected type.
         */
        @JsonProperty("digital_card_profile_id")
        @ExcludeMissing
        fun _digitalCardProfileId(): JsonField<String> = digitalCardProfileId

        /**
         * Returns the raw JSON value of [email].
         *
         * Unlike [email], this method doesn't throw if the JSON field has an unexpected type.
         */
        @JsonProperty("email") @ExcludeMissing fun _email(): JsonField<String> = email

        /**
         * Returns the raw JSON value of [phone].
         *
         * Unlike [phone], this method doesn't throw if the JSON field has an unexpected type.
         */
        @JsonProperty("phone") @ExcludeMissing fun _phone(): JsonField<String> = phone

        @JsonAnySetter
        private fun putAdditionalProperty(key: String, value: JsonValue) {
            additionalProperties.put(key, value)
        }

        @JsonAnyGetter
        @ExcludeMissing
        fun _additionalProperties(): Map<String, JsonValue> =
            Collections.unmodifiableMap(additionalProperties)

        fun toBuilder() = Builder().from(this)

        companion object {

            /**
             * Returns a mutable builder for constructing an instance of [DigitalWallet].
             *
             * The following fields are required:
             * ```java
             * .digitalCardProfileId()
             * .email()
             * .phone()
             * ```
             */
            @JvmStatic fun builder() = Builder()
        }

        /** A builder for [DigitalWallet]. */
        class Builder internal constructor() {

            private var digitalCardProfileId: JsonField<String>? = null
            private var email: JsonField<String>? = null
            private var phone: JsonField<String>? = null
            private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

            @JvmSynthetic
            internal fun from(digitalWallet: DigitalWallet) = apply {
                digitalCardProfileId = digitalWallet.digitalCardProfileId
                email = digitalWallet.email
                phone = digitalWallet.phone
                additionalProperties = digitalWallet.additionalProperties.toMutableMap()
            }

            /**
             * The digital card profile assigned to this digital card. Card profiles may also be
             * assigned at the program level.
             */
            fun digitalCardProfileId(digitalCardProfileId: String?) =
                digitalCardProfileId(JsonField.ofNullable(digitalCardProfileId))

            /**
             * Alias for calling [Builder.digitalCardProfileId] with
             * `digitalCardProfileId.orElse(null)`.
             */
            fun digitalCardProfileId(digitalCardProfileId: Optional<String>) =
                digitalCardProfileId(digitalCardProfileId.getOrNull())

            /**
             * Sets [Builder.digitalCardProfileId] to an arbitrary JSON value.
             *
             * You should usually call [Builder.digitalCardProfileId] with a well-typed [String]
             * value instead. This method is primarily for setting the field to an undocumented or
             * not yet supported value.
             */
            fun digitalCardProfileId(digitalCardProfileId: JsonField<String>) = apply {
                this.digitalCardProfileId = digitalCardProfileId
            }

            /**
             * An email address that can be used to verify the cardholder via one-time passcode over
             * email.
             */
            fun email(email: String?) = email(JsonField.ofNullable(email))

            /** Alias for calling [Builder.email] with `email.orElse(null)`. */
            fun email(email: Optional<String>) = email(email.getOrNull())

            /**
             * Sets [Builder.email] to an arbitrary JSON value.
             *
             * You should usually call [Builder.email] with a well-typed [String] value instead.
             * This method is primarily for setting the field to an undocumented or not yet
             * supported value.
             */
            fun email(email: JsonField<String>) = apply { this.email = email }

            /**
             * A phone number that can be used to verify the cardholder via one-time passcode over
             * SMS.
             */
            fun phone(phone: String?) = phone(JsonField.ofNullable(phone))

            /** Alias for calling [Builder.phone] with `phone.orElse(null)`. */
            fun phone(phone: Optional<String>) = phone(phone.getOrNull())

            /**
             * Sets [Builder.phone] to an arbitrary JSON value.
             *
             * You should usually call [Builder.phone] with a well-typed [String] value instead.
             * This method is primarily for setting the field to an undocumented or not yet
             * supported value.
             */
            fun phone(phone: JsonField<String>) = apply { this.phone = phone }

            fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                this.additionalProperties.clear()
                putAllAdditionalProperties(additionalProperties)
            }

            fun putAdditionalProperty(key: String, value: JsonValue) = apply {
                additionalProperties.put(key, value)
            }

            fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
                this.additionalProperties.putAll(additionalProperties)
            }

            fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }

            fun removeAllAdditionalProperties(keys: Set<String>) = apply {
                keys.forEach(::removeAdditionalProperty)
            }

            /**
             * Returns an immutable instance of [DigitalWallet].
             *
             * Further updates to this [Builder] will not mutate the returned instance.
             *
             * The following fields are required:
             * ```java
             * .digitalCardProfileId()
             * .email()
             * .phone()
             * ```
             *
             * @throws IllegalStateException if any required field is unset.
             */
            fun build(): DigitalWallet =
                DigitalWallet(
                    checkRequired("digitalCardProfileId", digitalCardProfileId),
                    checkRequired("email", email),
                    checkRequired("phone", phone),
                    additionalProperties.toMutableMap(),
                )
        }

        private var validated: Boolean = false

        /**
         * Validates that the types of all values in this object match their expected types
         * recursively.
         *
         * This method is _not_ forwards compatible with new types from the API for existing fields.
         *
         * @throws IncreaseInvalidDataException if any value type in this object doesn't match its
         *   expected type.
         */
        fun validate(): DigitalWallet = apply {
            if (validated) {
                return@apply
            }

            digitalCardProfileId()
            email()
            phone()
            validated = true
        }

        fun isValid(): Boolean =
            try {
                validate()
                true
            } catch (e: IncreaseInvalidDataException) {
                false
            }

        /**
         * Returns a score indicating how many valid values are contained in this object
         * recursively.
         *
         * Used for best match union deserialization.
         */
        @JvmSynthetic
        internal fun validity(): Int =
            (if (digitalCardProfileId.asKnown().isPresent) 1 else 0) +
                (if (email.asKnown().isPresent) 1 else 0) +
                (if (phone.asKnown().isPresent) 1 else 0)

        override fun equals(other: Any?): Boolean {
            if (this === other) {
                return true
            }

            return other is DigitalWallet &&
                digitalCardProfileId == other.digitalCardProfileId &&
                email == other.email &&
                phone == other.phone &&
                additionalProperties == other.additionalProperties
        }

        private val hashCode: Int by lazy {
            Objects.hash(digitalCardProfileId, email, phone, additionalProperties)
        }

        override fun hashCode(): Int = hashCode

        override fun toString() =
            "DigitalWallet{digitalCardProfileId=$digitalCardProfileId, email=$email, phone=$phone, additionalProperties=$additionalProperties}"
    }

    /** This indicates if payments can be made with the card. */
    class Status @JsonCreator private constructor(private val value: JsonField<String>) : Enum {

        /**
         * Returns this class instance's raw value.
         *
         * This is usually only useful if this instance was deserialized from data that doesn't
         * match any known member, and you want to know that value. For example, if the SDK is on an
         * older version than the API, then the API may respond with new members that the SDK is
         * unaware of.
         */
        @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value

        companion object {

            /** The card is active. */
            @JvmField val ACTIVE = of("active")

            /** The card is temporarily disabled. */
            @JvmField val DISABLED = of("disabled")

            /** The card is permanently canceled. */
            @JvmField val CANCELED = of("canceled")

            @JvmStatic fun of(value: String) = Status(JsonField.of(value))
        }

        /** An enum containing [Status]'s known values. */
        enum class Known {
            /** The card is active. */
            ACTIVE,
            /** The card is temporarily disabled. */
            DISABLED,
            /** The card is permanently canceled. */
            CANCELED,
        }

        /**
         * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member.
         *
         * An instance of [Status] can contain an unknown value in a couple of cases:
         * - It was deserialized from data that doesn't match any known member. For example, if the
         *   SDK is on an older version than the API, then the API may respond with new members that
         *   the SDK is unaware of.
         * - It was constructed with an arbitrary value using the [of] method.
         */
        enum class Value {
            /** The card is active. */
            ACTIVE,
            /** The card is temporarily disabled. */
            DISABLED,
            /** The card is permanently canceled. */
            CANCELED,
            /** An enum member indicating that [Status] was instantiated with an unknown value. */
            _UNKNOWN,
        }

        /**
         * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
         * if the class was instantiated with an unknown value.
         *
         * Use the [known] method instead if you're certain the value is always known or if you want
         * to throw for the unknown case.
         */
        fun value(): Value =
            when (this) {
                ACTIVE -> Value.ACTIVE
                DISABLED -> Value.DISABLED
                CANCELED -> Value.CANCELED
                else -> Value._UNKNOWN
            }

        /**
         * Returns an enum member corresponding to this class instance's value.
         *
         * Use the [value] method instead if you're uncertain the value is always known and don't
         * want to throw for the unknown case.
         *
         * @throws IncreaseInvalidDataException if this class instance's value is a not a known
         *   member.
         */
        fun known(): Known =
            when (this) {
                ACTIVE -> Known.ACTIVE
                DISABLED -> Known.DISABLED
                CANCELED -> Known.CANCELED
                else -> throw IncreaseInvalidDataException("Unknown Status: $value")
            }

        /**
         * Returns this class instance's primitive wire representation.
         *
         * This differs from the [toString] method because that method is primarily for debugging
         * and generally doesn't throw.
         *
         * @throws IncreaseInvalidDataException if this class instance's value does not have the
         *   expected primitive type.
         */
        fun asString(): String =
            _value().asString().orElseThrow {
                IncreaseInvalidDataException("Value is not a String")
            }

        private var validated: Boolean = false

        /**
         * Validates that the types of all values in this object match their expected types
         * recursively.
         *
         * This method is _not_ forwards compatible with new types from the API for existing fields.
         *
         * @throws IncreaseInvalidDataException if any value type in this object doesn't match its
         *   expected type.
         */
        fun validate(): Status = apply {
            if (validated) {
                return@apply
            }

            known()
            validated = true
        }

        fun isValid(): Boolean =
            try {
                validate()
                true
            } catch (e: IncreaseInvalidDataException) {
                false
            }

        /**
         * Returns a score indicating how many valid values are contained in this object
         * recursively.
         *
         * Used for best match union deserialization.
         */
        @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1

        override fun equals(other: Any?): Boolean {
            if (this === other) {
                return true
            }

            return other is Status && value == other.value
        }

        override fun hashCode() = value.hashCode()

        override fun toString() = value.toString()
    }

    /** A constant representing the object's type. For this resource it will always be `card`. */
    class Type @JsonCreator private constructor(private val value: JsonField<String>) : Enum {

        /**
         * Returns this class instance's raw value.
         *
         * This is usually only useful if this instance was deserialized from data that doesn't
         * match any known member, and you want to know that value. For example, if the SDK is on an
         * older version than the API, then the API may respond with new members that the SDK is
         * unaware of.
         */
        @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value

        companion object {

            @JvmField val CARD = of("card")

            @JvmStatic fun of(value: String) = Type(JsonField.of(value))
        }

        /** An enum containing [Type]'s known values. */
        enum class Known {
            CARD
        }

        /**
         * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member.
         *
         * An instance of [Type] can contain an unknown value in a couple of cases:
         * - It was deserialized from data that doesn't match any known member. For example, if the
         *   SDK is on an older version than the API, then the API may respond with new members that
         *   the SDK is unaware of.
         * - It was constructed with an arbitrary value using the [of] method.
         */
        enum class Value {
            CARD,
            /** An enum member indicating that [Type] was instantiated with an unknown value. */
            _UNKNOWN,
        }

        /**
         * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
         * if the class was instantiated with an unknown value.
         *
         * Use the [known] method instead if you're certain the value is always known or if you want
         * to throw for the unknown case.
         */
        fun value(): Value =
            when (this) {
                CARD -> Value.CARD
                else -> Value._UNKNOWN
            }

        /**
         * Returns an enum member corresponding to this class instance's value.
         *
         * Use the [value] method instead if you're uncertain the value is always known and don't
         * want to throw for the unknown case.
         *
         * @throws IncreaseInvalidDataException if this class instance's value is a not a known
         *   member.
         */
        fun known(): Known =
            when (this) {
                CARD -> Known.CARD
                else -> throw IncreaseInvalidDataException("Unknown Type: $value")
            }

        /**
         * Returns this class instance's primitive wire representation.
         *
         * This differs from the [toString] method because that method is primarily for debugging
         * and generally doesn't throw.
         *
         * @throws IncreaseInvalidDataException if this class instance's value does not have the
         *   expected primitive type.
         */
        fun asString(): String =
            _value().asString().orElseThrow {
                IncreaseInvalidDataException("Value is not a String")
            }

        private var validated: Boolean = false

        /**
         * Validates that the types of all values in this object match their expected types
         * recursively.
         *
         * This method is _not_ forwards compatible with new types from the API for existing fields.
         *
         * @throws IncreaseInvalidDataException if any value type in this object doesn't match its
         *   expected type.
         */
        fun validate(): Type = apply {
            if (validated) {
                return@apply
            }

            known()
            validated = true
        }

        fun isValid(): Boolean =
            try {
                validate()
                true
            } catch (e: IncreaseInvalidDataException) {
                false
            }

        /**
         * Returns a score indicating how many valid values are contained in this object
         * recursively.
         *
         * Used for best match union deserialization.
         */
        @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1

        override fun equals(other: Any?): Boolean {
            if (this === other) {
                return true
            }

            return other is Type && value == other.value
        }

        override fun hashCode() = value.hashCode()

        override fun toString() = value.toString()
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) {
            return true
        }

        return other is Card &&
            id == other.id &&
            accountId == other.accountId &&
            authorizationControls == other.authorizationControls &&
            billingAddress == other.billingAddress &&
            bin == other.bin &&
            createdAt == other.createdAt &&
            description == other.description &&
            digitalWallet == other.digitalWallet &&
            entityId == other.entityId &&
            expirationMonth == other.expirationMonth &&
            expirationYear == other.expirationYear &&
            idempotencyKey == other.idempotencyKey &&
            last4 == other.last4 &&
            status == other.status &&
            type == other.type &&
            additionalProperties == other.additionalProperties
    }

    private val hashCode: Int by lazy {
        Objects.hash(
            id,
            accountId,
            authorizationControls,
            billingAddress,
            bin,
            createdAt,
            description,
            digitalWallet,
            entityId,
            expirationMonth,
            expirationYear,
            idempotencyKey,
            last4,
            status,
            type,
            additionalProperties,
        )
    }

    override fun hashCode(): Int = hashCode

    override fun toString() =
        "Card{id=$id, accountId=$accountId, authorizationControls=$authorizationControls, billingAddress=$billingAddress, bin=$bin, createdAt=$createdAt, description=$description, digitalWallet=$digitalWallet, entityId=$entityId, expirationMonth=$expirationMonth, expirationYear=$expirationYear, idempotencyKey=$idempotencyKey, last4=$last4, status=$status, type=$type, additionalProperties=$additionalProperties}"
}
