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

  /// A datapoint of Index.
  public struct IndexDatapoint: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. Unique identifier of the datapoint.
    public var datapointId: Swift.String = Swift.String()

    /// Required. Feature embedding vector for dense index. An array of numbers
    /// with the length of [NearestNeighborSearchConfig.dimensions].
    public var featureVector: [Swift.Float] = []

    /// Optional. Feature embedding vector for sparse index.
    public var sparseEmbedding: IndexDatapoint.SparseEmbedding? = nil

    /// Optional. List of Restrict of the datapoint, used to perform "restricted
    /// searches" where boolean rule are used to filter the subset of the database
    /// eligible for matching. This uses categorical tokens. See:
    /// https://cloud.google.com/vertex-ai/docs/matching-engine/filtering
    public var restricts: [IndexDatapoint.Restriction] = []

    /// Optional. List of Restrict of the datapoint, used to perform "restricted
    /// searches" where boolean rule are used to filter the subset of the database
    /// eligible for matching. This uses numeric comparisons.
    public var numericRestricts: [IndexDatapoint.NumericRestriction] = []

    /// Optional. CrowdingTag of the datapoint, the number of neighbors to return
    /// in each crowding can be configured during query.
    public var crowdingTag: IndexDatapoint.CrowdingTag? = nil

    /// Optional. The key-value map of additional metadata for the datapoint.
    public var embeddingMetadata: GoogleCloudWkt.Struct? = nil

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

    /// Feature embedding vector for sparse index. An array of numbers whose values
    /// are located in the specified dimensions.
    public struct SparseEmbedding: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Required. The list of embedding values of the sparse vector.
      public var values: [Swift.Float] = []

      /// Required. The list of indexes for the embedding values of the sparse
      /// vector.
      public var dimensions: [Swift.Int64] = []

      /// Initialize a new instance of `SparseEmbedding`.
      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 = SparseEmbedding().with { $0.values = ... }
      /// ```
      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.IndexDatapoint.SparseEmbedding"
      }
      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)
      }
    }

    /// Restriction of a datapoint which describe its attributes(tokens) from each
    /// of several attribute categories(namespaces).
    public struct Restriction: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// The namespace of this restriction. e.g.: color.
      public var namespace: Swift.String = Swift.String()

      /// The attributes to allow in this namespace. e.g.: 'red'
      public var allowList: [Swift.String] = []

      /// The attributes to deny in this namespace. e.g.: 'blue'
      public var denyList: [Swift.String] = []

      /// Initialize a new instance of `Restriction`.
      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 = Restriction().with { $0.namespace = ... }
      /// ```
      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.IndexDatapoint.Restriction"
      }
      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)
      }
    }

    /// This field allows restricts to be based on numeric comparisons rather
    /// than categorical tokens.
    public struct NumericRestriction: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// The namespace of this restriction. e.g.: cost.
      public var namespace: Swift.String = Swift.String()

      /// This MUST be specified for queries and must NOT be specified for
      /// datapoints.
      public var op: IndexDatapoint.NumericRestriction.Operator = IndexDatapoint.NumericRestriction
        .Operator()

      /// The type of Value must be consistent for all datapoints with a given
      /// namespace name. This is verified at runtime.
      public var value: OneOf_Value? = nil

      /// Initialize a new instance of `NumericRestriction`.
      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 = NumericRestriction().with { $0.valueInt = ... }
      /// ```
      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 valueInt = "valueInt"
        case valueFloat = "valueFloat"
        case valueDouble = "valueDouble"
        case namespace = "namespace"
        case op = "op"
      }

      public init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.namespace = try container.decode(Swift.String.self, forKey: .namespace)
        self.op = try container.decode(IndexDatapoint.NumericRestriction.Operator.self, forKey: .op)

        var value: OneOf_Value? = nil
        let valueCheckAndSet = {
          if value != nil {
            throw DecodingError.dataCorrupted(
              DecodingError.Context(
                codingPath: decoder.codingPath,
                debugDescription: "Multiple values set for oneof 'value'"))
          }
          value = $0
        }
        if let valueInt = try container.decodeIfPresent(Swift.Int64.self, forKey: .valueInt) {
          try valueCheckAndSet(.valueInt(valueInt))
        }
        if let valueFloat = try container.decodeIfPresent(Swift.Float.self, forKey: .valueFloat) {
          try valueCheckAndSet(.valueFloat(valueFloat))
        }
        if let valueDouble = try container.decodeIfPresent(Swift.Double.self, forKey: .valueDouble)
        {
          try valueCheckAndSet(.valueDouble(valueDouble))
        }
        self.value = value
      }

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

        if let choice = self.value {
          switch choice {
          case .valueInt(let value):
            try container.encode(value, forKey: .valueInt)
          case .valueFloat(let value):
            try container.encode(value, forKey: .valueFloat)
          case .valueDouble(let value):
            try container.encode(value, forKey: .valueDouble)
          }
        }
      }

      /// Which comparison operator to use.  Should be specified for queries only;
      /// specifying this for a datapoint is an error.
      ///
      /// Datapoints for which Operator is true relative to the query's Value
      /// field will be allowlisted.
      public enum Operator: Codable, Equatable, Sendable {
        /// Default value of the enum.
        case unspecified
        /// Datapoints are eligible iff their value is < the query's.
        case less
        /// Datapoints are eligible iff their value is <= the query's.
        case lessEqual
        /// Datapoints are eligible iff their value is == the query's.
        case equal
        /// Datapoints are eligible iff their value is >= the query's.
        case greaterEqual
        /// Datapoints are eligible iff their value is > the query's.
        case greater
        /// Datapoints are eligible iff their value is != the query's.
        case notEqual
        /// 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 .less: return 1
          case .lessEqual: return 2
          case .equal: return 3
          case .greaterEqual: return 4
          case .greater: return 5
          case .notEqual: return 6
          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 "OPERATOR_UNSPECIFIED"
          case .less: return "LESS"
          case .lessEqual: return "LESS_EQUAL"
          case .equal: return "EQUAL"
          case .greaterEqual: return "GREATER_EQUAL"
          case .greater: return "GREATER"
          case .notEqual: return "NOT_EQUAL"
          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:Operator/unknownStringValue(_:)).
        public init(stringValue: Swift.String) {
          switch stringValue {
          case "OPERATOR_UNSPECIFIED": self = .unspecified
          case "LESS": self = .less
          case "LESS_EQUAL": self = .lessEqual
          case "EQUAL": self = .equal
          case "GREATER_EQUAL": self = .greaterEqual
          case "GREATER": self = .greater
          case "NOT_EQUAL": self = .notEqual
          default: self = .unknownStringValue(stringValue)
          }
        }

        /// Initialize from an integer value.
        ///
        /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Operator/unknownIntValue(_:)).
        public init(intValue: Int) {
          switch intValue {
          case 0: self = .unspecified
          case 1: self = .less
          case 2: self = .lessEqual
          case 3: self = .equal
          case 4: self = .greaterEqual
          case 5: self = .greater
          case 6: self = .notEqual
          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 .less: return try container.encode(1)
          case .lessEqual: return try container.encode(2)
          case .equal: return try container.encode(3)
          case .greaterEqual: return try container.encode(4)
          case .greater: return try container.encode(5)
          case .notEqual: return try container.encode(6)
          case .unknownIntValue(let v): return try container.encode(v)
          case .unknownStringValue(let v): return try container.encode(v)
          }
        }
      }

      /// The type of Value must be consistent for all datapoints with a given
      /// namespace name. This is verified at runtime.
      public enum OneOf_Value: Codable, Equatable, Sendable {
        /// Represents 64 bit integer.
        case valueInt(Swift.Int64)
        /// Represents 32 bit float.
        case valueFloat(Swift.Float)
        /// Represents 64 bit float.
        case valueDouble(Swift.Double)
      }

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

    /// Crowding tag is a constraint on a neighbor list produced by nearest
    /// neighbor search requiring that no more than some value k' of the k
    /// neighbors returned have the same value of crowding_attribute.
    public struct CrowdingTag: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// The attribute value used for crowding.  The maximum number of neighbors
      /// to return per crowding attribute value
      /// (per_crowding_attribute_num_neighbors) is configured per-query. This
      /// field is ignored if per_crowding_attribute_num_neighbors is larger than
      /// the total number of neighbors to return for a given query.
      public var crowdingAttribute: Swift.String = Swift.String()

      /// Initialize a new instance of `CrowdingTag`.
      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 = CrowdingTag().with { $0.crowdingAttribute = ... }
      /// ```
      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.IndexDatapoint.CrowdingTag"
      }
      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.aiplatform.v1.IndexDatapoint"
    }
    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
