|
| 1 | +// File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +package com.branddev.api.models.brand |
| 4 | + |
| 5 | +import com.branddev.api.core.Enum |
| 6 | +import com.branddev.api.core.JsonField |
| 7 | +import com.branddev.api.core.Params |
| 8 | +import com.branddev.api.core.checkRequired |
| 9 | +import com.branddev.api.core.http.Headers |
| 10 | +import com.branddev.api.core.http.QueryParams |
| 11 | +import com.branddev.api.errors.BrandDevInvalidDataException |
| 12 | +import com.fasterxml.jackson.annotation.JsonCreator |
| 13 | +import java.util.Objects |
| 14 | +import java.util.Optional |
| 15 | +import kotlin.jvm.optionals.getOrNull |
| 16 | + |
| 17 | +/** |
| 18 | + * Beta feature: Capture a screenshot of a website. Supports both viewport (standard browser view) |
| 19 | + * and full-page screenshots. Returns a URL to the uploaded screenshot image hosted on our CDN. |
| 20 | + */ |
| 21 | +class BrandScreenshotParams |
| 22 | +private constructor( |
| 23 | + private val domain: String, |
| 24 | + private val fullScreenshot: FullScreenshot?, |
| 25 | + private val additionalHeaders: Headers, |
| 26 | + private val additionalQueryParams: QueryParams, |
| 27 | +) : Params { |
| 28 | + |
| 29 | + /** |
| 30 | + * Domain name to take screenshot of (e.g., 'example.com', 'google.com'). The domain will be |
| 31 | + * automatically normalized and validated. |
| 32 | + */ |
| 33 | + fun domain(): String = domain |
| 34 | + |
| 35 | + /** |
| 36 | + * Optional parameter to determine screenshot type. If 'true', takes a full page screenshot |
| 37 | + * capturing all content. If 'false' or not provided, takes a viewport screenshot (standard |
| 38 | + * browser view). |
| 39 | + */ |
| 40 | + fun fullScreenshot(): Optional<FullScreenshot> = Optional.ofNullable(fullScreenshot) |
| 41 | + |
| 42 | + fun _additionalHeaders(): Headers = additionalHeaders |
| 43 | + |
| 44 | + fun _additionalQueryParams(): QueryParams = additionalQueryParams |
| 45 | + |
| 46 | + fun toBuilder() = Builder().from(this) |
| 47 | + |
| 48 | + companion object { |
| 49 | + |
| 50 | + /** |
| 51 | + * Returns a mutable builder for constructing an instance of [BrandScreenshotParams]. |
| 52 | + * |
| 53 | + * The following fields are required: |
| 54 | + * ```java |
| 55 | + * .domain() |
| 56 | + * ``` |
| 57 | + */ |
| 58 | + @JvmStatic fun builder() = Builder() |
| 59 | + } |
| 60 | + |
| 61 | + /** A builder for [BrandScreenshotParams]. */ |
| 62 | + class Builder internal constructor() { |
| 63 | + |
| 64 | + private var domain: String? = null |
| 65 | + private var fullScreenshot: FullScreenshot? = null |
| 66 | + private var additionalHeaders: Headers.Builder = Headers.builder() |
| 67 | + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() |
| 68 | + |
| 69 | + @JvmSynthetic |
| 70 | + internal fun from(brandScreenshotParams: BrandScreenshotParams) = apply { |
| 71 | + domain = brandScreenshotParams.domain |
| 72 | + fullScreenshot = brandScreenshotParams.fullScreenshot |
| 73 | + additionalHeaders = brandScreenshotParams.additionalHeaders.toBuilder() |
| 74 | + additionalQueryParams = brandScreenshotParams.additionalQueryParams.toBuilder() |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Domain name to take screenshot of (e.g., 'example.com', 'google.com'). The domain will be |
| 79 | + * automatically normalized and validated. |
| 80 | + */ |
| 81 | + fun domain(domain: String) = apply { this.domain = domain } |
| 82 | + |
| 83 | + /** |
| 84 | + * Optional parameter to determine screenshot type. If 'true', takes a full page screenshot |
| 85 | + * capturing all content. If 'false' or not provided, takes a viewport screenshot (standard |
| 86 | + * browser view). |
| 87 | + */ |
| 88 | + fun fullScreenshot(fullScreenshot: FullScreenshot?) = apply { |
| 89 | + this.fullScreenshot = fullScreenshot |
| 90 | + } |
| 91 | + |
| 92 | + /** Alias for calling [Builder.fullScreenshot] with `fullScreenshot.orElse(null)`. */ |
| 93 | + fun fullScreenshot(fullScreenshot: Optional<FullScreenshot>) = |
| 94 | + fullScreenshot(fullScreenshot.getOrNull()) |
| 95 | + |
| 96 | + fun additionalHeaders(additionalHeaders: Headers) = apply { |
| 97 | + this.additionalHeaders.clear() |
| 98 | + putAllAdditionalHeaders(additionalHeaders) |
| 99 | + } |
| 100 | + |
| 101 | + fun additionalHeaders(additionalHeaders: Map<String, Iterable<String>>) = apply { |
| 102 | + this.additionalHeaders.clear() |
| 103 | + putAllAdditionalHeaders(additionalHeaders) |
| 104 | + } |
| 105 | + |
| 106 | + fun putAdditionalHeader(name: String, value: String) = apply { |
| 107 | + additionalHeaders.put(name, value) |
| 108 | + } |
| 109 | + |
| 110 | + fun putAdditionalHeaders(name: String, values: Iterable<String>) = apply { |
| 111 | + additionalHeaders.put(name, values) |
| 112 | + } |
| 113 | + |
| 114 | + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { |
| 115 | + this.additionalHeaders.putAll(additionalHeaders) |
| 116 | + } |
| 117 | + |
| 118 | + fun putAllAdditionalHeaders(additionalHeaders: Map<String, Iterable<String>>) = apply { |
| 119 | + this.additionalHeaders.putAll(additionalHeaders) |
| 120 | + } |
| 121 | + |
| 122 | + fun replaceAdditionalHeaders(name: String, value: String) = apply { |
| 123 | + additionalHeaders.replace(name, value) |
| 124 | + } |
| 125 | + |
| 126 | + fun replaceAdditionalHeaders(name: String, values: Iterable<String>) = apply { |
| 127 | + additionalHeaders.replace(name, values) |
| 128 | + } |
| 129 | + |
| 130 | + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { |
| 131 | + this.additionalHeaders.replaceAll(additionalHeaders) |
| 132 | + } |
| 133 | + |
| 134 | + fun replaceAllAdditionalHeaders(additionalHeaders: Map<String, Iterable<String>>) = apply { |
| 135 | + this.additionalHeaders.replaceAll(additionalHeaders) |
| 136 | + } |
| 137 | + |
| 138 | + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } |
| 139 | + |
| 140 | + fun removeAllAdditionalHeaders(names: Set<String>) = apply { |
| 141 | + additionalHeaders.removeAll(names) |
| 142 | + } |
| 143 | + |
| 144 | + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { |
| 145 | + this.additionalQueryParams.clear() |
| 146 | + putAllAdditionalQueryParams(additionalQueryParams) |
| 147 | + } |
| 148 | + |
| 149 | + fun additionalQueryParams(additionalQueryParams: Map<String, Iterable<String>>) = apply { |
| 150 | + this.additionalQueryParams.clear() |
| 151 | + putAllAdditionalQueryParams(additionalQueryParams) |
| 152 | + } |
| 153 | + |
| 154 | + fun putAdditionalQueryParam(key: String, value: String) = apply { |
| 155 | + additionalQueryParams.put(key, value) |
| 156 | + } |
| 157 | + |
| 158 | + fun putAdditionalQueryParams(key: String, values: Iterable<String>) = apply { |
| 159 | + additionalQueryParams.put(key, values) |
| 160 | + } |
| 161 | + |
| 162 | + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { |
| 163 | + this.additionalQueryParams.putAll(additionalQueryParams) |
| 164 | + } |
| 165 | + |
| 166 | + fun putAllAdditionalQueryParams(additionalQueryParams: Map<String, Iterable<String>>) = |
| 167 | + apply { |
| 168 | + this.additionalQueryParams.putAll(additionalQueryParams) |
| 169 | + } |
| 170 | + |
| 171 | + fun replaceAdditionalQueryParams(key: String, value: String) = apply { |
| 172 | + additionalQueryParams.replace(key, value) |
| 173 | + } |
| 174 | + |
| 175 | + fun replaceAdditionalQueryParams(key: String, values: Iterable<String>) = apply { |
| 176 | + additionalQueryParams.replace(key, values) |
| 177 | + } |
| 178 | + |
| 179 | + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { |
| 180 | + this.additionalQueryParams.replaceAll(additionalQueryParams) |
| 181 | + } |
| 182 | + |
| 183 | + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map<String, Iterable<String>>) = |
| 184 | + apply { |
| 185 | + this.additionalQueryParams.replaceAll(additionalQueryParams) |
| 186 | + } |
| 187 | + |
| 188 | + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } |
| 189 | + |
| 190 | + fun removeAllAdditionalQueryParams(keys: Set<String>) = apply { |
| 191 | + additionalQueryParams.removeAll(keys) |
| 192 | + } |
| 193 | + |
| 194 | + /** |
| 195 | + * Returns an immutable instance of [BrandScreenshotParams]. |
| 196 | + * |
| 197 | + * Further updates to this [Builder] will not mutate the returned instance. |
| 198 | + * |
| 199 | + * The following fields are required: |
| 200 | + * ```java |
| 201 | + * .domain() |
| 202 | + * ``` |
| 203 | + * |
| 204 | + * @throws IllegalStateException if any required field is unset. |
| 205 | + */ |
| 206 | + fun build(): BrandScreenshotParams = |
| 207 | + BrandScreenshotParams( |
| 208 | + checkRequired("domain", domain), |
| 209 | + fullScreenshot, |
| 210 | + additionalHeaders.build(), |
| 211 | + additionalQueryParams.build(), |
| 212 | + ) |
| 213 | + } |
| 214 | + |
| 215 | + override fun _headers(): Headers = additionalHeaders |
| 216 | + |
| 217 | + override fun _queryParams(): QueryParams = |
| 218 | + QueryParams.builder() |
| 219 | + .apply { |
| 220 | + put("domain", domain) |
| 221 | + fullScreenshot?.let { put("fullScreenshot", it.toString()) } |
| 222 | + putAll(additionalQueryParams) |
| 223 | + } |
| 224 | + .build() |
| 225 | + |
| 226 | + /** |
| 227 | + * Optional parameter to determine screenshot type. If 'true', takes a full page screenshot |
| 228 | + * capturing all content. If 'false' or not provided, takes a viewport screenshot (standard |
| 229 | + * browser view). |
| 230 | + */ |
| 231 | + class FullScreenshot @JsonCreator private constructor(private val value: JsonField<String>) : |
| 232 | + Enum { |
| 233 | + |
| 234 | + /** |
| 235 | + * Returns this class instance's raw value. |
| 236 | + * |
| 237 | + * This is usually only useful if this instance was deserialized from data that doesn't |
| 238 | + * match any known member, and you want to know that value. For example, if the SDK is on an |
| 239 | + * older version than the API, then the API may respond with new members that the SDK is |
| 240 | + * unaware of. |
| 241 | + */ |
| 242 | + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value |
| 243 | + |
| 244 | + companion object { |
| 245 | + |
| 246 | + @JvmField val TRUE = of("true") |
| 247 | + |
| 248 | + @JvmField val FALSE = of("false") |
| 249 | + |
| 250 | + @JvmStatic fun of(value: String) = FullScreenshot(JsonField.of(value)) |
| 251 | + } |
| 252 | + |
| 253 | + /** An enum containing [FullScreenshot]'s known values. */ |
| 254 | + enum class Known { |
| 255 | + TRUE, |
| 256 | + FALSE, |
| 257 | + } |
| 258 | + |
| 259 | + /** |
| 260 | + * An enum containing [FullScreenshot]'s known values, as well as an [_UNKNOWN] member. |
| 261 | + * |
| 262 | + * An instance of [FullScreenshot] can contain an unknown value in a couple of cases: |
| 263 | + * - It was deserialized from data that doesn't match any known member. For example, if the |
| 264 | + * SDK is on an older version than the API, then the API may respond with new members that |
| 265 | + * the SDK is unaware of. |
| 266 | + * - It was constructed with an arbitrary value using the [of] method. |
| 267 | + */ |
| 268 | + enum class Value { |
| 269 | + TRUE, |
| 270 | + FALSE, |
| 271 | + /** |
| 272 | + * An enum member indicating that [FullScreenshot] was instantiated with an unknown |
| 273 | + * value. |
| 274 | + */ |
| 275 | + _UNKNOWN, |
| 276 | + } |
| 277 | + |
| 278 | + /** |
| 279 | + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] |
| 280 | + * if the class was instantiated with an unknown value. |
| 281 | + * |
| 282 | + * Use the [known] method instead if you're certain the value is always known or if you want |
| 283 | + * to throw for the unknown case. |
| 284 | + */ |
| 285 | + fun value(): Value = |
| 286 | + when (this) { |
| 287 | + TRUE -> Value.TRUE |
| 288 | + FALSE -> Value.FALSE |
| 289 | + else -> Value._UNKNOWN |
| 290 | + } |
| 291 | + |
| 292 | + /** |
| 293 | + * Returns an enum member corresponding to this class instance's value. |
| 294 | + * |
| 295 | + * Use the [value] method instead if you're uncertain the value is always known and don't |
| 296 | + * want to throw for the unknown case. |
| 297 | + * |
| 298 | + * @throws BrandDevInvalidDataException if this class instance's value is a not a known |
| 299 | + * member. |
| 300 | + */ |
| 301 | + fun known(): Known = |
| 302 | + when (this) { |
| 303 | + TRUE -> Known.TRUE |
| 304 | + FALSE -> Known.FALSE |
| 305 | + else -> throw BrandDevInvalidDataException("Unknown FullScreenshot: $value") |
| 306 | + } |
| 307 | + |
| 308 | + /** |
| 309 | + * Returns this class instance's primitive wire representation. |
| 310 | + * |
| 311 | + * This differs from the [toString] method because that method is primarily for debugging |
| 312 | + * and generally doesn't throw. |
| 313 | + * |
| 314 | + * @throws BrandDevInvalidDataException if this class instance's value does not have the |
| 315 | + * expected primitive type. |
| 316 | + */ |
| 317 | + fun asString(): String = |
| 318 | + _value().asString().orElseThrow { |
| 319 | + BrandDevInvalidDataException("Value is not a String") |
| 320 | + } |
| 321 | + |
| 322 | + private var validated: Boolean = false |
| 323 | + |
| 324 | + fun validate(): FullScreenshot = apply { |
| 325 | + if (validated) { |
| 326 | + return@apply |
| 327 | + } |
| 328 | + |
| 329 | + known() |
| 330 | + validated = true |
| 331 | + } |
| 332 | + |
| 333 | + fun isValid(): Boolean = |
| 334 | + try { |
| 335 | + validate() |
| 336 | + true |
| 337 | + } catch (e: BrandDevInvalidDataException) { |
| 338 | + false |
| 339 | + } |
| 340 | + |
| 341 | + /** |
| 342 | + * Returns a score indicating how many valid values are contained in this object |
| 343 | + * recursively. |
| 344 | + * |
| 345 | + * Used for best match union deserialization. |
| 346 | + */ |
| 347 | + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 |
| 348 | + |
| 349 | + override fun equals(other: Any?): Boolean { |
| 350 | + if (this === other) { |
| 351 | + return true |
| 352 | + } |
| 353 | + |
| 354 | + return /* spotless:off */ other is FullScreenshot && value == other.value /* spotless:on */ |
| 355 | + } |
| 356 | + |
| 357 | + override fun hashCode() = value.hashCode() |
| 358 | + |
| 359 | + override fun toString() = value.toString() |
| 360 | + } |
| 361 | + |
| 362 | + override fun equals(other: Any?): Boolean { |
| 363 | + if (this === other) { |
| 364 | + return true |
| 365 | + } |
| 366 | + |
| 367 | + return /* spotless:off */ other is BrandScreenshotParams && domain == other.domain && fullScreenshot == other.fullScreenshot && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ |
| 368 | + } |
| 369 | + |
| 370 | + override fun hashCode(): Int = /* spotless:off */ Objects.hash(domain, fullScreenshot, additionalHeaders, additionalQueryParams) /* spotless:on */ |
| 371 | + |
| 372 | + override fun toString() = |
| 373 | + "BrandScreenshotParams{domain=$domain, fullScreenshot=$fullScreenshot, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" |
| 374 | +} |
0 commit comments