|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.withorb.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.withorb.api.core.ExcludeMissing |
| 10 | +import com.withorb.api.core.JsonField |
| 11 | +import com.withorb.api.core.JsonMissing |
| 12 | +import com.withorb.api.core.JsonValue |
| 13 | +import com.withorb.api.core.checkRequired |
| 14 | +import com.withorb.api.errors.OrbInvalidDataException |
| 15 | +import java.util.Collections |
| 16 | +import java.util.Objects |
| 17 | +import java.util.Optional |
| 18 | +import kotlin.jvm.optionals.getOrNull |
| 19 | + |
| 20 | +class ConversionRateTier |
| 21 | +private constructor( |
| 22 | + private val firstUnit: JsonField<Double>, |
| 23 | + private val unitAmount: JsonField<String>, |
| 24 | + private val lastUnit: JsonField<Double>, |
| 25 | + private val additionalProperties: MutableMap<String, JsonValue>, |
| 26 | +) { |
| 27 | + |
| 28 | + @JsonCreator |
| 29 | + private constructor( |
| 30 | + @JsonProperty("first_unit") @ExcludeMissing firstUnit: JsonField<Double> = JsonMissing.of(), |
| 31 | + @JsonProperty("unit_amount") |
| 32 | + @ExcludeMissing |
| 33 | + unitAmount: JsonField<String> = JsonMissing.of(), |
| 34 | + @JsonProperty("last_unit") @ExcludeMissing lastUnit: JsonField<Double> = JsonMissing.of(), |
| 35 | + ) : this(firstUnit, unitAmount, lastUnit, mutableMapOf()) |
| 36 | + |
| 37 | + /** |
| 38 | + * Exclusive tier starting value |
| 39 | + * |
| 40 | + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly |
| 41 | + * missing or null (e.g. if the server responded with an unexpected value). |
| 42 | + */ |
| 43 | + fun firstUnit(): Double = firstUnit.getRequired("first_unit") |
| 44 | + |
| 45 | + /** |
| 46 | + * Amount per unit of overage |
| 47 | + * |
| 48 | + * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly |
| 49 | + * missing or null (e.g. if the server responded with an unexpected value). |
| 50 | + */ |
| 51 | + fun unitAmount(): String = unitAmount.getRequired("unit_amount") |
| 52 | + |
| 53 | + /** |
| 54 | + * Inclusive tier ending value. If null, this is treated as the last tier |
| 55 | + * |
| 56 | + * @throws OrbInvalidDataException if the JSON field has an unexpected type (e.g. if the server |
| 57 | + * responded with an unexpected value). |
| 58 | + */ |
| 59 | + fun lastUnit(): Optional<Double> = lastUnit.getOptional("last_unit") |
| 60 | + |
| 61 | + /** |
| 62 | + * Returns the raw JSON value of [firstUnit]. |
| 63 | + * |
| 64 | + * Unlike [firstUnit], this method doesn't throw if the JSON field has an unexpected type. |
| 65 | + */ |
| 66 | + @JsonProperty("first_unit") @ExcludeMissing fun _firstUnit(): JsonField<Double> = firstUnit |
| 67 | + |
| 68 | + /** |
| 69 | + * Returns the raw JSON value of [unitAmount]. |
| 70 | + * |
| 71 | + * Unlike [unitAmount], this method doesn't throw if the JSON field has an unexpected type. |
| 72 | + */ |
| 73 | + @JsonProperty("unit_amount") @ExcludeMissing fun _unitAmount(): JsonField<String> = unitAmount |
| 74 | + |
| 75 | + /** |
| 76 | + * Returns the raw JSON value of [lastUnit]. |
| 77 | + * |
| 78 | + * Unlike [lastUnit], this method doesn't throw if the JSON field has an unexpected type. |
| 79 | + */ |
| 80 | + @JsonProperty("last_unit") @ExcludeMissing fun _lastUnit(): JsonField<Double> = lastUnit |
| 81 | + |
| 82 | + @JsonAnySetter |
| 83 | + private fun putAdditionalProperty(key: String, value: JsonValue) { |
| 84 | + additionalProperties.put(key, value) |
| 85 | + } |
| 86 | + |
| 87 | + @JsonAnyGetter |
| 88 | + @ExcludeMissing |
| 89 | + fun _additionalProperties(): Map<String, JsonValue> = |
| 90 | + Collections.unmodifiableMap(additionalProperties) |
| 91 | + |
| 92 | + fun toBuilder() = Builder().from(this) |
| 93 | + |
| 94 | + companion object { |
| 95 | + |
| 96 | + /** |
| 97 | + * Returns a mutable builder for constructing an instance of [ConversionRateTier]. |
| 98 | + * |
| 99 | + * The following fields are required: |
| 100 | + * ```java |
| 101 | + * .firstUnit() |
| 102 | + * .unitAmount() |
| 103 | + * ``` |
| 104 | + */ |
| 105 | + @JvmStatic fun builder() = Builder() |
| 106 | + } |
| 107 | + |
| 108 | + /** A builder for [ConversionRateTier]. */ |
| 109 | + class Builder internal constructor() { |
| 110 | + |
| 111 | + private var firstUnit: JsonField<Double>? = null |
| 112 | + private var unitAmount: JsonField<String>? = null |
| 113 | + private var lastUnit: JsonField<Double> = JsonMissing.of() |
| 114 | + private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf() |
| 115 | + |
| 116 | + @JvmSynthetic |
| 117 | + internal fun from(conversionRateTier: ConversionRateTier) = apply { |
| 118 | + firstUnit = conversionRateTier.firstUnit |
| 119 | + unitAmount = conversionRateTier.unitAmount |
| 120 | + lastUnit = conversionRateTier.lastUnit |
| 121 | + additionalProperties = conversionRateTier.additionalProperties.toMutableMap() |
| 122 | + } |
| 123 | + |
| 124 | + /** Exclusive tier starting value */ |
| 125 | + fun firstUnit(firstUnit: Double) = firstUnit(JsonField.of(firstUnit)) |
| 126 | + |
| 127 | + /** |
| 128 | + * Sets [Builder.firstUnit] to an arbitrary JSON value. |
| 129 | + * |
| 130 | + * You should usually call [Builder.firstUnit] with a well-typed [Double] value instead. |
| 131 | + * This method is primarily for setting the field to an undocumented or not yet supported |
| 132 | + * value. |
| 133 | + */ |
| 134 | + fun firstUnit(firstUnit: JsonField<Double>) = apply { this.firstUnit = firstUnit } |
| 135 | + |
| 136 | + /** Amount per unit of overage */ |
| 137 | + fun unitAmount(unitAmount: String) = unitAmount(JsonField.of(unitAmount)) |
| 138 | + |
| 139 | + /** |
| 140 | + * Sets [Builder.unitAmount] to an arbitrary JSON value. |
| 141 | + * |
| 142 | + * You should usually call [Builder.unitAmount] with a well-typed [String] value instead. |
| 143 | + * This method is primarily for setting the field to an undocumented or not yet supported |
| 144 | + * value. |
| 145 | + */ |
| 146 | + fun unitAmount(unitAmount: JsonField<String>) = apply { this.unitAmount = unitAmount } |
| 147 | + |
| 148 | + /** Inclusive tier ending value. If null, this is treated as the last tier */ |
| 149 | + fun lastUnit(lastUnit: Double?) = lastUnit(JsonField.ofNullable(lastUnit)) |
| 150 | + |
| 151 | + /** |
| 152 | + * Alias for [Builder.lastUnit]. |
| 153 | + * |
| 154 | + * This unboxed primitive overload exists for backwards compatibility. |
| 155 | + */ |
| 156 | + fun lastUnit(lastUnit: Double) = lastUnit(lastUnit as Double?) |
| 157 | + |
| 158 | + /** Alias for calling [Builder.lastUnit] with `lastUnit.orElse(null)`. */ |
| 159 | + fun lastUnit(lastUnit: Optional<Double>) = lastUnit(lastUnit.getOrNull()) |
| 160 | + |
| 161 | + /** |
| 162 | + * Sets [Builder.lastUnit] to an arbitrary JSON value. |
| 163 | + * |
| 164 | + * You should usually call [Builder.lastUnit] with a well-typed [Double] value instead. This |
| 165 | + * method is primarily for setting the field to an undocumented or not yet supported value. |
| 166 | + */ |
| 167 | + fun lastUnit(lastUnit: JsonField<Double>) = apply { this.lastUnit = lastUnit } |
| 168 | + |
| 169 | + fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 170 | + this.additionalProperties.clear() |
| 171 | + putAllAdditionalProperties(additionalProperties) |
| 172 | + } |
| 173 | + |
| 174 | + fun putAdditionalProperty(key: String, value: JsonValue) = apply { |
| 175 | + additionalProperties.put(key, value) |
| 176 | + } |
| 177 | + |
| 178 | + fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 179 | + this.additionalProperties.putAll(additionalProperties) |
| 180 | + } |
| 181 | + |
| 182 | + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } |
| 183 | + |
| 184 | + fun removeAllAdditionalProperties(keys: Set<String>) = apply { |
| 185 | + keys.forEach(::removeAdditionalProperty) |
| 186 | + } |
| 187 | + |
| 188 | + /** |
| 189 | + * Returns an immutable instance of [ConversionRateTier]. |
| 190 | + * |
| 191 | + * Further updates to this [Builder] will not mutate the returned instance. |
| 192 | + * |
| 193 | + * The following fields are required: |
| 194 | + * ```java |
| 195 | + * .firstUnit() |
| 196 | + * .unitAmount() |
| 197 | + * ``` |
| 198 | + * |
| 199 | + * @throws IllegalStateException if any required field is unset. |
| 200 | + */ |
| 201 | + fun build(): ConversionRateTier = |
| 202 | + ConversionRateTier( |
| 203 | + checkRequired("firstUnit", firstUnit), |
| 204 | + checkRequired("unitAmount", unitAmount), |
| 205 | + lastUnit, |
| 206 | + additionalProperties.toMutableMap(), |
| 207 | + ) |
| 208 | + } |
| 209 | + |
| 210 | + private var validated: Boolean = false |
| 211 | + |
| 212 | + fun validate(): ConversionRateTier = apply { |
| 213 | + if (validated) { |
| 214 | + return@apply |
| 215 | + } |
| 216 | + |
| 217 | + firstUnit() |
| 218 | + unitAmount() |
| 219 | + lastUnit() |
| 220 | + validated = true |
| 221 | + } |
| 222 | + |
| 223 | + fun isValid(): Boolean = |
| 224 | + try { |
| 225 | + validate() |
| 226 | + true |
| 227 | + } catch (e: OrbInvalidDataException) { |
| 228 | + false |
| 229 | + } |
| 230 | + |
| 231 | + /** |
| 232 | + * Returns a score indicating how many valid values are contained in this object recursively. |
| 233 | + * |
| 234 | + * Used for best match union deserialization. |
| 235 | + */ |
| 236 | + @JvmSynthetic |
| 237 | + internal fun validity(): Int = |
| 238 | + (if (firstUnit.asKnown().isPresent) 1 else 0) + |
| 239 | + (if (unitAmount.asKnown().isPresent) 1 else 0) + |
| 240 | + (if (lastUnit.asKnown().isPresent) 1 else 0) |
| 241 | + |
| 242 | + override fun equals(other: Any?): Boolean { |
| 243 | + if (this === other) { |
| 244 | + return true |
| 245 | + } |
| 246 | + |
| 247 | + return /* spotless:off */ other is ConversionRateTier && firstUnit == other.firstUnit && unitAmount == other.unitAmount && lastUnit == other.lastUnit && additionalProperties == other.additionalProperties /* spotless:on */ |
| 248 | + } |
| 249 | + |
| 250 | + /* spotless:off */ |
| 251 | + private val hashCode: Int by lazy { Objects.hash(firstUnit, unitAmount, lastUnit, additionalProperties) } |
| 252 | + /* spotless:on */ |
| 253 | + |
| 254 | + override fun hashCode(): Int = hashCode |
| 255 | + |
| 256 | + override fun toString() = |
| 257 | + "ConversionRateTier{firstUnit=$firstUnit, unitAmount=$unitAmount, lastUnit=$lastUnit, additionalProperties=$additionalProperties}" |
| 258 | +} |
0 commit comments