|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.courier.models |
| 4 | + |
| 5 | +import com.courier.core.ExcludeMissing |
| 6 | +import com.courier.core.JsonField |
| 7 | +import com.courier.core.JsonMissing |
| 8 | +import com.courier.core.JsonValue |
| 9 | +import com.courier.core.checkKnown |
| 10 | +import com.courier.core.checkRequired |
| 11 | +import com.courier.core.toImmutable |
| 12 | +import com.courier.errors.CourierInvalidDataException |
| 13 | +import com.fasterxml.jackson.annotation.JsonAnyGetter |
| 14 | +import com.fasterxml.jackson.annotation.JsonAnySetter |
| 15 | +import com.fasterxml.jackson.annotation.JsonCreator |
| 16 | +import com.fasterxml.jackson.annotation.JsonProperty |
| 17 | +import java.util.Collections |
| 18 | +import java.util.Objects |
| 19 | +import kotlin.jvm.optionals.getOrNull |
| 20 | + |
| 21 | +class AirshipProfile |
| 22 | +@JsonCreator(mode = JsonCreator.Mode.DISABLED) |
| 23 | +private constructor( |
| 24 | + private val audience: JsonField<AirshipProfileAudience>, |
| 25 | + private val deviceTypes: JsonField<List<String>>, |
| 26 | + private val additionalProperties: MutableMap<String, JsonValue>, |
| 27 | +) { |
| 28 | + |
| 29 | + @JsonCreator |
| 30 | + private constructor( |
| 31 | + @JsonProperty("audience") |
| 32 | + @ExcludeMissing |
| 33 | + audience: JsonField<AirshipProfileAudience> = JsonMissing.of(), |
| 34 | + @JsonProperty("device_types") |
| 35 | + @ExcludeMissing |
| 36 | + deviceTypes: JsonField<List<String>> = JsonMissing.of(), |
| 37 | + ) : this(audience, deviceTypes, mutableMapOf()) |
| 38 | + |
| 39 | + /** |
| 40 | + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is |
| 41 | + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). |
| 42 | + */ |
| 43 | + fun audience(): AirshipProfileAudience = audience.getRequired("audience") |
| 44 | + |
| 45 | + /** |
| 46 | + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is |
| 47 | + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). |
| 48 | + */ |
| 49 | + fun deviceTypes(): List<String> = deviceTypes.getRequired("device_types") |
| 50 | + |
| 51 | + /** |
| 52 | + * Returns the raw JSON value of [audience]. |
| 53 | + * |
| 54 | + * Unlike [audience], this method doesn't throw if the JSON field has an unexpected type. |
| 55 | + */ |
| 56 | + @JsonProperty("audience") |
| 57 | + @ExcludeMissing |
| 58 | + fun _audience(): JsonField<AirshipProfileAudience> = audience |
| 59 | + |
| 60 | + /** |
| 61 | + * Returns the raw JSON value of [deviceTypes]. |
| 62 | + * |
| 63 | + * Unlike [deviceTypes], this method doesn't throw if the JSON field has an unexpected type. |
| 64 | + */ |
| 65 | + @JsonProperty("device_types") |
| 66 | + @ExcludeMissing |
| 67 | + fun _deviceTypes(): JsonField<List<String>> = deviceTypes |
| 68 | + |
| 69 | + @JsonAnySetter |
| 70 | + private fun putAdditionalProperty(key: String, value: JsonValue) { |
| 71 | + additionalProperties.put(key, value) |
| 72 | + } |
| 73 | + |
| 74 | + @JsonAnyGetter |
| 75 | + @ExcludeMissing |
| 76 | + fun _additionalProperties(): Map<String, JsonValue> = |
| 77 | + Collections.unmodifiableMap(additionalProperties) |
| 78 | + |
| 79 | + fun toBuilder() = Builder().from(this) |
| 80 | + |
| 81 | + companion object { |
| 82 | + |
| 83 | + /** |
| 84 | + * Returns a mutable builder for constructing an instance of [AirshipProfile]. |
| 85 | + * |
| 86 | + * The following fields are required: |
| 87 | + * ```java |
| 88 | + * .audience() |
| 89 | + * .deviceTypes() |
| 90 | + * ``` |
| 91 | + */ |
| 92 | + @JvmStatic fun builder() = Builder() |
| 93 | + } |
| 94 | + |
| 95 | + /** A builder for [AirshipProfile]. */ |
| 96 | + class Builder internal constructor() { |
| 97 | + |
| 98 | + private var audience: JsonField<AirshipProfileAudience>? = null |
| 99 | + private var deviceTypes: JsonField<MutableList<String>>? = null |
| 100 | + private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf() |
| 101 | + |
| 102 | + @JvmSynthetic |
| 103 | + internal fun from(airshipProfile: AirshipProfile) = apply { |
| 104 | + audience = airshipProfile.audience |
| 105 | + deviceTypes = airshipProfile.deviceTypes.map { it.toMutableList() } |
| 106 | + additionalProperties = airshipProfile.additionalProperties.toMutableMap() |
| 107 | + } |
| 108 | + |
| 109 | + fun audience(audience: AirshipProfileAudience) = audience(JsonField.of(audience)) |
| 110 | + |
| 111 | + /** |
| 112 | + * Sets [Builder.audience] to an arbitrary JSON value. |
| 113 | + * |
| 114 | + * You should usually call [Builder.audience] with a well-typed [AirshipProfileAudience] |
| 115 | + * value instead. This method is primarily for setting the field to an undocumented or not |
| 116 | + * yet supported value. |
| 117 | + */ |
| 118 | + fun audience(audience: JsonField<AirshipProfileAudience>) = apply { |
| 119 | + this.audience = audience |
| 120 | + } |
| 121 | + |
| 122 | + fun deviceTypes(deviceTypes: List<String>) = deviceTypes(JsonField.of(deviceTypes)) |
| 123 | + |
| 124 | + /** |
| 125 | + * Sets [Builder.deviceTypes] to an arbitrary JSON value. |
| 126 | + * |
| 127 | + * You should usually call [Builder.deviceTypes] with a well-typed `List<String>` value |
| 128 | + * instead. This method is primarily for setting the field to an undocumented or not yet |
| 129 | + * supported value. |
| 130 | + */ |
| 131 | + fun deviceTypes(deviceTypes: JsonField<List<String>>) = apply { |
| 132 | + this.deviceTypes = deviceTypes.map { it.toMutableList() } |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Adds a single [String] to [deviceTypes]. |
| 137 | + * |
| 138 | + * @throws IllegalStateException if the field was previously set to a non-list. |
| 139 | + */ |
| 140 | + fun addDeviceType(deviceType: String) = apply { |
| 141 | + deviceTypes = |
| 142 | + (deviceTypes ?: JsonField.of(mutableListOf())).also { |
| 143 | + checkKnown("deviceTypes", it).add(deviceType) |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 148 | + this.additionalProperties.clear() |
| 149 | + putAllAdditionalProperties(additionalProperties) |
| 150 | + } |
| 151 | + |
| 152 | + fun putAdditionalProperty(key: String, value: JsonValue) = apply { |
| 153 | + additionalProperties.put(key, value) |
| 154 | + } |
| 155 | + |
| 156 | + fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply { |
| 157 | + this.additionalProperties.putAll(additionalProperties) |
| 158 | + } |
| 159 | + |
| 160 | + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } |
| 161 | + |
| 162 | + fun removeAllAdditionalProperties(keys: Set<String>) = apply { |
| 163 | + keys.forEach(::removeAdditionalProperty) |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * Returns an immutable instance of [AirshipProfile]. |
| 168 | + * |
| 169 | + * Further updates to this [Builder] will not mutate the returned instance. |
| 170 | + * |
| 171 | + * The following fields are required: |
| 172 | + * ```java |
| 173 | + * .audience() |
| 174 | + * .deviceTypes() |
| 175 | + * ``` |
| 176 | + * |
| 177 | + * @throws IllegalStateException if any required field is unset. |
| 178 | + */ |
| 179 | + fun build(): AirshipProfile = |
| 180 | + AirshipProfile( |
| 181 | + checkRequired("audience", audience), |
| 182 | + checkRequired("deviceTypes", deviceTypes).map { it.toImmutable() }, |
| 183 | + additionalProperties.toMutableMap(), |
| 184 | + ) |
| 185 | + } |
| 186 | + |
| 187 | + private var validated: Boolean = false |
| 188 | + |
| 189 | + fun validate(): AirshipProfile = apply { |
| 190 | + if (validated) { |
| 191 | + return@apply |
| 192 | + } |
| 193 | + |
| 194 | + audience().validate() |
| 195 | + deviceTypes() |
| 196 | + validated = true |
| 197 | + } |
| 198 | + |
| 199 | + fun isValid(): Boolean = |
| 200 | + try { |
| 201 | + validate() |
| 202 | + true |
| 203 | + } catch (e: CourierInvalidDataException) { |
| 204 | + false |
| 205 | + } |
| 206 | + |
| 207 | + /** |
| 208 | + * Returns a score indicating how many valid values are contained in this object recursively. |
| 209 | + * |
| 210 | + * Used for best match union deserialization. |
| 211 | + */ |
| 212 | + @JvmSynthetic |
| 213 | + internal fun validity(): Int = |
| 214 | + (audience.asKnown().getOrNull()?.validity() ?: 0) + |
| 215 | + (deviceTypes.asKnown().getOrNull()?.size ?: 0) |
| 216 | + |
| 217 | + override fun equals(other: Any?): Boolean { |
| 218 | + if (this === other) { |
| 219 | + return true |
| 220 | + } |
| 221 | + |
| 222 | + return other is AirshipProfile && |
| 223 | + audience == other.audience && |
| 224 | + deviceTypes == other.deviceTypes && |
| 225 | + additionalProperties == other.additionalProperties |
| 226 | + } |
| 227 | + |
| 228 | + private val hashCode: Int by lazy { Objects.hash(audience, deviceTypes, additionalProperties) } |
| 229 | + |
| 230 | + override fun hashCode(): Int = hashCode |
| 231 | + |
| 232 | + override fun toString() = |
| 233 | + "AirshipProfile{audience=$audience, deviceTypes=$deviceTypes, additionalProperties=$additionalProperties}" |
| 234 | +} |
0 commit comments