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

/// Description of data transformation during migration as part of the
/// ConditionalColumnSetValue.
public struct ValueTransformation: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  public var filter: OneOf_Filter? = nil

  public var action: OneOf_Action? = nil

  /// Initialize a new instance of `ValueTransformation`.
  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 = ValueTransformation().with { $0.isNull = ... }
  /// ```
  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 isNull = "isNull"
    case valueList = "valueList"
    case intComparison = "intComparison"
    case doubleComparison = "doubleComparison"
    case assignNull = "assignNull"
    case assignSpecificValue = "assignSpecificValue"
    case assignMinValue = "assignMinValue"
    case assignMaxValue = "assignMaxValue"
    case roundScale = "roundScale"
    case applyHash = "applyHash"
  }

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

    var filter: OneOf_Filter? = nil
    let filterCheckAndSet = {
      if filter != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'filter'"))
      }
      filter = $0
    }
    if let isNull = try container.decodeIfPresent(GoogleCloudWkt.Empty?.self, forKey: .isNull) {
      try filterCheckAndSet(.isNull(isNull))
    }
    if let valueList = try container.decodeIfPresent(ValueListFilter?.self, forKey: .valueList) {
      try filterCheckAndSet(.valueList(valueList))
    }
    if let intComparison = try container.decodeIfPresent(
      IntComparisonFilter?.self, forKey: .intComparison)
    {
      try filterCheckAndSet(.intComparison(intComparison))
    }
    if let doubleComparison = try container.decodeIfPresent(
      DoubleComparisonFilter?.self, forKey: .doubleComparison)
    {
      try filterCheckAndSet(.doubleComparison(doubleComparison))
    }
    self.filter = filter

    var action: OneOf_Action? = nil
    let actionCheckAndSet = {
      if action != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'action'"))
      }
      action = $0
    }
    if let assignNull = try container.decodeIfPresent(
      GoogleCloudWkt.Empty?.self, forKey: .assignNull)
    {
      try actionCheckAndSet(.assignNull(assignNull))
    }
    if let assignSpecificValue = try container.decodeIfPresent(
      AssignSpecificValue?.self, forKey: .assignSpecificValue)
    {
      try actionCheckAndSet(.assignSpecificValue(assignSpecificValue))
    }
    if let assignMinValue = try container.decodeIfPresent(
      GoogleCloudWkt.Empty?.self, forKey: .assignMinValue)
    {
      try actionCheckAndSet(.assignMinValue(assignMinValue))
    }
    if let assignMaxValue = try container.decodeIfPresent(
      GoogleCloudWkt.Empty?.self, forKey: .assignMaxValue)
    {
      try actionCheckAndSet(.assignMaxValue(assignMaxValue))
    }
    if let roundScale = try container.decodeIfPresent(RoundToScale?.self, forKey: .roundScale) {
      try actionCheckAndSet(.roundScale(roundScale))
    }
    if let applyHash = try container.decodeIfPresent(ApplyHash?.self, forKey: .applyHash) {
      try actionCheckAndSet(.applyHash(applyHash))
    }
    self.action = action
  }

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

    if let choice = self.filter {
      switch choice {
      case .isNull(let value):
        try container.encode(value, forKey: .isNull)
      case .valueList(let value):
        try container.encode(value, forKey: .valueList)
      case .intComparison(let value):
        try container.encode(value, forKey: .intComparison)
      case .doubleComparison(let value):
        try container.encode(value, forKey: .doubleComparison)
      }
    }

    if let choice = self.action {
      switch choice {
      case .assignNull(let value):
        try container.encode(value, forKey: .assignNull)
      case .assignSpecificValue(let value):
        try container.encode(value, forKey: .assignSpecificValue)
      case .assignMinValue(let value):
        try container.encode(value, forKey: .assignMinValue)
      case .assignMaxValue(let value):
        try container.encode(value, forKey: .assignMaxValue)
      case .roundScale(let value):
        try container.encode(value, forKey: .roundScale)
      case .applyHash(let value):
        try container.encode(value, forKey: .applyHash)
      }
    }
  }

  public enum OneOf_Filter: Codable, Equatable, Sendable {
    /// Optional. Value is null
    indirect case isNull(GoogleCloudWkt.Empty?)
    /// Optional. Value is found in the specified list.
    indirect case valueList(ValueListFilter?)
    /// Optional. Filter on relation between source value and compare value of
    /// type integer.
    indirect case intComparison(IntComparisonFilter?)
    /// Optional. Filter on relation between source value and compare value of
    /// type double.
    indirect case doubleComparison(DoubleComparisonFilter?)
  }

  public enum OneOf_Action: Codable, Equatable, Sendable {
    /// Optional. Set to null
    indirect case assignNull(GoogleCloudWkt.Empty?)
    /// Optional. Set to a specific value (value is converted to fit the target
    /// data type)
    indirect case assignSpecificValue(AssignSpecificValue?)
    /// Optional. Set to min_value - if integer or numeric, will use
    /// int.minvalue, etc
    indirect case assignMinValue(GoogleCloudWkt.Empty?)
    /// Optional. Set to max_value - if integer or numeric, will use
    /// int.maxvalue, etc
    indirect case assignMaxValue(GoogleCloudWkt.Empty?)
    /// Optional. Allows the data to change scale
    indirect case roundScale(RoundToScale?)
    /// Optional. Applies a hash function on the data
    indirect case applyHash(ApplyHash?)
  }

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