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

  public struct InstanceGroupManagerUpdatePolicy: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// The
    /// instance redistribution policy for regional managed instance groups.
    /// Valid values are:
    ///
    ///    - PROACTIVE (default): The group attempts to maintain an
    ///    even distribution of VM instances across zones in the region.
    ///    - NONE: For non-autoscaled groups, proactive
    ///    redistribution is disabled.
    public var instanceRedistributionType:
      InstanceGroupManagerUpdatePolicy.InstanceRedistributionType? = nil

    /// The maximum number of instances that can be created above the specifiedtargetSize during the update process. This value can be
    /// either a fixed number or, if the group has 10 or more instances, a
    /// percentage. If you set a percentage, the number of instances is rounded
    /// if necessary.  The default value for maxSurge is a fixed
    /// value equal to the number of zones in which the managed instance group
    /// operates.
    ///
    /// At least one of either maxSurge ormaxUnavailable must be greater than 0. Learn more about maxSurge.
    public var maxSurge: FixedOrPercent? = nil

    /// The maximum number of instances that can be unavailable during the update
    /// process. An instance is considered available if all of the following
    /// conditions are satisfied:
    ///
    ///
    ///
    ///      - The instance's status is
    ///      RUNNING.
    ///    - If there is a health
    ///      check on the instance group, the instance's health check status
    ///      must be HEALTHY at least once. If there is no health check
    ///      on the group, then the instance only needs to have a status of
    ///      RUNNING to be considered available.
    ///
    ///
    /// This value can be either a fixed number or, if the group has 10 or more
    /// instances, a percentage. If you set a percentage, the number of instances
    /// is rounded if necessary. The default value formaxUnavailable is a fixed value equal to the number of zones
    /// in which the managed instance group operates.
    ///
    /// At least one of either maxSurge ormaxUnavailable must be greater than 0. Learn more about maxUnavailable.
    public var maxUnavailable: FixedOrPercent? = nil

    /// Minimal action to be taken on an instance. Use this option to minimize
    /// disruption as much as possible or to apply a more disruptive action than
    /// is necessary.
    ///
    ///    - To limit disruption as much as possible, set the minimal action toREFRESH. If your update requires a more disruptive action,
    ///    Compute Engine performs the necessary action to execute the update.
    ///    - To apply a more disruptive action than is strictly necessary, set the
    ///    minimal action to RESTART or REPLACE. For
    ///    example, Compute Engine does not need to restart a VM to change its
    ///    metadata. But if your application reads instance metadata only when a VM
    ///    is restarted, you can set the minimal action to RESTART in
    ///    order to pick up metadata changes.
    public var minimalAction: InstanceGroupManagerUpdatePolicy.MinimalAction? = nil

    /// Most disruptive action that is allowed to be taken on an instance.
    /// You can specify either NONE to forbid any actions,REFRESH to avoid restarting the VM and to limit disruption
    /// as much as possible. RESTART to allow actions that can be
    /// applied without instance replacing or REPLACE to allow all
    /// possible actions. If the Updater determines that the minimal update
    /// action needed is more disruptive than most disruptive allowed action you
    /// specify it will not perform the update at all.
    public var mostDisruptiveAllowedAction:
      InstanceGroupManagerUpdatePolicy.MostDisruptiveAllowedAction? = nil

    /// What action should be used to replace instances.
    /// See minimal_action.REPLACE
    public var replacementMethod: InstanceGroupManagerUpdatePolicy.ReplacementMethod? = nil

    /// The type
    /// of update process. You can specify either PROACTIVE so
    /// that the MIG automatically updates VMs to the latest configurations orOPPORTUNISTIC so that you can select the VMs that you want
    /// to update.
    public var type: InstanceGroupManagerUpdatePolicy.Type_? = nil

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

    /// The enumerated type for the [instanceRedistributionType][google.cloud.compute.v1.InstanceGroupManagerUpdatePolicy.instanceRedistributionType] field.
    ///
    /// [google.cloud.compute.v1.InstanceGroupManagerUpdatePolicy.instanceRedistributionType]: <doc:InstanceGroupManagerUpdatePolicy/InstanceRedistributionType>
    public enum InstanceRedistributionType: Codable, Equatable, Sendable {
      /// No action is being proactively performed in order to bring this IGM
      /// to its target instance distribution.
      case `none`
      /// This IGM will actively converge to its target instance distribution.
      case proactive
      /// 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 = .`none`
      }

      /// 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 .`none`: return 0
        case .proactive: return 1
        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 .`none`: return "NONE"
        case .proactive: return "PROACTIVE"
        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:InstanceRedistributionType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "NONE": self = .`none`
        case "PROACTIVE": self = .proactive
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:InstanceRedistributionType/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .`none`
        case 1: self = .proactive
        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 .`none`: return try container.encode(0)
        case .proactive: return try container.encode(1)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

    /// The enumerated type for the [minimalAction][google.cloud.compute.v1.InstanceGroupManagerUpdatePolicy.minimalAction] field.
    ///
    /// [google.cloud.compute.v1.InstanceGroupManagerUpdatePolicy.minimalAction]: <doc:InstanceGroupManagerUpdatePolicy/MinimalAction>
    public enum MinimalAction: Codable, Equatable, Sendable {
      /// Do not perform any action.
      case `none`
      /// Do not stop the instance.
      case refresh
      /// (Default.) Replace the instance according to the replacement method
      /// option.
      case replace
      /// Stop the instance and start it again.
      case restart
      /// 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 = .`none`
      }

      /// 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 .`none`: return 0
        case .refresh: return 1
        case .replace: return 2
        case .restart: return 3
        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 .`none`: return "NONE"
        case .refresh: return "REFRESH"
        case .replace: return "REPLACE"
        case .restart: return "RESTART"
        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:MinimalAction/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "NONE": self = .`none`
        case "REFRESH": self = .refresh
        case "REPLACE": self = .replace
        case "RESTART": self = .restart
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:MinimalAction/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .`none`
        case 1: self = .refresh
        case 2: self = .replace
        case 3: self = .restart
        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 .`none`: return try container.encode(0)
        case .refresh: return try container.encode(1)
        case .replace: return try container.encode(2)
        case .restart: return try container.encode(3)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

    /// The enumerated type for the [mostDisruptiveAllowedAction][google.cloud.compute.v1.InstanceGroupManagerUpdatePolicy.mostDisruptiveAllowedAction] field.
    ///
    /// [google.cloud.compute.v1.InstanceGroupManagerUpdatePolicy.mostDisruptiveAllowedAction]: <doc:InstanceGroupManagerUpdatePolicy/MostDisruptiveAllowedAction>
    public enum MostDisruptiveAllowedAction: Codable, Equatable, Sendable {
      /// Do not perform any action.
      case `none`
      /// Do not stop the instance.
      case refresh
      /// (Default.) Replace the instance according to the replacement method
      /// option.
      case replace
      /// Stop the instance and start it again.
      case restart
      /// 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 = .`none`
      }

      /// 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 .`none`: return 0
        case .refresh: return 1
        case .replace: return 2
        case .restart: return 3
        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 .`none`: return "NONE"
        case .refresh: return "REFRESH"
        case .replace: return "REPLACE"
        case .restart: return "RESTART"
        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:MostDisruptiveAllowedAction/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "NONE": self = .`none`
        case "REFRESH": self = .refresh
        case "REPLACE": self = .replace
        case "RESTART": self = .restart
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:MostDisruptiveAllowedAction/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .`none`
        case 1: self = .refresh
        case 2: self = .replace
        case 3: self = .restart
        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 .`none`: return try container.encode(0)
        case .refresh: return try container.encode(1)
        case .replace: return try container.encode(2)
        case .restart: return try container.encode(3)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

    /// The enumerated type for the [replacementMethod][google.cloud.compute.v1.InstanceGroupManagerUpdatePolicy.replacementMethod] field.
    ///
    /// [google.cloud.compute.v1.InstanceGroupManagerUpdatePolicy.replacementMethod]: <doc:InstanceGroupManagerUpdatePolicy/ReplacementMethod>
    public enum ReplacementMethod: Codable, Equatable, Sendable {
      /// Instances will be recreated (with the same name)
      case recreate
      /// Default option: instances will be deleted and created (with a new name)
      case substitute
      /// 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 = .recreate
      }

      /// 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 .recreate: return 0
        case .substitute: return 1
        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 .recreate: return "RECREATE"
        case .substitute: return "SUBSTITUTE"
        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:ReplacementMethod/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "RECREATE": self = .recreate
        case "SUBSTITUTE": self = .substitute
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:ReplacementMethod/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .recreate
        case 1: self = .substitute
        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 .recreate: return try container.encode(0)
        case .substitute: return try container.encode(1)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

    /// The enumerated type for the [type][google.cloud.compute.v1.InstanceGroupManagerUpdatePolicy.type] field.
    ///
    /// [google.cloud.compute.v1.InstanceGroupManagerUpdatePolicy.type]: <doc:InstanceGroupManagerUpdatePolicy/Type_>
    public enum Type_: Codable, Equatable, Sendable {
      /// MIG will apply new configurations
      /// to existing VMs only when you selectively target specific or all VMs to
      /// be updated.
      case opportunistic
      /// MIG will automatically apply new configurations
      /// to all or a subset of existing VMs and also to new VMs that are added
      /// to the group.
      case proactive
      /// 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 = .opportunistic
      }

      /// 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 .opportunistic: return 0
        case .proactive: return 1
        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 .opportunistic: return "OPPORTUNISTIC"
        case .proactive: return "PROACTIVE"
        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:Type_/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "OPPORTUNISTIC": self = .opportunistic
        case "PROACTIVE": self = .proactive
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Type_/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .opportunistic
        case 1: self = .proactive
        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 .opportunistic: return try container.encode(0)
        case .proactive: return try container.encode(1)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

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