com.tryfinch.api.models.BenefitContribution.kt Maven / Gradle / Ivy
// File generated from our OpenAPI spec by Stainless.
package com.tryfinch.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.databind.annotation.JsonDeserialize
import com.tryfinch.api.core.Enum
import com.tryfinch.api.core.ExcludeMissing
import com.tryfinch.api.core.JsonField
import com.tryfinch.api.core.JsonMissing
import com.tryfinch.api.core.JsonValue
import com.tryfinch.api.core.NoAutoDetect
import com.tryfinch.api.core.toImmutable
import com.tryfinch.api.errors.FinchInvalidDataException
import java.util.Objects
@JsonDeserialize(builder = BenefitContribution.Builder::class)
@NoAutoDetect
class BenefitContribution
private constructor(
private val type: JsonField,
private val amount: JsonField,
private val additionalProperties: Map,
) {
private var validated: Boolean = false
/** Contribution type. */
fun type(): Type? = type.getNullable("type")
/** Contribution amount in cents (if `fixed`) or basis points (if `percent`). */
fun amount(): Long? = amount.getNullable("amount")
/** Contribution type. */
@JsonProperty("type") @ExcludeMissing fun _type() = type
/** Contribution amount in cents (if `fixed`) or basis points (if `percent`). */
@JsonProperty("amount") @ExcludeMissing fun _amount() = amount
@JsonAnyGetter
@ExcludeMissing
fun _additionalProperties(): Map = additionalProperties
fun validate(): BenefitContribution = apply {
if (!validated) {
type()
amount()
validated = true
}
}
fun toBuilder() = Builder().from(this)
companion object {
fun builder() = Builder()
}
class Builder {
private var type: JsonField = JsonMissing.of()
private var amount: JsonField = JsonMissing.of()
private var additionalProperties: MutableMap = mutableMapOf()
internal fun from(benefitContribution: BenefitContribution) = apply {
this.type = benefitContribution.type
this.amount = benefitContribution.amount
additionalProperties(benefitContribution.additionalProperties)
}
/** Contribution type. */
fun type(type: Type) = type(JsonField.of(type))
/** Contribution type. */
@JsonProperty("type")
@ExcludeMissing
fun type(type: JsonField) = apply { this.type = type }
/** Contribution amount in cents (if `fixed`) or basis points (if `percent`). */
fun amount(amount: Long) = amount(JsonField.of(amount))
/** Contribution amount in cents (if `fixed`) or basis points (if `percent`). */
@JsonProperty("amount")
@ExcludeMissing
fun amount(amount: JsonField) = apply { this.amount = amount }
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(): BenefitContribution =
BenefitContribution(
type,
amount,
additionalProperties.toImmutable(),
)
}
class Type
@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 /* spotless:off */ other is Type && value == other.value /* spotless:on */
}
override fun hashCode() = value.hashCode()
override fun toString() = value.toString()
companion object {
val FIXED = Type(JsonField.of("fixed"))
val PERCENT = Type(JsonField.of("percent"))
fun of(value: String) = Type(JsonField.of(value))
}
enum class Known {
FIXED,
PERCENT,
}
enum class Value {
FIXED,
PERCENT,
_UNKNOWN,
}
fun value(): Value =
when (this) {
FIXED -> Value.FIXED
PERCENT -> Value.PERCENT
else -> Value._UNKNOWN
}
fun known(): Known =
when (this) {
FIXED -> Known.FIXED
PERCENT -> Known.PERCENT
else -> throw FinchInvalidDataException("Unknown Type: $value")
}
fun asString(): String = _value().asStringOrThrow()
}
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
return /* spotless:off */ other is BenefitContribution && type == other.type && amount == other.amount && additionalProperties == other.additionalProperties /* spotless:on */
}
/* spotless:off */
private val hashCode: Int by lazy { Objects.hash(type, amount, additionalProperties) }
/* spotless:on */
override fun hashCode(): Int = hashCode
override fun toString() =
"BenefitContribution{type=$type, amount=$amount, additionalProperties=$additionalProperties}"
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy