|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.lithic.api.models |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.JsonAnyGetter |
| 6 | +import com.fasterxml.jackson.annotation.JsonAnySetter |
| 7 | +import com.fasterxml.jackson.annotation.JsonCreator |
| 8 | +import com.fasterxml.jackson.annotation.JsonProperty |
| 9 | +import com.lithic.api.core.ExcludeMissing |
| 10 | +import com.lithic.api.core.JsonField |
| 11 | +import com.lithic.api.core.JsonMissing |
| 12 | +import com.lithic.api.core.JsonValue |
| 13 | +import com.lithic.api.errors.LithicInvalidDataException |
| 14 | +import java.util.Collections |
| 15 | +import java.util.Objects |
| 16 | +import java.util.Optional |
| 17 | + |
| 18 | +/** Rate and rate cap for interest on a category */ |
| 19 | +class CategoryTier |
| 20 | +@JsonCreator(mode = JsonCreator.Mode.DISABLED) |
| 21 | +private constructor( |
| 22 | + private val capRate: JsonField<String>, |
| 23 | + private val rate: JsonField<String>, |
| 24 | + private val additionalProperties: MutableMap<String, JsonValue>, |
| 25 | +) { |
| 26 | + |
| 27 | + @JsonCreator |
| 28 | + private constructor( |
| 29 | + @JsonProperty("cap_rate") @ExcludeMissing capRate: JsonField<String> = JsonMissing.of(), |
| 30 | + @JsonProperty("rate") @ExcludeMissing rate: JsonField<String> = JsonMissing.of(), |
| 31 | + ) : this(capRate, rate, mutableMapOf()) |
| 32 | + |
| 33 | + /** |
| 34 | + * Maximum interest rate for this category, e.g. '0.0525' for 5.25% |
| 35 | + * |
| 36 | + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the |
| 37 | + * server responded with an unexpected value). |
| 38 | + */ |
| 39 | + fun capRate(): Optional<String> = capRate.getOptional("cap_rate") |
| 40 | + |
| 41 | + /** |
| 42 | + * Interest rate for this category, e.g. '0.0525' for 5.25% |
| 43 | + * |
| 44 | + * @throws LithicInvalidDataException if the JSON field has an unexpected type (e.g. if the |
| 45 | + * server responded with an unexpected value). |
| 46 | + */ |
| 47 | + fun rate(): Optional<String> = rate.getOptional("rate") |
| 48 | + |
| 49 | + /** |
| 50 | + * Returns the raw JSON value of [capRate]. |
| 51 | + * |
| 52 | + * Unlike [capRate], this method doesn't throw if the JSON field has an unexpected type. |
| 53 | + */ |
| 54 | + @JsonProperty("cap_rate") @ExcludeMissing fun _capRate(): JsonField<String> = capRate |
| 55 | + |
| 56 | + /** |
| 57 | + * Returns the raw JSON value of [rate]. |
| 58 | + * |
| 59 | + * Unlike [rate], this method doesn't throw if the JSON field has an unexpected type. |
| 60 | + */ |
| 61 | + @JsonProperty("rate") @ExcludeMissing fun _rate(): JsonField<String> = rate |
| 62 | + |
| 63 | + @JsonAnySetter |
| 64 | + private fun putAdditionalProperty(key: String, value: JsonValue) { |
| 65 | + additionalProperties.put(key, value) |
| 66 | + } |
| 67 | + |
| 68 | + @JsonAnyGetter |
| 69 | + @ExcludeMissing |
| 70 | + fun _additionalProperties(): Map<String, JsonValue> = |
| 71 | + Collections.unmodifiableMap(additionalProperties) |
| 72 | + |
| 73 | + fun toBuilder() = Builder().from(this) |
| 74 | + |
| 75 | + companion object { |
| 76 | + |
| 77 | + /** Returns a mutable builder for constructing an instance of [CategoryTier]. */ |
| 78 | + @JvmStatic fun builder() = Builder() |
| 79 | + } |
| 80 | + |
| 81 | + /** A builder for [CategoryTier]. */ |
| 82 | + class Builder internal constructor() { |
| 83 | + |
| 84 | + private var capRate: JsonField<String> = JsonMissing.of() |
| 85 | + private var rate: JsonField<String> = JsonMissing.of() |
| 86 | + private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf() |
| 87 | + |
| 88 | + @JvmSynthetic |
| 89 | + internal fun from(categoryTier: CategoryTier) = apply { |
| 90 | + capRate = categoryTier.capRate |
| 91 | + rate = categoryTier.rate |
| 92 | + additionalProperties = categoryTier.additionalProperties.toMutableMap() |
| 93 | + } |
| 94 | + |
| 95 | + /** Maximum interest rate for this category, e.g. '0.0525' for 5.25% */ |
| 96 | + fun capRate(capRate: String) = capRate(JsonField.of(capRate)) |
| 97 | + |
| 98 | + /** |
| 99 | + * Sets [Builder.capRate] to an arbitrary JSON value. |
| 100 | + * |
| 101 | + * You should usually call [Builder.capRate] with a well-typed [String] value instead. This |
| 102 | + * method is primarily for setting the field to an undocumented or not yet supported value. |
| 103 | + */ |
| 104 | + fun capRate(capRate: JsonField<String>) = apply { this.capRate = capRate } |
| 105 | + |
| 106 | + /** Interest rate for this category, e.g. '0.0525' for 5.25% */ |
| 107 | + fun rate(rate: String) = rate(JsonField.of(rate)) |
| 108 | + |
| 109 | + /** |
| 110 | + * Sets [Builder.rate] to an arbitrary JSON value. |
| 111 | + * |
| 112 | + * You should usually call [Builder.rate] with a well-typed [String] value instead. This |
| 113 | + * method is primarily for setting the field to an undocumented or not yet supported value. |
| 114 | + */ |
| 115 | + fun rate(rate: JsonField<String>) = apply { this.rate = rate } |
| 116 | + |
| 117 | + fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 118 | + this.additionalProperties.clear() |
| 119 | + putAllAdditionalProperties(additionalProperties) |
| 120 | + } |
| 121 | + |
| 122 | + fun putAdditionalProperty(key: String, value: JsonValue) = apply { |
| 123 | + additionalProperties.put(key, value) |
| 124 | + } |
| 125 | + |
| 126 | + fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 127 | + this.additionalProperties.putAll(additionalProperties) |
| 128 | + } |
| 129 | + |
| 130 | + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } |
| 131 | + |
| 132 | + fun removeAllAdditionalProperties(keys: Set<String>) = apply { |
| 133 | + keys.forEach(::removeAdditionalProperty) |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Returns an immutable instance of [CategoryTier]. |
| 138 | + * |
| 139 | + * Further updates to this [Builder] will not mutate the returned instance. |
| 140 | + */ |
| 141 | + fun build(): CategoryTier = CategoryTier(capRate, rate, additionalProperties.toMutableMap()) |
| 142 | + } |
| 143 | + |
| 144 | + private var validated: Boolean = false |
| 145 | + |
| 146 | + fun validate(): CategoryTier = apply { |
| 147 | + if (validated) { |
| 148 | + return@apply |
| 149 | + } |
| 150 | + |
| 151 | + capRate() |
| 152 | + rate() |
| 153 | + validated = true |
| 154 | + } |
| 155 | + |
| 156 | + fun isValid(): Boolean = |
| 157 | + try { |
| 158 | + validate() |
| 159 | + true |
| 160 | + } catch (e: LithicInvalidDataException) { |
| 161 | + false |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * Returns a score indicating how many valid values are contained in this object recursively. |
| 166 | + * |
| 167 | + * Used for best match union deserialization. |
| 168 | + */ |
| 169 | + @JvmSynthetic |
| 170 | + internal fun validity(): Int = |
| 171 | + (if (capRate.asKnown().isPresent) 1 else 0) + (if (rate.asKnown().isPresent) 1 else 0) |
| 172 | + |
| 173 | + override fun equals(other: Any?): Boolean { |
| 174 | + if (this === other) { |
| 175 | + return true |
| 176 | + } |
| 177 | + |
| 178 | + return other is CategoryTier && |
| 179 | + capRate == other.capRate && |
| 180 | + rate == other.rate && |
| 181 | + additionalProperties == other.additionalProperties |
| 182 | + } |
| 183 | + |
| 184 | + private val hashCode: Int by lazy { Objects.hash(capRate, rate, additionalProperties) } |
| 185 | + |
| 186 | + override fun hashCode(): Int = hashCode |
| 187 | + |
| 188 | + override fun toString() = |
| 189 | + "CategoryTier{capRate=$capRate, rate=$rate, additionalProperties=$additionalProperties}" |
| 190 | +} |
0 commit comments