// 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 RecommendationService || UserEventService
  import Foundation
  import GoogleCloudWkt

  /// Detailed document information associated with a user event.
  public struct DocumentInfo: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Quantity of the Document associated with the user event. Defaults to 1.
    ///
    /// For example, this field is 2 if two quantities of the same Document
    /// are involved in a `add-to-cart` event.
    ///
    /// Required for events of the following event types:
    ///
    /// * `add-to-cart`
    /// * `purchase`
    public var quantity: Swift.Int32? = nil

    /// The promotion IDs associated with this Document.
    /// Currently, this field is restricted to at most one ID.
    public var promotionIds: [Swift.String] = []

    /// Output only. Whether the referenced Document can be found in the data
    /// store.
    public var joined: Swift.Bool = Swift.Bool()

    /// Optional. The conversion value associated with this Document.
    /// Must be set if
    /// [UserEvent.event_type][google.cloud.discoveryengine.v1.UserEvent.event_type]
    /// is "conversion".
    ///
    /// For example, a value of 1000 signifies that 1000 seconds were spent viewing
    /// a Document for the `watch` conversion type.
    ///
    /// [google.cloud.discoveryengine.v1.UserEvent.event_type]: <doc:UserEvent/eventType>
    public var conversionValue: Swift.Float? = nil

    /// A required descriptor of the associated
    /// [Document][google.cloud.discoveryengine.v1.Document].
    ///
    /// * If [id][google.cloud.discoveryengine.v1.DocumentInfo.id] is specified,
    /// then the default values for
    /// `{location}`, `{collection_id}`, `{data_store_id}`, and `{branch_id}` are
    /// used when annotating with the stored Document.
    ///
    /// * If [name][google.cloud.discoveryengine.v1.DocumentInfo.name] is
    /// specified, then the provided values (default values allowed) for
    /// `{location}`, `{collection_id}`, `{data_store_id}`, and
    /// `{branch_id}` are used when annotating with the stored Document.
    ///
    /// [google.cloud.discoveryengine.v1.Document]: <doc:Document>
    /// [google.cloud.discoveryengine.v1.DocumentInfo.id]: <doc:DocumentInfo/id>
    /// [google.cloud.discoveryengine.v1.DocumentInfo.name]: <doc:DocumentInfo/name>
    public var documentDescriptor: OneOf_DocumentDescriptor? = nil

    /// Initialize a new instance of `DocumentInfo`.
    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 = DocumentInfo().with { $0.id = ... }
    /// ```
    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 id = "id"
      case name = "name"
      case uri = "uri"
      case quantity = "quantity"
      case promotionIds = "promotionIds"
      case joined = "joined"
      case conversionValue = "conversionValue"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.quantity = try container.decodeIfPresent(Swift.Int32.self, forKey: .quantity)
      self.promotionIds = try container.decode([Swift.String].self, forKey: .promotionIds)
      self.joined = try container.decode(Swift.Bool.self, forKey: .joined)
      self.conversionValue = try container.decodeIfPresent(
        Swift.Float.self, forKey: .conversionValue)

      var documentDescriptor: OneOf_DocumentDescriptor? = nil
      let documentDescriptorCheckAndSet = {
        if documentDescriptor != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'documentDescriptor'"))
        }
        documentDescriptor = $0
      }
      if let id = try container.decodeIfPresent(Swift.String.self, forKey: .id) {
        try documentDescriptorCheckAndSet(.id(id))
      }
      if let name = try container.decodeIfPresent(Swift.String.self, forKey: .name) {
        try documentDescriptorCheckAndSet(.name(name))
      }
      if let uri = try container.decodeIfPresent(Swift.String.self, forKey: .uri) {
        try documentDescriptorCheckAndSet(.uri(uri))
      }
      self.documentDescriptor = documentDescriptor
    }

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

      if let choice = self.documentDescriptor {
        switch choice {
        case .id(let value):
          try container.encode(value, forKey: .id)
        case .name(let value):
          try container.encode(value, forKey: .name)
        case .uri(let value):
          try container.encode(value, forKey: .uri)
        }
      }
    }

    /// A required descriptor of the associated
    /// [Document][google.cloud.discoveryengine.v1.Document].
    ///
    /// * If [id][google.cloud.discoveryengine.v1.DocumentInfo.id] is specified,
    /// then the default values for
    /// `{location}`, `{collection_id}`, `{data_store_id}`, and `{branch_id}` are
    /// used when annotating with the stored Document.
    ///
    /// * If [name][google.cloud.discoveryengine.v1.DocumentInfo.name] is
    /// specified, then the provided values (default values allowed) for
    /// `{location}`, `{collection_id}`, `{data_store_id}`, and
    /// `{branch_id}` are used when annotating with the stored Document.
    ///
    /// [google.cloud.discoveryengine.v1.Document]: <doc:Document>
    /// [google.cloud.discoveryengine.v1.DocumentInfo.id]: <doc:DocumentInfo/id>
    /// [google.cloud.discoveryengine.v1.DocumentInfo.name]: <doc:DocumentInfo/name>
    public enum OneOf_DocumentDescriptor: Codable, Equatable, Sendable {
      /// The [Document][google.cloud.discoveryengine.v1.Document] resource ID.
      ///
      /// [google.cloud.discoveryengine.v1.Document]: <doc:Document>
      case id(Swift.String)
      /// The [Document][google.cloud.discoveryengine.v1.Document] resource full
      /// name, of the form:
      /// `projects/{project}/locations/{location}/collections/{collection_id}/dataStores/{data_store_id}/branches/{branch_id}/documents/{document_id}`
      ///
      /// [google.cloud.discoveryengine.v1.Document]: <doc:Document>
      case name(Swift.String)
      /// The [Document][google.cloud.discoveryengine.v1.Document] URI - only
      /// allowed for website data stores.
      ///
      /// [google.cloud.discoveryengine.v1.Document]: <doc:Document>
      case uri(Swift.String)
    }

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