// 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 AssistantService || ConversationalSearchService || SessionService
  import Foundation
  import GoogleCloudWkt

  /// A piece of content and possibly its grounding information.
  ///
  /// Not all content needs grounding. Phrases like "Of course, I will gladly
  /// search it for you." do not need grounding.
  public struct AssistantGroundedContent: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// The content.
    public var content: AssistantContent? = nil

    /// Grounding metadata for various modals. It only supports text for now.
    public var metadata: OneOf_Metadata? = nil

    /// Initialize a new instance of `AssistantGroundedContent`.
    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 = AssistantGroundedContent().with { $0.textGroundingMetadata = ... }
    /// ```
    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 textGroundingMetadata = "textGroundingMetadata"
      case content = "content"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.content = try container.decodeIfPresent(AssistantContent.self, forKey: .content)

      var metadata: OneOf_Metadata? = nil
      let metadataCheckAndSet = {
        if metadata != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'metadata'"))
        }
        metadata = $0
      }
      if let textGroundingMetadata = try container.decodeIfPresent(
        AssistantGroundedContent.TextGroundingMetadata?.self, forKey: .textGroundingMetadata)
      {
        try metadataCheckAndSet(.textGroundingMetadata(textGroundingMetadata))
      }
      self.metadata = metadata
    }

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

      if let choice = self.metadata {
        switch choice {
        case .textGroundingMetadata(let value):
          try container.encode(value, forKey: .textGroundingMetadata)
        }
      }
    }

    /// Grounding details for text sources.
    public struct TextGroundingMetadata: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Grounding information for parts of the text.
      public var segments: [AssistantGroundedContent.TextGroundingMetadata.Segment] = []

      /// References for the grounded text.
      public var references: [AssistantGroundedContent.TextGroundingMetadata.Reference] = []

      /// Initialize a new instance of `TextGroundingMetadata`.
      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 = TextGroundingMetadata().with { $0.segments = ... }
      /// ```
      public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
        var copy = self
        try config(&copy)
        return copy
      }

      /// Grounding information for a segment of the text.
      public struct Segment: Codable, Equatable, GoogleCloudWkt._AnyPackable,
        Sendable
      {
        /// Zero-based index indicating the start of the segment, measured in bytes
        /// of a UTF-8 string (i.e. characters encoded on multiple bytes have a
        /// length of more than one).
        public var startIndex: Swift.Int64 = Swift.Int64()

        /// End of the segment, exclusive.
        public var endIndex: Swift.Int64 = Swift.Int64()

        /// References for the segment.
        public var referenceIndices: [Swift.Int32] = []

        /// Score for the segment.
        public var groundingScore: Swift.Float = Swift.Float()

        /// The text segment itself.
        public var text: Swift.String = Swift.String()

        /// Initialize a new instance of `Segment`.
        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 = Segment().with { $0.startIndex = ... }
        /// ```
        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.AssistantGroundedContent.TextGroundingMetadata.Segment"
        }
        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)
        }
      }

      /// Referenced content and related document metadata.
      public struct Reference: Codable, Equatable, GoogleCloudWkt._AnyPackable,
        Sendable
      {
        /// Referenced text content.
        public var content: Swift.String = Swift.String()

        /// Document metadata.
        public var documentMetadata:
          AssistantGroundedContent.TextGroundingMetadata.Reference.DocumentMetadata? = nil

        /// Initialize a new instance of `Reference`.
        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 = Reference().with { $0.content = ... }
        /// ```
        public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
          var copy = self
          try config(&copy)
          return copy
        }

        /// Document metadata.
        public struct DocumentMetadata: Codable, Equatable, GoogleCloudWkt._AnyPackable,
          Sendable
        {
          /// Document resource name.
          public var document: Swift.String? = nil

          /// URI for the document. It may contain a URL that redirects to the
          /// actual website.
          public var uri: Swift.String? = nil

          /// Title.
          public var title: Swift.String? = nil

          /// Page identifier.
          public var pageIdentifier: Swift.String? = nil

          /// Domain name from the document URI. Note that the `uri` field may
          /// contain a URL that redirects to the actual website, in which case
          /// this will contain the domain name of the target site.
          public var domain: Swift.String? = nil

          /// Initialize a new instance of `DocumentMetadata`.
          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 = DocumentMetadata().with { $0.document = ... }
          /// ```
          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.AssistantGroundedContent.TextGroundingMetadata.Reference.DocumentMetadata"
          }
          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.AssistantGroundedContent.TextGroundingMetadata.Reference"
        }
        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.AssistantGroundedContent.TextGroundingMetadata"
      }
      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 metadata for various modals. It only supports text for now.
    public enum OneOf_Metadata: Codable, Equatable, Sendable {
      /// Metadata for grounding based on text sources.
      indirect case textGroundingMetadata(AssistantGroundedContent.TextGroundingMetadata?)
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.discoveryengine.v1.AssistantGroundedContent"
    }
    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
