All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lithic.api.models.VelocityLimitParams.kt Maven / Gradle / Ivy

Go to download

The Lithic Developer API is designed to provide a predictable programmatic interface for accessing your Lithic account through an API and transaction webhooks. Note that your API key is a secret and should be treated as such. Don't share it with anyone, including us. We will never ask you for it.

There is a newer version: 0.61.0
Show newest version
// File generated from our OpenAPI spec by Stainless.

package com.lithic.api.models

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.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.ObjectCodec
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.lithic.api.core.BaseDeserializer
import com.lithic.api.core.BaseSerializer
import com.lithic.api.core.Enum
import com.lithic.api.core.ExcludeMissing
import com.lithic.api.core.JsonField
import com.lithic.api.core.JsonMissing
import com.lithic.api.core.JsonValue
import com.lithic.api.core.NoAutoDetect
import com.lithic.api.core.getOrThrow
import com.lithic.api.core.toUnmodifiable
import com.lithic.api.errors.LithicInvalidDataException
import java.util.Objects
import java.util.Optional

@JsonDeserialize(builder = VelocityLimitParams.Builder::class)
@NoAutoDetect
class VelocityLimitParams
private constructor(
    private val scope: JsonField,
    private val period: JsonField,
    private val filters: JsonField,
    private val limitAmount: JsonField,
    private val limitCount: JsonField,
    private val additionalProperties: Map,
) {

    private var validated: Boolean = false

    fun scope(): Scope = scope.getRequired("scope")

    fun period(): Period = period.getRequired("period")

    fun filters(): Filters = filters.getRequired("filters")

    /**
     * The maximum amount of spend velocity allowed in the period in minor units (the smallest unit
     * of a currency, e.g. cents for USD). Transactions exceeding this limit will be declined.
     */
    fun limitAmount(): Optional =
        Optional.ofNullable(limitAmount.getNullable("limit_amount"))

    /**
     * The number of spend velocity impacting transactions may not exceed this limit in the period.
     * Transactions exceeding this limit will be declined. A spend velocity impacting transaction is
     * a transaction that has been authorized, and optionally settled, or a force post (a
     * transaction that settled without prior authorization).
     */
    fun limitCount(): Optional = Optional.ofNullable(limitCount.getNullable("limit_count"))

    @JsonProperty("scope") @ExcludeMissing fun _scope() = scope

    @JsonProperty("period") @ExcludeMissing fun _period() = period

    @JsonProperty("filters") @ExcludeMissing fun _filters() = filters

    /**
     * The maximum amount of spend velocity allowed in the period in minor units (the smallest unit
     * of a currency, e.g. cents for USD). Transactions exceeding this limit will be declined.
     */
    @JsonProperty("limit_amount") @ExcludeMissing fun _limitAmount() = limitAmount

    /**
     * The number of spend velocity impacting transactions may not exceed this limit in the period.
     * Transactions exceeding this limit will be declined. A spend velocity impacting transaction is
     * a transaction that has been authorized, and optionally settled, or a force post (a
     * transaction that settled without prior authorization).
     */
    @JsonProperty("limit_count") @ExcludeMissing fun _limitCount() = limitCount

    @JsonAnyGetter
    @ExcludeMissing
    fun _additionalProperties(): Map = additionalProperties

    fun validate(): VelocityLimitParams = apply {
        if (!validated) {
            scope()
            period()
            filters().validate()
            limitAmount()
            limitCount()
            validated = true
        }
    }

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

    companion object {

        @JvmStatic fun builder() = Builder()
    }

    class Builder {

        private var scope: JsonField = JsonMissing.of()
        private var period: JsonField = JsonMissing.of()
        private var filters: JsonField = JsonMissing.of()
        private var limitAmount: JsonField = JsonMissing.of()
        private var limitCount: JsonField = JsonMissing.of()
        private var additionalProperties: MutableMap = mutableMapOf()

        @JvmSynthetic
        internal fun from(velocityLimitParams: VelocityLimitParams) = apply {
            this.scope = velocityLimitParams.scope
            this.period = velocityLimitParams.period
            this.filters = velocityLimitParams.filters
            this.limitAmount = velocityLimitParams.limitAmount
            this.limitCount = velocityLimitParams.limitCount
            additionalProperties(velocityLimitParams.additionalProperties)
        }

        fun scope(scope: Scope) = scope(JsonField.of(scope))

        @JsonProperty("scope")
        @ExcludeMissing
        fun scope(scope: JsonField) = apply { this.scope = scope }

        fun period(period: Period) = period(JsonField.of(period))

        @JsonProperty("period")
        @ExcludeMissing
        fun period(period: JsonField) = apply { this.period = period }

        fun filters(filters: Filters) = filters(JsonField.of(filters))

        @JsonProperty("filters")
        @ExcludeMissing
        fun filters(filters: JsonField) = apply { this.filters = filters }

        /**
         * The maximum amount of spend velocity allowed in the period in minor units (the smallest
         * unit of a currency, e.g. cents for USD). Transactions exceeding this limit will be
         * declined.
         */
        fun limitAmount(limitAmount: Double) = limitAmount(JsonField.of(limitAmount))

        /**
         * The maximum amount of spend velocity allowed in the period in minor units (the smallest
         * unit of a currency, e.g. cents for USD). Transactions exceeding this limit will be
         * declined.
         */
        @JsonProperty("limit_amount")
        @ExcludeMissing
        fun limitAmount(limitAmount: JsonField) = apply { this.limitAmount = limitAmount }

        /**
         * The number of spend velocity impacting transactions may not exceed this limit in the
         * period. Transactions exceeding this limit will be declined. A spend velocity impacting
         * transaction is a transaction that has been authorized, and optionally settled, or a force
         * post (a transaction that settled without prior authorization).
         */
        fun limitCount(limitCount: Double) = limitCount(JsonField.of(limitCount))

        /**
         * The number of spend velocity impacting transactions may not exceed this limit in the
         * period. Transactions exceeding this limit will be declined. A spend velocity impacting
         * transaction is a transaction that has been authorized, and optionally settled, or a force
         * post (a transaction that settled without prior authorization).
         */
        @JsonProperty("limit_count")
        @ExcludeMissing
        fun limitCount(limitCount: JsonField) = apply { this.limitCount = limitCount }

        fun additionalProperties(additionalProperties: Map) = apply {
            this.additionalProperties.clear()
            this.additionalProperties.putAll(additionalProperties)
        }

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

        fun putAllAdditionalProperties(additionalProperties: Map) = apply {
            this.additionalProperties.putAll(additionalProperties)
        }

        fun build(): VelocityLimitParams =
            VelocityLimitParams(
                scope,
                period,
                filters,
                limitAmount,
                limitCount,
                additionalProperties.toUnmodifiable(),
            )
    }

    @JsonDeserialize(builder = Filters.Builder::class)
    @NoAutoDetect
    class Filters
    private constructor(
        private val includeMccs: JsonField>,
        private val includeCountries: JsonField>,
        private val additionalProperties: Map,
    ) {

        private var validated: Boolean = false

        /**
         * Merchant Category Codes to include in the velocity calculation. Transactions not matching
         * this MCC will not be included in the calculated velocity.
         */
        fun includeMccs(): Optional> =
            Optional.ofNullable(includeMccs.getNullable("include_mccs"))

        /**
         * ISO-3166-1 alpha-3 Country Codes to include in the velocity calculation. Transactions not
         * matching any of the provided will not be included in the calculated velocity.
         */
        fun includeCountries(): Optional> =
            Optional.ofNullable(includeCountries.getNullable("include_countries"))

        /**
         * Merchant Category Codes to include in the velocity calculation. Transactions not matching
         * this MCC will not be included in the calculated velocity.
         */
        @JsonProperty("include_mccs") @ExcludeMissing fun _includeMccs() = includeMccs

        /**
         * ISO-3166-1 alpha-3 Country Codes to include in the velocity calculation. Transactions not
         * matching any of the provided will not be included in the calculated velocity.
         */
        @JsonProperty("include_countries")
        @ExcludeMissing
        fun _includeCountries() = includeCountries

        @JsonAnyGetter
        @ExcludeMissing
        fun _additionalProperties(): Map = additionalProperties

        fun validate(): Filters = apply {
            if (!validated) {
                includeMccs()
                includeCountries()
                validated = true
            }
        }

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

        companion object {

            @JvmStatic fun builder() = Builder()
        }

        class Builder {

            private var includeMccs: JsonField> = JsonMissing.of()
            private var includeCountries: JsonField> = JsonMissing.of()
            private var additionalProperties: MutableMap = mutableMapOf()

            @JvmSynthetic
            internal fun from(filters: Filters) = apply {
                this.includeMccs = filters.includeMccs
                this.includeCountries = filters.includeCountries
                additionalProperties(filters.additionalProperties)
            }

            /**
             * Merchant Category Codes to include in the velocity calculation. Transactions not
             * matching this MCC will not be included in the calculated velocity.
             */
            fun includeMccs(includeMccs: List) = includeMccs(JsonField.of(includeMccs))

            /**
             * Merchant Category Codes to include in the velocity calculation. Transactions not
             * matching this MCC will not be included in the calculated velocity.
             */
            @JsonProperty("include_mccs")
            @ExcludeMissing
            fun includeMccs(includeMccs: JsonField>) = apply {
                this.includeMccs = includeMccs
            }

            /**
             * ISO-3166-1 alpha-3 Country Codes to include in the velocity calculation. Transactions
             * not matching any of the provided will not be included in the calculated velocity.
             */
            fun includeCountries(includeCountries: List) =
                includeCountries(JsonField.of(includeCountries))

            /**
             * ISO-3166-1 alpha-3 Country Codes to include in the velocity calculation. Transactions
             * not matching any of the provided will not be included in the calculated velocity.
             */
            @JsonProperty("include_countries")
            @ExcludeMissing
            fun includeCountries(includeCountries: JsonField>) = apply {
                this.includeCountries = includeCountries
            }

            fun additionalProperties(additionalProperties: Map) = apply {
                this.additionalProperties.clear()
                this.additionalProperties.putAll(additionalProperties)
            }

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

            fun putAllAdditionalProperties(additionalProperties: Map) = apply {
                this.additionalProperties.putAll(additionalProperties)
            }

            fun build(): Filters =
                Filters(
                    includeMccs.map { it.toUnmodifiable() },
                    includeCountries.map { it.toUnmodifiable() },
                    additionalProperties.toUnmodifiable(),
                )
        }

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

            return other is Filters &&
                this.includeMccs == other.includeMccs &&
                this.includeCountries == other.includeCountries &&
                this.additionalProperties == other.additionalProperties
        }

        private var hashCode: Int = 0

        override fun hashCode(): Int {
            if (hashCode == 0) {
                hashCode =
                    Objects.hash(
                        includeMccs,
                        includeCountries,
                        additionalProperties,
                    )
            }
            return hashCode
        }

        override fun toString() =
            "Filters{includeMccs=$includeMccs, includeCountries=$includeCountries, additionalProperties=$additionalProperties}"
    }

    @JsonDeserialize(using = Period.Deserializer::class)
    @JsonSerialize(using = Period.Serializer::class)
    class Period
    private constructor(
        private val double_: Double? = null,
        private val velocityLimitParamsPeriodWindow: VelocityLimitParamsPeriodWindow? = null,
        private val _json: JsonValue? = null,
    ) {

        private var validated: Boolean = false

        /** The size of the trailing window to calculate Spend Velocity over in seconds. */
        fun double_(): Optional = Optional.ofNullable(double_)
        /**
         * The window of time to calculate Spend Velocity over.
         * - `DAY`: Velocity over the current day since midnight Eastern Time.
         * - `MONTH`: Velocity over the current month since 00:00 / 12 AM on the first of the month
         *   in Eastern Time.
         */
        fun velocityLimitParamsPeriodWindow(): Optional =
            Optional.ofNullable(velocityLimitParamsPeriodWindow)

        fun isDouble(): Boolean = double_ != null

        fun isVelocityLimitParamsPeriodWindow(): Boolean = velocityLimitParamsPeriodWindow != null

        fun asDouble(): Double = double_.getOrThrow("double_")

        fun asVelocityLimitParamsPeriodWindow(): VelocityLimitParamsPeriodWindow =
            velocityLimitParamsPeriodWindow.getOrThrow("velocityLimitParamsPeriodWindow")

        fun _json(): Optional = Optional.ofNullable(_json)

        fun  accept(visitor: Visitor): T {
            return when {
                double_ != null -> visitor.visitDouble(double_)
                velocityLimitParamsPeriodWindow != null ->
                    visitor.visitVelocityLimitParamsPeriodWindow(velocityLimitParamsPeriodWindow)
                else -> visitor.unknown(_json)
            }
        }

        fun validate(): Period = apply {
            if (!validated) {
                if (double_ == null && velocityLimitParamsPeriodWindow == null) {
                    throw LithicInvalidDataException("Unknown Period: $_json")
                }
                validated = true
            }
        }

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

            return other is Period &&
                this.double_ == other.double_ &&
                this.velocityLimitParamsPeriodWindow == other.velocityLimitParamsPeriodWindow
        }

        override fun hashCode(): Int {
            return Objects.hash(double_, velocityLimitParamsPeriodWindow)
        }

        override fun toString(): String {
            return when {
                double_ != null -> "Period{double_=$double_}"
                velocityLimitParamsPeriodWindow != null ->
                    "Period{velocityLimitParamsPeriodWindow=$velocityLimitParamsPeriodWindow}"
                _json != null -> "Period{_unknown=$_json}"
                else -> throw IllegalStateException("Invalid Period")
            }
        }

        companion object {

            @JvmStatic fun ofDouble(double_: Double) = Period(double_ = double_)

            @JvmStatic
            fun ofVelocityLimitParamsPeriodWindow(
                velocityLimitParamsPeriodWindow: VelocityLimitParamsPeriodWindow
            ) = Period(velocityLimitParamsPeriodWindow = velocityLimitParamsPeriodWindow)
        }

        interface Visitor {

            fun visitDouble(double_: Double): T

            fun visitVelocityLimitParamsPeriodWindow(
                velocityLimitParamsPeriodWindow: VelocityLimitParamsPeriodWindow
            ): T

            fun unknown(json: JsonValue?): T {
                throw LithicInvalidDataException("Unknown Period: $json")
            }
        }

        class Deserializer : BaseDeserializer(Period::class) {

            override fun ObjectCodec.deserialize(node: JsonNode): Period {
                val json = JsonValue.fromJsonNode(node)
                tryDeserialize(node, jacksonTypeRef())?.let {
                    return Period(double_ = it, _json = json)
                }
                tryDeserialize(node, jacksonTypeRef())?.let {
                    return Period(velocityLimitParamsPeriodWindow = it, _json = json)
                }

                return Period(_json = json)
            }
        }

        class Serializer : BaseSerializer(Period::class) {

            override fun serialize(
                value: Period,
                generator: JsonGenerator,
                provider: SerializerProvider
            ) {
                when {
                    value.double_ != null -> generator.writeObject(value.double_)
                    value.velocityLimitParamsPeriodWindow != null ->
                        generator.writeObject(value.velocityLimitParamsPeriodWindow)
                    value._json != null -> generator.writeObject(value._json)
                    else -> throw IllegalStateException("Invalid Period")
                }
            }
        }
    }

    class Scope
    @JsonCreator
    private constructor(
        private val value: JsonField,
    ) : Enum {

        @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value

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

            return other is Scope && this.value == other.value
        }

        override fun hashCode() = value.hashCode()

        override fun toString() = value.toString()

        companion object {

            @JvmField val CARD = Scope(JsonField.of("CARD"))

            @JvmField val ACCOUNT = Scope(JsonField.of("ACCOUNT"))

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

        enum class Known {
            CARD,
            ACCOUNT,
        }

        enum class Value {
            CARD,
            ACCOUNT,
            _UNKNOWN,
        }

        fun value(): Value =
            when (this) {
                CARD -> Value.CARD
                ACCOUNT -> Value.ACCOUNT
                else -> Value._UNKNOWN
            }

        fun known(): Known =
            when (this) {
                CARD -> Known.CARD
                ACCOUNT -> Known.ACCOUNT
                else -> throw LithicInvalidDataException("Unknown Scope: $value")
            }

        fun asString(): String = _value().asStringOrThrow()
    }

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

        return other is VelocityLimitParams &&
            this.scope == other.scope &&
            this.period == other.period &&
            this.filters == other.filters &&
            this.limitAmount == other.limitAmount &&
            this.limitCount == other.limitCount &&
            this.additionalProperties == other.additionalProperties
    }

    private var hashCode: Int = 0

    override fun hashCode(): Int {
        if (hashCode == 0) {
            hashCode =
                Objects.hash(
                    scope,
                    period,
                    filters,
                    limitAmount,
                    limitCount,
                    additionalProperties,
                )
        }
        return hashCode
    }

    override fun toString() =
        "VelocityLimitParams{scope=$scope, period=$period, filters=$filters, limitAmount=$limitAmount, limitCount=$limitCount, additionalProperties=$additionalProperties}"
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy