// Code generated by sidekick. DO NOT EDIT.
//
// Copyright 2026 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
//
//     https://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.

#if GroundedGenerationService
  import Foundation
  import GoogleCloudWkt

  /// Top-level message sent by the client for the `GenerateGroundedContent`
  /// method.
  public struct GenerateGroundedContentRequest: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. Location resource.
    ///
    /// Format: `projects/{project}/locations/{location}`.
    public var location: Swift.String = Swift.String()

    /// Content of the system instruction for the current API.
    ///
    /// These instructions will take priority over any other prompt instructions
    /// if the selected model is supporting them.
    public var systemInstruction: GroundedGenerationContent? = nil

    /// Content of the current conversation with the model.
    ///
    /// For single-turn queries, this is a single instance. For multi-turn queries,
    /// this is a repeated field that contains conversation history + latest
    /// request.
    public var contents: [GroundedGenerationContent] = []

    /// Content generation specification.
    public var generationSpec: GenerateGroundedContentRequest.GenerationSpec? = nil

    /// Grounding specification.
    public var groundingSpec: GenerateGroundedContentRequest.GroundingSpec? = nil

    /// The user labels applied to a resource must meet the following requirements:
    ///
    /// * Each resource can have multiple labels, up to a maximum of 64.
    /// * Each label must be a key-value pair.
    /// * Keys have a minimum length of 1 character and a maximum length of 63
    ///   characters and cannot be empty. Values can be empty and have a maximum
    ///   length of 63 characters.
    /// * Keys and values can contain only lowercase letters, numeric characters,
    ///   underscores, and dashes. All characters must use UTF-8 encoding, and
    ///   international characters are allowed.
    /// * The key portion of a label must be unique. However, you can use the same
    ///   key with multiple resources.
    /// * Keys must start with a lowercase letter or international character.
    ///
    /// See [Google Cloud
    /// Document](https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements)
    /// for more details.
    public var userLabels: [Swift.String: Swift.String] = [:]

    /// Initialize a new instance of `GenerateGroundedContentRequest`.
    public init() {}

    /// Use `config` to return a new instance of this object, with some fields updated.
    ///
    /// Commonly used to initialize the value, for example:
    ///
    /// ```
    /// let value = GenerateGroundedContentRequest().with { $0.location = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

    /// Content generation specification.
    public struct GenerationSpec: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Specifies which Vertex model id to use for generation.
      public var modelId: Swift.String = Swift.String()

      /// Language code for content. Use language tags defined by
      /// [BCP47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt).
      public var languageCode: Swift.String = Swift.String()

      /// If specified, custom value for the temperature will be used.
      public var temperature: Swift.Float? = nil

      /// If specified, custom value for nucleus sampling will be used.
      public var topP: Swift.Float? = nil

      /// If specified, custom value for top-k sampling will be used.
      public var topK: Swift.Int32? = nil

      /// If specified, custom value for frequency penalty will be used.
      public var frequencyPenalty: Swift.Float? = nil

      /// If specified, custom value for the seed will be used.
      public var seed: Swift.Int32? = nil

      /// If specified, custom value for presence penalty will be used.
      public var presencePenalty: Swift.Float? = nil

      /// If specified, custom value for max output tokens will be used.
      public var maxOutputTokens: Swift.Int32? = nil

      /// Initialize a new instance of `GenerationSpec`.
      public init() {}

      /// Use `config` to return a new instance of this object, with some fields updated.
      ///
      /// Commonly used to initialize the value, for example:
      ///
      /// ```
      /// let value = GenerationSpec().with { $0.modelId = ... }
      /// ```
      public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
        var copy = self
        try config(&copy)
        return copy
      }

      public static var _anyTypeUrl: Swift.String {
        return
          "type.googleapis.com/google.cloud.discoveryengine.v1.GenerateGroundedContentRequest.GenerationSpec"
      }
      public init(fromAny any: GoogleCloudWkt.`Any`) throws {
        self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
      }
      public func _pack() throws -> GoogleCloudWkt.Struct {
        return try GoogleCloudWkt._slowAnySerialize(message: self)
      }
    }

    /// Describes the options to customize dynamic retrieval.
    public struct DynamicRetrievalConfiguration: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Specification for the predictor for dynamic retrieval.
      public var predictor:
        GenerateGroundedContentRequest.DynamicRetrievalConfiguration.DynamicRetrievalPredictor? =
          nil

      /// Initialize a new instance of `DynamicRetrievalConfiguration`.
      public init() {}

      /// Use `config` to return a new instance of this object, with some fields updated.
      ///
      /// Commonly used to initialize the value, for example:
      ///
      /// ```
      /// let value = DynamicRetrievalConfiguration().with { $0.predictor = ... }
      /// ```
      public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
        var copy = self
        try config(&copy)
        return copy
      }

      /// Describes the predictor settings for dynamic retrieval.
      public struct DynamicRetrievalPredictor: Codable, Equatable, GoogleCloudWkt._AnyPackable,
        Sendable
      {
        /// The version of the predictor to be used in dynamic retrieval.
        public var version:
          GenerateGroundedContentRequest.DynamicRetrievalConfiguration.DynamicRetrievalPredictor
            .Version = GenerateGroundedContentRequest.DynamicRetrievalConfiguration
            .DynamicRetrievalPredictor.Version()

        /// The value of the threshold. If the predictor will predict a
        /// value smaller than this, it would suppress grounding in the source.
        public var threshold: Swift.Float? = nil

        /// Initialize a new instance of `DynamicRetrievalPredictor`.
        public init() {}

        /// Use `config` to return a new instance of this object, with some fields updated.
        ///
        /// Commonly used to initialize the value, for example:
        ///
        /// ```
        /// let value = DynamicRetrievalPredictor().with { $0.version = ... }
        /// ```
        public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
          var copy = self
          try config(&copy)
          return copy
        }

        /// The version of the predictor to be used in dynamic retrieval.
        public enum Version: Codable, Equatable, Sendable {
          /// Automatically choose the best version of the retrieval predictor.
          case unspecified
          /// The V1 model which is evaluating each source independently.
          case v1Independent
          /// Encodes an unknown integer value.
          ///
          /// The most common cause for an unknown values is for the service to send
          /// a value unknown to the library. We recommend you update your library to
          /// the latest version.
          case unknownIntValue(Int)
          /// Encodes an unknown string value.
          ///
          /// The most common cause for an unknown values is for the service to send
          /// a value unknown to the library. We recommend you update your library to
          /// the latest version.
          case unknownStringValue(String)

          public init() {
            self = .unspecified
          }

          /// Returns the integer value associated with the enumeration.
          ///
          /// If the enumeration was initialized with an unknown string value, this returns `nil`.
          public var intValue: Int? {
            switch self {
            case .unspecified: return 0
            case .v1Independent: return 1
            case .unknownIntValue(let v): return v
            case .unknownStringValue: return nil
            }
          }

          /// Returns the string value (or name) associated with the enumeration.
          ///
          /// If the enumeration was initialized with an unknown integer value, this returns `nil`.
          public var stringValue: Swift.String? {
            switch self {
            case .unspecified: return "VERSION_UNSPECIFIED"
            case .v1Independent: return "V1_INDEPENDENT"
            case .unknownIntValue: return nil
            case .unknownStringValue(let v): return v
            }
          }

          /// Initialize from a string value.
          ///
          /// If the value is unknown, this initializes to [`unknownStringValue`](doc:Version/unknownStringValue(_:)).
          public init(stringValue: Swift.String) {
            switch stringValue {
            case "VERSION_UNSPECIFIED": self = .unspecified
            case "V1_INDEPENDENT": self = .v1Independent
            default: self = .unknownStringValue(stringValue)
            }
          }

          /// Initialize from an integer value.
          ///
          /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Version/unknownIntValue(_:)).
          public init(intValue: Int) {
            switch intValue {
            case 0: self = .unspecified
            case 1: self = .v1Independent
            default: self = .unknownIntValue(intValue)
            }
          }

          public init(from decoder: Decoder) throws {
            let container = try decoder.singleValueContainer()
            if let v = try? container.decode(Int.self) {
              self.init(intValue: v)
              return
            }
            if let s = try? container.decode(String.self) {
              if let v = Int(s) {
                self.init(intValue: v)
              } else {
                self.init(stringValue: s)
              }
              return
            }
            throw DecodingError.dataCorruptedError(
              in: container, debugDescription: "Expected enum value, must be integer or string.")
          }

          public func encode(to encoder: Encoder) throws {
            var container = encoder.singleValueContainer()
            switch self {
            case .unspecified: return try container.encode(0)
            case .v1Independent: return try container.encode(1)
            case .unknownIntValue(let v): return try container.encode(v)
            case .unknownStringValue(let v): return try container.encode(v)
            }
          }
        }

        public static var _anyTypeUrl: Swift.String {
          return
            "type.googleapis.com/google.cloud.discoveryengine.v1.GenerateGroundedContentRequest.DynamicRetrievalConfiguration.DynamicRetrievalPredictor"
        }
        public init(fromAny any: GoogleCloudWkt.`Any`) throws {
          self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
        }
        public func _pack() throws -> GoogleCloudWkt.Struct {
          return try GoogleCloudWkt._slowAnySerialize(message: self)
        }
      }

      public static var _anyTypeUrl: Swift.String {
        return
          "type.googleapis.com/google.cloud.discoveryengine.v1.GenerateGroundedContentRequest.DynamicRetrievalConfiguration"
      }
      public init(fromAny any: GoogleCloudWkt.`Any`) throws {
        self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
      }
      public func _pack() throws -> GoogleCloudWkt.Struct {
        return try GoogleCloudWkt._slowAnySerialize(message: self)
      }
    }

    /// Grounding source.
    public struct GroundingSource: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Sources.
      public var source: OneOf_Source? = nil

      /// Initialize a new instance of `GroundingSource`.
      public init() {}

      /// Use `config` to return a new instance of this object, with some fields updated.
      ///
      /// Commonly used to initialize the value, for example:
      ///
      /// ```
      /// let value = GroundingSource().with { $0.inlineSource = ... }
      /// ```
      public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
        var copy = self
        try config(&copy)
        return copy
      }

      private enum CodingKeys: Swift.String, CodingKey {
        case inlineSource = "inlineSource"
        case searchSource = "searchSource"
        case googleSearchSource = "googleSearchSource"
        case enterpriseWebRetrievalSource = "enterpriseWebRetrievalSource"
      }

      public init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)

        var source: OneOf_Source? = nil
        let sourceCheckAndSet = {
          if source != nil {
            throw DecodingError.dataCorrupted(
              DecodingError.Context(
                codingPath: decoder.codingPath,
                debugDescription: "Multiple values set for oneof 'source'"))
          }
          source = $0
        }
        if let inlineSource = try container.decodeIfPresent(
          GenerateGroundedContentRequest.GroundingSource.InlineSource?.self, forKey: .inlineSource)
        {
          try sourceCheckAndSet(.inlineSource(inlineSource))
        }
        if let searchSource = try container.decodeIfPresent(
          GenerateGroundedContentRequest.GroundingSource.SearchSource?.self, forKey: .searchSource)
        {
          try sourceCheckAndSet(.searchSource(searchSource))
        }
        if let googleSearchSource = try container.decodeIfPresent(
          GenerateGroundedContentRequest.GroundingSource.GoogleSearchSource?.self,
          forKey: .googleSearchSource)
        {
          try sourceCheckAndSet(.googleSearchSource(googleSearchSource))
        }
        if let enterpriseWebRetrievalSource = try container.decodeIfPresent(
          GenerateGroundedContentRequest.GroundingSource.EnterpriseWebRetrievalSource?.self,
          forKey: .enterpriseWebRetrievalSource)
        {
          try sourceCheckAndSet(.enterpriseWebRetrievalSource(enterpriseWebRetrievalSource))
        }
        self.source = source
      }

      public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)

        if let choice = self.source {
          switch choice {
          case .inlineSource(let value):
            try container.encode(value, forKey: .inlineSource)
          case .searchSource(let value):
            try container.encode(value, forKey: .searchSource)
          case .googleSearchSource(let value):
            try container.encode(value, forKey: .googleSearchSource)
          case .enterpriseWebRetrievalSource(let value):
            try container.encode(value, forKey: .enterpriseWebRetrievalSource)
          }
        }
      }

      /// Message to be used for grounding based on inline content.
      public struct InlineSource: Codable, Equatable, GoogleCloudWkt._AnyPackable,
        Sendable
      {
        /// List of facts to be used for grounding.
        public var groundingFacts: [GroundingFact] = []

        /// Attributes associated with the content.
        ///
        /// Common attributes include `source` (indicating where the content was
        /// sourced from) and `author` (indicating the author of the content).
        public var attributes: [Swift.String: Swift.String] = [:]

        /// Initialize a new instance of `InlineSource`.
        public init() {}

        /// Use `config` to return a new instance of this object, with some fields updated.
        ///
        /// Commonly used to initialize the value, for example:
        ///
        /// ```
        /// let value = InlineSource().with { $0.groundingFacts = ... }
        /// ```
        public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
          var copy = self
          try config(&copy)
          return copy
        }

        public static var _anyTypeUrl: Swift.String {
          return
            "type.googleapis.com/google.cloud.discoveryengine.v1.GenerateGroundedContentRequest.GroundingSource.InlineSource"
        }
        public init(fromAny any: GoogleCloudWkt.`Any`) throws {
          self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
        }
        public func _pack() throws -> GoogleCloudWkt.Struct {
          return try GoogleCloudWkt._slowAnySerialize(message: self)
        }
      }

      /// Message to be used for grounding with Vertex AI Search.
      public struct SearchSource: Codable, Equatable, GoogleCloudWkt._AnyPackable,
        Sendable
      {
        /// The resource name of the Engine to use.
        ///
        /// Format:
        /// `projects/{project}/locations/{location}/collections/{collection_id}/engines/{engine_id}/servingConfigs/{serving_config_id}`
        public var servingConfig: Swift.String = Swift.String()

        /// Number of search results to return.
        ///
        /// The default value is 10. The maximumm allowed value is 10.
        public var maxResultCount: Swift.Int32 = Swift.Int32()

        /// Filter expression to be applied to the search.
        ///
        /// The syntax is the same as
        /// [SearchRequest.filter][google.cloud.discoveryengine.v1.SearchRequest.filter].
        ///
        /// [google.cloud.discoveryengine.v1.SearchRequest.filter]: <doc:SearchRequest/filter>
        public var filter: Swift.String = Swift.String()

        /// If set, safe search is enabled in Vertex AI Search requests.
        public var safeSearch: Swift.Bool = Swift.Bool()

        /// Initialize a new instance of `SearchSource`.
        public init() {}

        /// Use `config` to return a new instance of this object, with some fields updated.
        ///
        /// Commonly used to initialize the value, for example:
        ///
        /// ```
        /// let value = SearchSource().with { $0.servingConfig = ... }
        /// ```
        public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
          var copy = self
          try config(&copy)
          return copy
        }

        public static var _anyTypeUrl: Swift.String {
          return
            "type.googleapis.com/google.cloud.discoveryengine.v1.GenerateGroundedContentRequest.GroundingSource.SearchSource"
        }
        public init(fromAny any: GoogleCloudWkt.`Any`) throws {
          self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
        }
        public func _pack() throws -> GoogleCloudWkt.Struct {
          return try GoogleCloudWkt._slowAnySerialize(message: self)
        }
      }

      /// Google Search config parameters.
      public struct GoogleSearchSource: Codable, Equatable, GoogleCloudWkt._AnyPackable,
        Sendable
      {
        /// Optional. Specifies the dynamic retrieval configuration for the given
        /// source.
        public var dynamicRetrievalConfig:
          GenerateGroundedContentRequest.DynamicRetrievalConfiguration? = nil

        /// Initialize a new instance of `GoogleSearchSource`.
        public init() {}

        /// Use `config` to return a new instance of this object, with some fields updated.
        ///
        /// Commonly used to initialize the value, for example:
        ///
        /// ```
        /// let value = GoogleSearchSource().with { $0.dynamicRetrievalConfig = ... }
        /// ```
        public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
          var copy = self
          try config(&copy)
          return copy
        }

        public static var _anyTypeUrl: Swift.String {
          return
            "type.googleapis.com/google.cloud.discoveryengine.v1.GenerateGroundedContentRequest.GroundingSource.GoogleSearchSource"
        }
        public init(fromAny any: GoogleCloudWkt.`Any`) throws {
          self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
        }
        public func _pack() throws -> GoogleCloudWkt.Struct {
          return try GoogleCloudWkt._slowAnySerialize(message: self)
        }
      }

      /// Params for using enterprise web retrieval as grounding source.
      public struct EnterpriseWebRetrievalSource: Codable, Equatable, GoogleCloudWkt._AnyPackable,
        Sendable
      {
        /// Initialize a new instance of `EnterpriseWebRetrievalSource`.
        public init() {}

        /// Use `config` to return a new instance of this object, with some fields updated.
        ///
        /// Commonly used to initialize the value, for example:
        ///
        /// ```
        /// let value = EnterpriseWebRetrievalSource().with { $0.<placeholder> = ... }
        /// ```
        public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
          var copy = self
          try config(&copy)
          return copy
        }

        public static var _anyTypeUrl: Swift.String {
          return
            "type.googleapis.com/google.cloud.discoveryengine.v1.GenerateGroundedContentRequest.GroundingSource.EnterpriseWebRetrievalSource"
        }
        public init(fromAny any: GoogleCloudWkt.`Any`) throws {
          self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
        }
        public func _pack() throws -> GoogleCloudWkt.Struct {
          return try GoogleCloudWkt._slowAnySerialize(message: self)
        }
      }

      /// Sources.
      public enum OneOf_Source: Codable, Equatable, Sendable {
        /// If set, grounding is performed with inline content.
        indirect case inlineSource(GenerateGroundedContentRequest.GroundingSource.InlineSource?)
        /// If set, grounding is performed with Vertex AI Search.
        indirect case searchSource(GenerateGroundedContentRequest.GroundingSource.SearchSource?)
        /// If set, grounding is performed with Google Search.
        indirect case googleSearchSource(
          GenerateGroundedContentRequest.GroundingSource.GoogleSearchSource?)
        /// If set, grounding is performed with enterprise web retrieval.
        indirect case enterpriseWebRetrievalSource(
          GenerateGroundedContentRequest.GroundingSource.EnterpriseWebRetrievalSource?)
      }

      public static var _anyTypeUrl: Swift.String {
        return
          "type.googleapis.com/google.cloud.discoveryengine.v1.GenerateGroundedContentRequest.GroundingSource"
      }
      public init(fromAny any: GoogleCloudWkt.`Any`) throws {
        self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
      }
      public func _pack() throws -> GoogleCloudWkt.Struct {
        return try GoogleCloudWkt._slowAnySerialize(message: self)
      }
    }

    /// Grounding specification.
    public struct GroundingSpec: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Grounding sources.
      public var groundingSources: [GenerateGroundedContentRequest.GroundingSource] = []

      /// Initialize a new instance of `GroundingSpec`.
      public init() {}

      /// Use `config` to return a new instance of this object, with some fields updated.
      ///
      /// Commonly used to initialize the value, for example:
      ///
      /// ```
      /// let value = GroundingSpec().with { $0.groundingSources = ... }
      /// ```
      public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
        var copy = self
        try config(&copy)
        return copy
      }

      public static var _anyTypeUrl: Swift.String {
        return
          "type.googleapis.com/google.cloud.discoveryengine.v1.GenerateGroundedContentRequest.GroundingSpec"
      }
      public init(fromAny any: GoogleCloudWkt.`Any`) throws {
        self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
      }
      public func _pack() throws -> GoogleCloudWkt.Struct {
        return try GoogleCloudWkt._slowAnySerialize(message: self)
      }
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.discoveryengine.v1.GenerateGroundedContentRequest"
    }
    public init(fromAny any: GoogleCloudWkt.`Any`) throws {
      self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
    }
    public func _pack() throws -> GoogleCloudWkt.Struct {
      return try GoogleCloudWkt._slowAnySerialize(message: self)
    }
  }
#endif
