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

  /// Request message for
  /// [FeatureOnlineStoreService.FeatureViewDirectWrite][google.cloud.aiplatform.v1.FeatureOnlineStoreService.FeatureViewDirectWrite].
  ///
  /// [google.cloud.aiplatform.v1.FeatureOnlineStoreService.FeatureViewDirectWrite]: <doc:FeatureOnlineStoreService/featureViewDirectWrite(request:)>
  public struct FeatureViewDirectWriteRequest: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// FeatureView resource format
    /// `projects/{project}/locations/{location}/featureOnlineStores/{featureOnlineStore}/featureViews/{featureView}`
    public var featureView: Swift.String = Swift.String()

    /// Required. The data keys and associated feature values.
    public var dataKeyAndFeatureValues: [FeatureViewDirectWriteRequest.DataKeyAndFeatureValues] = []

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

    /// A data key and associated feature values to write to the feature view.
    public struct DataKeyAndFeatureValues: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// The data key.
      public var dataKey: FeatureViewDataKey? = nil

      /// List of features to write.
      public var features: [FeatureViewDirectWriteRequest.DataKeyAndFeatureValues.Feature] = []

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

      /// Feature name & value pair.
      public struct Feature: Codable, Equatable, GoogleCloudWkt._AnyPackable,
        Sendable
      {
        /// Feature short name.
        public var name: Swift.String = Swift.String()

        /// Feature value data to write.
        public var dataOneof: OneOf_DataOneof? = nil

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

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

          var dataOneof: OneOf_DataOneof? = nil
          let dataOneofCheckAndSet = {
            if dataOneof != nil {
              throw DecodingError.dataCorrupted(
                DecodingError.Context(
                  codingPath: decoder.codingPath,
                  debugDescription: "Multiple values set for oneof 'dataOneof'"))
            }
            dataOneof = $0
          }
          if let value = try container.decodeIfPresent(FeatureValue?.self, forKey: .value) {
            try dataOneofCheckAndSet(.value(value))
          }
          self.dataOneof = dataOneof
        }

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

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

        /// Feature value data to write.
        public enum OneOf_DataOneof: Codable, Equatable, Sendable {
          /// Feature value. A user provided timestamp may be set in the
          /// `FeatureValue.metadata.generate_time` field.
          indirect case value(FeatureValue?)
        }

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