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

  /// Request message for
  /// [DatasetService.SearchDataItems][google.cloud.aiplatform.v1.DatasetService.SearchDataItems].
  ///
  /// [google.cloud.aiplatform.v1.DatasetService.SearchDataItems]: <doc:DatasetService/searchDataItems(request:)>
  public struct SearchDataItemsRequest: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. The resource name of the Dataset from which to search DataItems.
    /// Format:
    /// `projects/{project}/locations/{location}/datasets/{dataset}`
    public var dataset: Swift.String = Swift.String()

    /// The resource name of a SavedQuery(annotation set in UI).
    /// Format:
    /// `projects/{project}/locations/{location}/datasets/{dataset}/savedQueries/{saved_query}`
    /// All of the search will be done in the context of this SavedQuery.
    @available(*, deprecated)
    public var savedQuery: Swift.String = Swift.String()

    /// The resource name of a DataLabelingJob.
    /// Format:
    /// `projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`
    /// If this field is set, all of the search will be done in the context of
    /// this DataLabelingJob.
    public var dataLabelingJob: Swift.String = Swift.String()

    /// An expression for filtering the DataItem that will be returned.
    ///
    ///   * `data_item_id` - for = or !=.
    ///   * `labeled` - for = or !=.
    ///   * `has_annotation(ANNOTATION_SPEC_ID)` - true only for DataItem that
    ///     have at least one annotation with annotation_spec_id =
    ///     `ANNOTATION_SPEC_ID` in the context of SavedQuery or DataLabelingJob.
    ///
    /// For example:
    ///
    /// * `data_item=1`
    /// * `has_annotation(5)`
    public var dataItemFilter: Swift.String = Swift.String()

    /// An expression for filtering the Annotations that will be returned per
    /// DataItem.
    ///   * `annotation_spec_id` - for = or !=.
    @available(*, deprecated)
    public var annotationsFilter: Swift.String = Swift.String()

    /// An expression that specifies what Annotations will be returned per
    /// DataItem. Annotations satisfied either of the conditions will be returned.
    ///   * `annotation_spec_id` - for = or !=.
    /// Must specify `saved_query_id=` - saved query id that annotations should
    /// belong to.
    public var annotationFilters: [Swift.String] = []

    /// Mask specifying which fields of
    /// [DataItemView][google.cloud.aiplatform.v1.DataItemView] to read.
    ///
    /// [google.cloud.aiplatform.v1.DataItemView]: <doc:DataItemView>
    public var fieldMask: GoogleCloudWkt.FieldMask? = nil

    /// If set, only up to this many of Annotations will be returned per
    /// DataItemView. The maximum value is 1000. If not set, the maximum value will
    /// be used.
    public var annotationsLimit: Swift.Int32 = Swift.Int32()

    /// Requested page size. Server may return fewer results than requested.
    /// Default and maximum page size is 100.
    public var pageSize: Swift.Int32 = Swift.Int32()

    /// A comma-separated list of fields to order by, sorted in ascending order.
    /// Use "desc" after a field name for descending.
    @available(*, deprecated)
    public var orderBy: Swift.String = Swift.String()

    /// A token identifying a page of results for the server to return
    /// Typically obtained via
    /// [SearchDataItemsResponse.next_page_token][google.cloud.aiplatform.v1.SearchDataItemsResponse.next_page_token]
    /// of the previous
    /// [DatasetService.SearchDataItems][google.cloud.aiplatform.v1.DatasetService.SearchDataItems]
    /// call.
    ///
    /// [google.cloud.aiplatform.v1.DatasetService.SearchDataItems]: <doc:DatasetService/searchDataItems(request:)>
    /// [google.cloud.aiplatform.v1.SearchDataItemsResponse.next_page_token]: <doc:SearchDataItemsResponse/nextPageToken>
    public var pageToken: Swift.String = Swift.String()

    public var order: OneOf_Order? = nil

    /// Initialize a new instance of `SearchDataItemsRequest`.
    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 = SearchDataItemsRequest().with { $0.orderByDataItem = ... }
    /// ```
    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 orderByDataItem = "orderByDataItem"
      case orderByAnnotation = "orderByAnnotation"
      case dataset = "dataset"
      case savedQuery = "savedQuery"
      case dataLabelingJob = "dataLabelingJob"
      case dataItemFilter = "dataItemFilter"
      case annotationsFilter = "annotationsFilter"
      case annotationFilters = "annotationFilters"
      case fieldMask = "fieldMask"
      case annotationsLimit = "annotationsLimit"
      case pageSize = "pageSize"
      case orderBy = "orderBy"
      case pageToken = "pageToken"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.dataset = try container.decode(Swift.String.self, forKey: .dataset)
      self.savedQuery = try container.decode(Swift.String.self, forKey: .savedQuery)
      self.dataLabelingJob = try container.decode(Swift.String.self, forKey: .dataLabelingJob)
      self.dataItemFilter = try container.decode(Swift.String.self, forKey: .dataItemFilter)
      self.annotationsFilter = try container.decode(Swift.String.self, forKey: .annotationsFilter)
      self.annotationFilters = try container.decode([Swift.String].self, forKey: .annotationFilters)
      self.fieldMask = try container.decodeIfPresent(
        GoogleCloudWkt.FieldMask.self, forKey: .fieldMask)
      self.annotationsLimit = try container.decode(Swift.Int32.self, forKey: .annotationsLimit)
      self.pageSize = try container.decode(Swift.Int32.self, forKey: .pageSize)
      self.orderBy = try container.decode(Swift.String.self, forKey: .orderBy)
      self.pageToken = try container.decode(Swift.String.self, forKey: .pageToken)

      var order: OneOf_Order? = nil
      let orderCheckAndSet = {
        if order != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'order'"))
        }
        order = $0
      }
      if let orderByDataItem = try container.decodeIfPresent(
        Swift.String.self, forKey: .orderByDataItem)
      {
        try orderCheckAndSet(.orderByDataItem(orderByDataItem))
      }
      if let orderByAnnotation = try container.decodeIfPresent(
        SearchDataItemsRequest.OrderByAnnotation?.self, forKey: .orderByAnnotation)
      {
        try orderCheckAndSet(.orderByAnnotation(orderByAnnotation))
      }
      self.order = order
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)
      try container.encode(self.dataset, forKey: .dataset)
      try container.encode(self.savedQuery, forKey: .savedQuery)
      try container.encode(self.dataLabelingJob, forKey: .dataLabelingJob)
      try container.encode(self.dataItemFilter, forKey: .dataItemFilter)
      try container.encode(self.annotationsFilter, forKey: .annotationsFilter)
      try container.encode(self.annotationFilters, forKey: .annotationFilters)
      try container.encode(self.fieldMask, forKey: .fieldMask)
      try container.encode(self.annotationsLimit, forKey: .annotationsLimit)
      try container.encode(self.pageSize, forKey: .pageSize)
      try container.encode(self.orderBy, forKey: .orderBy)
      try container.encode(self.pageToken, forKey: .pageToken)

      if let choice = self.order {
        switch choice {
        case .orderByDataItem(let value):
          try container.encode(value, forKey: .orderByDataItem)
        case .orderByAnnotation(let value):
          try container.encode(value, forKey: .orderByAnnotation)
        }
      }
    }

    /// Expression that allows ranking results based on annotation's property.
    public struct OrderByAnnotation: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Required. Saved query of the Annotation. Only Annotations belong to this
      /// saved query will be considered for ordering.
      public var savedQuery: Swift.String = Swift.String()

      /// A comma-separated list of annotation fields to order by, sorted in
      /// ascending order. Use "desc" after a field name for descending. Must also
      /// specify saved_query.
      public var orderBy: Swift.String = Swift.String()

      /// Initialize a new instance of `OrderByAnnotation`.
      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 = OrderByAnnotation().with { $0.savedQuery = ... }
      /// ```
      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.aiplatform.v1.SearchDataItemsRequest.OrderByAnnotation"
      }
      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 enum OneOf_Order: Codable, Equatable, Sendable {
      /// A comma-separated list of data item fields to order by, sorted in
      /// ascending order. Use "desc" after a field name for descending.
      case orderByDataItem(Swift.String)
      /// Expression that allows ranking results based on annotation's property.
      indirect case orderByAnnotation(SearchDataItemsRequest.OrderByAnnotation?)
    }

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