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

/// Options to configure rule type ConditionalColumnSetValue.
/// The rule is used to transform the data which is being replicated/migrated.
///
/// The rule filter field can refer to one or more entities.
///
/// The rule scope can be one of: Column.
public struct ConditionalColumnSetValue: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. Description of data transformation during migration.
  public var valueTransformation: ValueTransformation? = nil

  /// Optional. Custom engine specific features.
  public var customFeatures: GoogleCloudWkt.Struct? = nil

  public var sourceFilter: OneOf_SourceFilter? = nil

  /// Initialize a new instance of `ConditionalColumnSetValue`.
  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 = ConditionalColumnSetValue().with { $0.sourceTextFilter = ... }
  /// ```
  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 sourceTextFilter = "sourceTextFilter"
    case sourceNumericFilter = "sourceNumericFilter"
    case valueTransformation = "valueTransformation"
    case customFeatures = "customFeatures"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.valueTransformation = try container.decodeIfPresent(
      ValueTransformation.self, forKey: .valueTransformation)
    self.customFeatures = try container.decodeIfPresent(
      GoogleCloudWkt.Struct.self, forKey: .customFeatures)

    var sourceFilter: OneOf_SourceFilter? = nil
    let sourceFilterCheckAndSet = {
      if sourceFilter != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'sourceFilter'"))
      }
      sourceFilter = $0
    }
    if let sourceTextFilter = try container.decodeIfPresent(
      SourceTextFilter?.self, forKey: .sourceTextFilter)
    {
      try sourceFilterCheckAndSet(.sourceTextFilter(sourceTextFilter))
    }
    if let sourceNumericFilter = try container.decodeIfPresent(
      SourceNumericFilter?.self, forKey: .sourceNumericFilter)
    {
      try sourceFilterCheckAndSet(.sourceNumericFilter(sourceNumericFilter))
    }
    self.sourceFilter = sourceFilter
  }

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

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

  public enum OneOf_SourceFilter: Codable, Equatable, Sendable {
    /// Optional. Optional filter on source column length. Used for text based
    /// data types like varchar.
    indirect case sourceTextFilter(SourceTextFilter?)
    /// Optional. Optional filter on source column precision and scale. Used for
    /// fixed point numbers such as NUMERIC/NUMBER data types.
    indirect case sourceNumericFilter(SourceNumericFilter?)
  }

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