// 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 InstanceGroupManagerInstanceLifecyclePolicy: Codable, Equatable, GoogleCloudWkt
      ._AnyPackable,
    Sendable
  {
    /// The action that a MIG performs on a failed VM. If the value of the
    /// onFailedHealthCheck field is `DEFAULT_ACTION`, then the same action also
    /// applies to the VMs on which your application fails a health check.
    /// Valid values are
    ///
    ///    - REPAIR (default): MIG automatically repairs a failed VM
    ///    by recreating it. For more information, see About
    ///    repairing VMs in a MIG.
    ///    - DO_NOTHING: MIG does not repair a failed VM.
    public var defaultActionOnFailure:
      InstanceGroupManagerInstanceLifecyclePolicy.DefaultActionOnFailure? = nil

    /// A bit indicating whether to forcefully apply the group's latest
    /// configuration when repairing a VM. Valid options are:
    ///
    ///
    ///
    ///      -  NO (default): If configuration updates are available, they are not
    ///      forcefully applied during repair. Instead, configuration updates are
    ///      applied according to the group's update policy.
    ///
    ///      -  YES: If configuration updates are available, they are applied
    ///      during repair.
    public var forceUpdateOnRepair:
      InstanceGroupManagerInstanceLifecyclePolicy.ForceUpdateOnRepair? = nil

    /// The action that a MIG performs on an unhealthy VM. A VM is marked as
    /// unhealthy when the application running on that VM fails a health check.
    /// Valid values are:
    ///
    ///    - DEFAULT_ACTION (default): MIG uses the same action
    ///    configured for instanceLifecyclePolicy.defaultActionOnFailure field.
    ///    - REPAIR: MIG automatically repairs an unhealthy VM by
    ///    recreating it.
    ///    - DO_NOTHING: MIG doesn't repair an unhealthy VM.
    ///    For more information, see
    ///    About repairing VMs in a MIG.
    public var onFailedHealthCheck:
      InstanceGroupManagerInstanceLifecyclePolicy.OnFailedHealthCheck? = nil

    /// Configuration for VM repairs in the MIG.
    public var onRepair: InstanceGroupManagerInstanceLifecyclePolicyOnRepair? = nil

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

    /// The enumerated type for the [defaultActionOnFailure][google.cloud.compute.v1.InstanceGroupManagerInstanceLifecyclePolicy.defaultActionOnFailure] field.
    ///
    /// [google.cloud.compute.v1.InstanceGroupManagerInstanceLifecyclePolicy.defaultActionOnFailure]: <doc:InstanceGroupManagerInstanceLifecyclePolicy/DefaultActionOnFailure>
    public enum DefaultActionOnFailure: Codable, Equatable, Sendable {
      /// MIG does not repair a failed VM.
      case doNothing
      /// (default): MIG automatically repairs a failed VM by recreating it.
      /// For more information, see About
      /// repairing VMs in a MIG.
      case repair
      /// 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 = .doNothing
      }

      /// 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 .doNothing: return 0
        case .repair: 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 .doNothing: return "DO_NOTHING"
        case .repair: return "REPAIR"
        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:DefaultActionOnFailure/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "DO_NOTHING": self = .doNothing
        case "REPAIR": self = .repair
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:DefaultActionOnFailure/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .doNothing
        case 1: self = .repair
        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 .doNothing: return try container.encode(0)
        case .repair: 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 [forceUpdateOnRepair][google.cloud.compute.v1.InstanceGroupManagerInstanceLifecyclePolicy.forceUpdateOnRepair] field.
    ///
    /// [google.cloud.compute.v1.InstanceGroupManagerInstanceLifecyclePolicy.forceUpdateOnRepair]: <doc:InstanceGroupManagerInstanceLifecyclePolicy/ForceUpdateOnRepair>
    public enum ForceUpdateOnRepair: Codable, Equatable, Sendable {
      case no
      case yes
      /// 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 = .no
      }

      /// 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 .no: return 0
        case .yes: 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 .no: return "NO"
        case .yes: return "YES"
        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:ForceUpdateOnRepair/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "NO": self = .no
        case "YES": self = .yes
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:ForceUpdateOnRepair/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .no
        case 1: self = .yes
        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 .no: return try container.encode(0)
        case .yes: 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 [onFailedHealthCheck][google.cloud.compute.v1.InstanceGroupManagerInstanceLifecyclePolicy.onFailedHealthCheck] field.
    ///
    /// [google.cloud.compute.v1.InstanceGroupManagerInstanceLifecyclePolicy.onFailedHealthCheck]: <doc:InstanceGroupManagerInstanceLifecyclePolicy/OnFailedHealthCheck>
    public enum OnFailedHealthCheck: Codable, Equatable, Sendable {
      /// (Default) MIG uses the same action configured for
      /// instanceLifecyclePolicy.defaultActionOnFailure field.
      case defaultAction
      /// MIG doesn't repair an unhealthy VM.
      case doNothing
      /// MIG automatically repairs an unhealthy VM by recreating it.
      case repair
      /// 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 = .defaultAction
      }

      /// 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 .defaultAction: return 0
        case .doNothing: return 1
        case .repair: return 2
        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 .defaultAction: return "DEFAULT_ACTION"
        case .doNothing: return "DO_NOTHING"
        case .repair: return "REPAIR"
        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:OnFailedHealthCheck/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "DEFAULT_ACTION": self = .defaultAction
        case "DO_NOTHING": self = .doNothing
        case "REPAIR": self = .repair
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:OnFailedHealthCheck/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .defaultAction
        case 1: self = .doNothing
        case 2: self = .repair
        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 .defaultAction: return try container.encode(0)
        case .doNothing: return try container.encode(1)
        case .repair: return try container.encode(2)
        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.InstanceGroupManagerInstanceLifecyclePolicy"
    }
    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
