// 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.

import Foundation
import GoogleCloudWkt

/// Request message for
/// [VectorSearchService.ExportDataObjects][google.cloud.vectorsearch.v1.VectorSearchService.ExportDataObjects].
///
/// [google.cloud.vectorsearch.v1.VectorSearchService.ExportDataObjects]: <doc:VectorSearchService/exportDataObjects(request:)>
public struct ExportDataObjectsRequest: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. The resource name of the Collection from which we want to export
  /// Data Objects. Format:
  /// `projects/{project}/locations/{location}/collections/{collection}`.
  public var name: Swift.String = Swift.String()

  /// Optional. Restricts which top-level Data Object fields appear in each
  /// exported JSONL record. If unset, every field is exported (the existing
  /// behavior). The primary use case is excluding the per-object `etag` so
  /// that the exported records can be imported into a Collection in a
  /// different region without optimistic-concurrency conflicts.
  ///
  /// Allowed field names are `id`, `data`, `vectors`, `etag`.
  public var fieldFilter: ExportDataObjectsRequest.FieldFilter? = nil

  /// The configuration for the export data.
  public var destination: OneOf_Destination? = nil

  /// Initialize a new instance of `ExportDataObjectsRequest`.
  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 = ExportDataObjectsRequest().with { $0.gcsDestination = ... }
  /// ```
  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 gcsDestination = "gcsDestination"
    case name = "name"
    case fieldFilter = "fieldFilter"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.name = try container.decode(Swift.String.self, forKey: .name)
    self.fieldFilter = try container.decodeIfPresent(
      ExportDataObjectsRequest.FieldFilter.self, forKey: .fieldFilter)

    var destination: OneOf_Destination? = nil
    let destinationCheckAndSet = {
      if destination != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'destination'"))
      }
      destination = $0
    }
    if let gcsDestination = try container.decodeIfPresent(
      ExportDataObjectsRequest.GcsExportDestination?.self, forKey: .gcsDestination)
    {
      try destinationCheckAndSet(.gcsDestination(gcsDestination))
    }
    self.destination = destination
  }

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

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

  /// Google Cloud Storage configuration for the export.
  public struct GcsExportDestination: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. URI prefix of the Cloud Storage where to export Data Objects.
    /// The bucket is required to be in the same region as the collection.
    public var exportUri: Swift.String = Swift.String()

    /// Required. The format of the exported Data Objects.
    public var format: ExportDataObjectsRequest.GcsExportDestination.Format =
      ExportDataObjectsRequest.GcsExportDestination.Format()

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

    /// Options for the format of the exported Data Objects.
    public enum Format: Codable, Equatable, Sendable {
      /// Unspecified format.
      case unspecified
      /// Exports Data Objects in `JSONL` format.
      case jsonl
      /// 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 .jsonl: return 2
        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 "FORMAT_UNSPECIFIED"
        case .jsonl: return "JSONL"
        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:Format/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "FORMAT_UNSPECIFIED": self = .unspecified
        case "JSONL": self = .jsonl
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Format/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .unspecified
        case 2: self = .jsonl
        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 .jsonl: return try container.encode(2)
        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.vectorsearch.v1.ExportDataObjectsRequest.GcsExportDestination"
    }
    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)
    }
  }

  /// Selects which top-level Data Object fields are emitted at export time.
  public struct FieldFilter: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Exactly one of `included_fields` or `excluded_fields` must be set.
    public var selector: OneOf_Selector? = nil

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

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

      var selector: OneOf_Selector? = nil
      let selectorCheckAndSet = {
        if selector != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'selector'"))
        }
        selector = $0
      }
      if let includedFields = try container.decodeIfPresent(
        ExportDataObjectsRequest.FieldFilter.FieldList?.self, forKey: .includedFields)
      {
        try selectorCheckAndSet(.includedFields(includedFields))
      }
      if let excludedFields = try container.decodeIfPresent(
        ExportDataObjectsRequest.FieldFilter.FieldList?.self, forKey: .excludedFields)
      {
        try selectorCheckAndSet(.excludedFields(excludedFields))
      }
      self.selector = selector
    }

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

      if let choice = self.selector {
        switch choice {
        case .includedFields(let value):
          try container.encode(value, forKey: .includedFields)
        case .excludedFields(let value):
          try container.encode(value, forKey: .excludedFields)
        }
      }
    }

    /// Wrapper for a repeated string. Wrapping in a message lets the
    /// surrounding `oneof` distinguish "field set to an empty list" (which is
    /// rejected as INVALID_ARGUMENT) from "field not set".
    public struct FieldList: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Required. The list of top-level Data Object JSON field names. Allowed
      /// values are `id`, `data`, `vectors`, `etag`.
      public var fields: [Swift.String] = []

      /// Initialize a new instance of `FieldList`.
      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 = FieldList().with { $0.fields = ... }
      /// ```
      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.vectorsearch.v1.ExportDataObjectsRequest.FieldFilter.FieldList"
      }
      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)
      }
    }

    /// Exactly one of `included_fields` or `excluded_fields` must be set.
    public enum OneOf_Selector: Codable, Equatable, Sendable {
      /// Optional. Only these top-level fields will appear in each exported
      /// record.
      indirect case includedFields(ExportDataObjectsRequest.FieldFilter.FieldList?)
      /// Optional. Every top-level field except these will appear in each
      /// exported record.
      indirect case excludedFields(ExportDataObjectsRequest.FieldFilter.FieldList?)
    }

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

  /// The configuration for the export data.
  public enum OneOf_Destination: Codable, Equatable, Sendable {
    /// The Cloud Storage location where user wants to export Data Objects.
    indirect case gcsDestination(ExportDataObjectsRequest.GcsExportDestination?)
  }

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