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