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

/// RolloutStrategy defines different ways to rollout a resource bundle across
/// a set of clusters.
public struct RolloutStrategy: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// strategy defines how updates to a resource bundle should be rolled out
  /// across clusters.
  public var strategy: OneOf_Strategy? = nil

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

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

    var strategy: OneOf_Strategy? = nil
    let strategyCheckAndSet = {
      if strategy != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'strategy'"))
      }
      strategy = $0
    }
    if let allAtOnce = try container.decodeIfPresent(AllAtOnceStrategy?.self, forKey: .allAtOnce) {
      try strategyCheckAndSet(.allAtOnce(allAtOnce))
    }
    if let rolling = try container.decodeIfPresent(RollingStrategy?.self, forKey: .rolling) {
      try strategyCheckAndSet(.rolling(rolling))
    }
    self.strategy = strategy
  }

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

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

  /// strategy defines how updates to a resource bundle should be rolled out
  /// across clusters.
  public enum OneOf_Strategy: Codable, Equatable, Sendable {
    /// AllAtOnceStrategy causes all clusters to be updated concurrently.
    indirect case allAtOnce(AllAtOnceStrategy?)
    /// RollingStrategy causes a specified number of clusters to be updated
    /// concurrently until all clusters are updated.
    indirect case rolling(RollingStrategy?)
  }

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