Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// File generated from our OpenAPI spec by Stainless.

package com.google.genai.interactions.models.interactions

import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonAnySetter
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import com.google.genai.interactions.core.ExcludeMissing
import com.google.genai.interactions.core.JsonField
import com.google.genai.interactions.core.JsonMissing
import com.google.genai.interactions.core.JsonValue
import com.google.genai.interactions.core.checkKnown
import com.google.genai.interactions.core.checkRequired
import com.google.genai.interactions.core.toImmutable
import com.google.genai.interactions.errors.GeminiNextGenApiInvalidDataException
import java.util.Collections
import java.util.Objects
import java.util.Optional
import kotlin.jvm.optionals.getOrNull

class GoogleSearchResultDelta
@JsonCreator(mode = JsonCreator.Mode.DISABLED)
private constructor(
private val result: JsonField<List<GoogleSearchResult>>,
private val type: JsonValue,
private val isError: JsonField<Boolean>,
private val signature: JsonField<String>,
private val additionalProperties: MutableMap<String, JsonValue>,
) {

@JsonCreator
private constructor(
@JsonProperty("result")
@ExcludeMissing
result: JsonField<List<GoogleSearchResult>> = JsonMissing.of(),
@JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(),
@JsonProperty("is_error") @ExcludeMissing isError: JsonField<Boolean> = JsonMissing.of(),
@JsonProperty("signature") @ExcludeMissing signature: JsonField<String> = JsonMissing.of(),
) : this(result, type, isError, signature, mutableMapOf())

/**
* @throws GeminiNextGenApiInvalidDataException if the JSON field has an unexpected type or is
* unexpectedly missing or null (e.g. if the server responded with an unexpected value).
*/
fun result(): List<GoogleSearchResult> = result.getRequired("result")

/**
* Expected to always return the following:
* ```java
* JsonValue.from("google_search_result")
* ```
*
* However, this method can be useful for debugging and logging (e.g. if the server responded
* with an unexpected value).
*/
@JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type

/**
* @throws GeminiNextGenApiInvalidDataException if the JSON field has an unexpected type (e.g.
* if the server responded with an unexpected value).
*/
fun isError(): Optional<Boolean> = isError.getOptional("is_error")

/**
* A signature hash for backend validation.
*
* @throws GeminiNextGenApiInvalidDataException if the JSON field has an unexpected type (e.g.
* if the server responded with an unexpected value).
*/
fun signature(): Optional<String> = signature.getOptional("signature")

/**
* Returns the raw JSON value of [result].
*
* Unlike [result], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("result")
@ExcludeMissing
fun _result(): JsonField<List<GoogleSearchResult>> = result

/**
* Returns the raw JSON value of [isError].
*
* Unlike [isError], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("is_error") @ExcludeMissing fun _isError(): JsonField<Boolean> = isError

/**
* Returns the raw JSON value of [signature].
*
* Unlike [signature], this method doesn't throw if the JSON field has an unexpected type.
*/
@JsonProperty("signature") @ExcludeMissing fun _signature(): JsonField<String> = signature

@JsonAnySetter
private fun putAdditionalProperty(key: String, value: JsonValue) {
additionalProperties.put(key, value)
}

@JsonAnyGetter
@ExcludeMissing
fun _additionalProperties(): Map<String, JsonValue> =
Collections.unmodifiableMap(additionalProperties)

fun toBuilder() = Builder().from(this)

companion object {

/**
* Returns a mutable builder for constructing an instance of [GoogleSearchResultDelta].
*
* The following fields are required:
* ```java
* .result()
* ```
*/
@JvmStatic fun builder() = Builder()
}

/** A builder for [GoogleSearchResultDelta]. */
class Builder internal constructor() {

private var result: JsonField<MutableList<GoogleSearchResult>>? = null
private var type: JsonValue = JsonValue.from("google_search_result")
private var isError: JsonField<Boolean> = JsonMissing.of()
private var signature: JsonField<String> = JsonMissing.of()
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

@JvmSynthetic
internal fun from(googleSearchResultDelta: GoogleSearchResultDelta) = apply {
result = googleSearchResultDelta.result.map { it.toMutableList() }
type = googleSearchResultDelta.type
isError = googleSearchResultDelta.isError
signature = googleSearchResultDelta.signature
additionalProperties = googleSearchResultDelta.additionalProperties.toMutableMap()
}

fun result(result: List<GoogleSearchResult>) = result(JsonField.of(result))

/**
* Sets [Builder.result] to an arbitrary JSON value.
*
* You should usually call [Builder.result] with a well-typed `List<GoogleSearchResult>`
* value instead. This method is primarily for setting the field to an undocumented or not
* yet supported value.
*/
fun result(result: JsonField<List<GoogleSearchResult>>) = apply {
this.result = result.map { it.toMutableList() }
}

/**
* Adds a single [GoogleSearchResult] to [Builder.result].
*
* @throws IllegalStateException if the field was previously set to a non-list.
*/
fun addResult(result: GoogleSearchResult) = apply {
this.result =
(this.result ?: JsonField.of(mutableListOf())).also {
checkKnown("result", it).add(result)
}
}

/**
* Sets the field to an arbitrary JSON value.
*
* It is usually unnecessary to call this method because the field defaults to the
* following:
* ```java
* JsonValue.from("google_search_result")
* ```
*
* This method is primarily for setting the field to an undocumented or not yet supported
* value.
*/
fun type(type: JsonValue) = apply { this.type = type }

fun isError(isError: Boolean) = isError(JsonField.of(isError))

/**
* Sets [Builder.isError] to an arbitrary JSON value.
*
* You should usually call [Builder.isError] with a well-typed [Boolean] value instead. This
* method is primarily for setting the field to an undocumented or not yet supported value.
*/
fun isError(isError: JsonField<Boolean>) = apply { this.isError = isError }

/** A signature hash for backend validation. */
fun signature(signature: String) = signature(JsonField.of(signature))

/**
* Sets [Builder.signature] to an arbitrary JSON value.
*
* You should usually call [Builder.signature] with a well-typed [String] value instead.
* This method is primarily for setting the field to an undocumented or not yet supported
* value.
*/
fun signature(signature: JsonField<String>) = apply { this.signature = signature }

fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
this.additionalProperties.clear()
putAllAdditionalProperties(additionalProperties)
}

fun putAdditionalProperty(key: String, value: JsonValue) = apply {
additionalProperties.put(key, value)
}

fun putAllAdditionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
this.additionalProperties.putAll(additionalProperties)
}

fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }

fun removeAllAdditionalProperties(keys: Set<String>) = apply {
keys.forEach(::removeAdditionalProperty)
}

/**
* Returns an immutable instance of [GoogleSearchResultDelta].
*
* Further updates to this [Builder] will not mutate the returned instance.
*
* The following fields are required:
* ```java
* .result()
* ```
*
* @throws IllegalStateException if any required field is unset.
*/
fun build(): GoogleSearchResultDelta =
GoogleSearchResultDelta(
checkRequired("result", result).map { it.toImmutable() },
type,
isError,
signature,
additionalProperties.toMutableMap(),
)
}

private var validated: Boolean = false

fun validate(): GoogleSearchResultDelta = apply {
if (validated) {
return@apply
}

result().forEach { it.validate() }
_type().let {
if (it != JsonValue.from("google_search_result")) {
throw GeminiNextGenApiInvalidDataException("'type' is invalid, received $it")
}
}
isError()
signature()
validated = true
}

fun isValid(): Boolean =
try {
validate()
true
} catch (e: GeminiNextGenApiInvalidDataException) {
false
}

/**
* Returns a score indicating how many valid values are contained in this object recursively.
*
* Used for best match union deserialization.
*/
@JvmSynthetic
internal fun validity(): Int =
(result.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
type.let { if (it == JsonValue.from("google_search_result")) 1 else 0 } +
(if (isError.asKnown().isPresent) 1 else 0) +
(if (signature.asKnown().isPresent) 1 else 0)

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return other is GoogleSearchResultDelta &&
result == other.result &&
type == other.type &&
isError == other.isError &&
signature == other.signature &&
additionalProperties == other.additionalProperties
}

private val hashCode: Int by lazy {
Objects.hash(result, type, isError, signature, additionalProperties)
}

override fun hashCode(): Int = hashCode

override fun toString() =
"GoogleSearchResultDelta{result=$result, type=$type, isError=$isError, signature=$signature, additionalProperties=$additionalProperties}"
}
Loading
Loading