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

  /// Represents a Managed Instance Group resource.
  ///
  /// An instance group is a collection of VM instances that you can manage as a
  /// single entity. For more information, readInstance groups.
  ///
  /// For zonal Managed Instance Group, use the instanceGroupManagers
  /// resource.
  ///
  /// For regional Managed Instance Group, use theregionInstanceGroupManagers resource.
  public struct InstanceGroupManager: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Specifies configuration that overrides the instance template configuration
    /// for the group.
    public var allInstancesConfig: InstanceGroupManagerAllInstancesConfig? = nil

    /// The autohealing policy for this managed instance group. You can specify
    /// only one value.
    public var autoHealingPolicies: [InstanceGroupManagerAutoHealingPolicy] = []

    /// The base instance name is a prefix that you want to attach to the names of
    /// all VMs in a MIG. The maximum character length is 58 and the name must
    /// comply with RFC1035 format.
    ///
    /// When a VM is created in the group, the MIG appends a hyphen and a random
    /// four-character string to the base instance name. If you want the MIG to
    /// assign sequential numbers instead of a random string, then end the base
    /// instance name with a hyphen followed by one or more hash symbols. The hash
    /// symbols indicate the number of digits. For example, a base instance name of
    /// "vm-###" results in "vm-001" as a VM name.
    /// @pattern
    /// [a-z](([-a-z0-9]{0,57})|([-a-z0-9]{0,51}-#{1,10}(\\[[0-9]{1,10}\\])?))
    public var baseInstanceName: Swift.String? = nil

    /// Output only. The creation timestamp for this managed instance group inRFC3339
    /// text format.
    public var creationTimestamp: Swift.String? = nil

    /// Output only. The list of instance actions and the number of instances
    /// in this managed instance group that are scheduled for each of those
    /// actions.
    public var currentActions: InstanceGroupManagerActionsSummary? = nil

    /// An optional description of this resource.
    public var description: Swift.String? = nil

    /// Policy specifying the intended distribution of managed instances across
    /// zones in a regional managed instance group.
    public var distributionPolicy: DistributionPolicy? = nil

    /// Fingerprint of this resource. This field may be used in optimistic locking.
    /// It will be ignored when inserting an InstanceGroupManager. An up-to-date
    /// fingerprint must be provided in order to update the InstanceGroupManager,
    /// otherwise the request will fail with error412 conditionNotMet.
    ///
    /// To see the latest fingerprint, make a get() request to
    /// retrieve an InstanceGroupManager.
    public var fingerprint: Foundation.Data? = nil

    /// Output only. A unique identifier for this resource type. The server
    /// generates this identifier.
    public var id: Swift.UInt64? = nil

    /// Instance flexibility allowing MIG to create VMs from multiple
    /// types of machines.
    /// Instance flexibility configuration on MIG overrides instance
    /// template configuration.
    public var instanceFlexibilityPolicy: InstanceGroupManagerInstanceFlexibilityPolicy? = nil

    /// Output only. The URL of the Instance Group resource.
    public var instanceGroup: Swift.String? = nil

    /// The repair policy for this managed instance group.
    public var instanceLifecyclePolicy: InstanceGroupManagerInstanceLifecyclePolicy? = nil

    /// The URL of the instance template that is specified for this managed
    /// instance group. The group uses this template to create all new instances
    /// in the managed instance group. The templates for existing instances in the
    /// group do not change unless you run recreateInstances, runapplyUpdatesToInstances, or set the group'supdatePolicy.type to PROACTIVE.
    public var instanceTemplate: Swift.String? = nil

    /// Output only. The resource type, which is alwayscompute#instanceGroupManager for managed instance groups.
    public var kind: Swift.String? = nil

    /// Pagination behavior of the listManagedInstances API method for
    /// this managed instance group.
    public var listManagedInstancesResults: InstanceGroupManager.ListManagedInstancesResults? = nil

    /// The name of the managed instance group. The name must be 1-63 characters
    /// long, and comply withRFC1035.
    public var name: Swift.String? = nil

    /// [Output Only] Named ports configured on the Instance Groups complementary
    /// to this Instance Group Manager.
    public var namedPorts: [NamedPort] = []

    /// Output only. [Output Only] The URL of theregion
    /// where the managed instance group resides (for regional resources).
    public var region: Swift.String? = nil

    /// Resource policies for this managed instance group.
    public var resourcePolicies: InstanceGroupManagerResourcePolicies? = nil

    /// Output only. Reserved for future use.
    public var satisfiesPzi: Swift.Bool? = nil

    /// Output only. Reserved for future use.
    public var satisfiesPzs: Swift.Bool? = nil

    /// Output only. The URL for this managed instance group. The server defines
    /// this URL.
    public var selfLink: Swift.String? = nil

    /// Standby policy for stopped and suspended instances.
    public var standbyPolicy: InstanceGroupManagerStandbyPolicy? = nil

    /// Stateful configuration for this Instanced Group Manager
    public var statefulPolicy: StatefulPolicy? = nil

    /// Output only. The status of this managed instance group.
    public var status: InstanceGroupManagerStatus? = nil

    /// The URLs for all TargetPool resources to which instances in theinstanceGroup field are added. The target pools automatically
    /// apply to all of the instances in the managed instance group.
    public var targetPools: [Swift.String] = []

    /// The target number of running instances for this managed instance group.
    /// You can reduce this number by using the instanceGroupManager
    /// deleteInstances or abandonInstances methods. Resizing the group also
    /// changes this number.
    public var targetSize: Swift.Int32? = nil

    /// The policy that specifies how the MIG creates its VMs to achieve the target
    /// size.
    public var targetSizePolicy: InstanceGroupManagerTargetSizePolicy? = nil

    /// The target number of stopped instances for this managed instance group.
    /// This number changes when you:
    ///
    ///    - Stop instance using the stopInstances
    ///    method or start instances using the startInstances
    ///    method.
    ///    - Manually change the targetStoppedSize using the update
    ///    method.
    public var targetStoppedSize: Swift.Int32? = nil

    /// The target number of suspended instances for this managed instance group.
    /// This number changes when you:
    ///
    ///    - Suspend instance using the suspendInstances
    ///    method or resume instances using the resumeInstances
    ///    method.
    ///    - Manually change the targetSuspendedSize using the update
    ///    method.
    public var targetSuspendedSize: Swift.Int32? = nil

    /// The update policy for this managed instance group.
    public var updatePolicy: InstanceGroupManagerUpdatePolicy? = nil

    /// Specifies the instance templates used by this managed instance group to
    /// create instances.
    ///
    /// Each version is defined by an instanceTemplate and aname. Every version can appear at most once per instance
    /// group. This field overrides the top-level instanceTemplate
    /// field. Read more about therelationships
    /// between these fields. Exactly one version must leave thetargetSize field unset. That version will be applied to all
    /// remaining instances. For more information, read aboutcanary
    /// updates.
    public var versions: [InstanceGroupManagerVersion] = []

    /// Output only. The URL of azone
    /// where the managed instance group is located (for zonal resources).
    public var zone: Swift.String? = nil

    /// Initialize a new instance of `InstanceGroupManager`.
    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 = InstanceGroupManager().with { $0.allInstancesConfig = ... }
    /// ```
    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 allInstancesConfig = "allInstancesConfig"
      case autoHealingPolicies = "autoHealingPolicies"
      case baseInstanceName = "baseInstanceName"
      case creationTimestamp = "creationTimestamp"
      case currentActions = "currentActions"
      case description = "description"
      case distributionPolicy = "distributionPolicy"
      case fingerprint = "fingerprint"
      case id = "id"
      case instanceFlexibilityPolicy = "instanceFlexibilityPolicy"
      case instanceGroup = "instanceGroup"
      case instanceLifecyclePolicy = "instanceLifecyclePolicy"
      case instanceTemplate = "instanceTemplate"
      case kind = "kind"
      case listManagedInstancesResults = "listManagedInstancesResults"
      case name = "name"
      case namedPorts = "namedPorts"
      case region = "region"
      case resourcePolicies = "resourcePolicies"
      case satisfiesPzi = "satisfiesPzi"
      case satisfiesPzs = "satisfiesPzs"
      case selfLink = "selfLink"
      case standbyPolicy = "standbyPolicy"
      case statefulPolicy = "statefulPolicy"
      case status = "status"
      case targetPools = "targetPools"
      case targetSize = "targetSize"
      case targetSizePolicy = "targetSizePolicy"
      case targetStoppedSize = "targetStoppedSize"
      case targetSuspendedSize = "targetSuspendedSize"
      case updatePolicy = "updatePolicy"
      case versions = "versions"
      case zone = "zone"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.allInstancesConfig = try container.decodeIfPresent(
        InstanceGroupManagerAllInstancesConfig.self, forKey: .allInstancesConfig)
      self.autoHealingPolicies = try container.decode(
        [InstanceGroupManagerAutoHealingPolicy].self, forKey: .autoHealingPolicies)
      self.baseInstanceName = try container.decodeIfPresent(
        Swift.String.self, forKey: .baseInstanceName)
      self.creationTimestamp = try container.decodeIfPresent(
        Swift.String.self, forKey: .creationTimestamp)
      self.currentActions = try container.decodeIfPresent(
        InstanceGroupManagerActionsSummary.self, forKey: .currentActions)
      self.description = try container.decodeIfPresent(Swift.String.self, forKey: .description)
      self.distributionPolicy = try container.decodeIfPresent(
        DistributionPolicy.self, forKey: .distributionPolicy)
      if let s = try container.decodeIfPresent(Swift.String.self, forKey: .fingerprint) {
        guard let v = GoogleCloudWkt._DiscoveryBase64.decode(s) else {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath, debugDescription: "Expected url-safe encoded value")
          )
        }
        self.fingerprint = v
      }
      self.id = try container.decodeIfPresent(Swift.UInt64.self, forKey: .id)
      self.instanceFlexibilityPolicy = try container.decodeIfPresent(
        InstanceGroupManagerInstanceFlexibilityPolicy.self, forKey: .instanceFlexibilityPolicy)
      self.instanceGroup = try container.decodeIfPresent(Swift.String.self, forKey: .instanceGroup)
      self.instanceLifecyclePolicy = try container.decodeIfPresent(
        InstanceGroupManagerInstanceLifecyclePolicy.self, forKey: .instanceLifecyclePolicy)
      self.instanceTemplate = try container.decodeIfPresent(
        Swift.String.self, forKey: .instanceTemplate)
      self.kind = try container.decodeIfPresent(Swift.String.self, forKey: .kind)
      self.listManagedInstancesResults = try container.decodeIfPresent(
        InstanceGroupManager.ListManagedInstancesResults.self, forKey: .listManagedInstancesResults)
      self.name = try container.decodeIfPresent(Swift.String.self, forKey: .name)
      self.namedPorts = try container.decode([NamedPort].self, forKey: .namedPorts)
      self.region = try container.decodeIfPresent(Swift.String.self, forKey: .region)
      self.resourcePolicies = try container.decodeIfPresent(
        InstanceGroupManagerResourcePolicies.self, forKey: .resourcePolicies)
      self.satisfiesPzi = try container.decodeIfPresent(Swift.Bool.self, forKey: .satisfiesPzi)
      self.satisfiesPzs = try container.decodeIfPresent(Swift.Bool.self, forKey: .satisfiesPzs)
      self.selfLink = try container.decodeIfPresent(Swift.String.self, forKey: .selfLink)
      self.standbyPolicy = try container.decodeIfPresent(
        InstanceGroupManagerStandbyPolicy.self, forKey: .standbyPolicy)
      self.statefulPolicy = try container.decodeIfPresent(
        StatefulPolicy.self, forKey: .statefulPolicy)
      self.status = try container.decodeIfPresent(InstanceGroupManagerStatus.self, forKey: .status)
      self.targetPools = try container.decode([Swift.String].self, forKey: .targetPools)
      self.targetSize = try container.decodeIfPresent(Swift.Int32.self, forKey: .targetSize)
      self.targetSizePolicy = try container.decodeIfPresent(
        InstanceGroupManagerTargetSizePolicy.self, forKey: .targetSizePolicy)
      self.targetStoppedSize = try container.decodeIfPresent(
        Swift.Int32.self, forKey: .targetStoppedSize)
      self.targetSuspendedSize = try container.decodeIfPresent(
        Swift.Int32.self, forKey: .targetSuspendedSize)
      self.updatePolicy = try container.decodeIfPresent(
        InstanceGroupManagerUpdatePolicy.self, forKey: .updatePolicy)
      self.versions = try container.decode([InstanceGroupManagerVersion].self, forKey: .versions)
      self.zone = try container.decodeIfPresent(Swift.String.self, forKey: .zone)
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)
      try container.encode(self.allInstancesConfig, forKey: .allInstancesConfig)
      try container.encode(self.autoHealingPolicies, forKey: .autoHealingPolicies)
      try container.encode(self.baseInstanceName, forKey: .baseInstanceName)
      try container.encode(self.creationTimestamp, forKey: .creationTimestamp)
      try container.encode(self.currentActions, forKey: .currentActions)
      try container.encode(self.description, forKey: .description)
      try container.encode(self.distributionPolicy, forKey: .distributionPolicy)
      if let v = fingerprint {
        try container.encode(
          GoogleCloudWkt._DiscoveryBase64.encode(v), forKey: .fingerprint
        )
      }
      try container.encode(self.id, forKey: .id)
      try container.encode(self.instanceFlexibilityPolicy, forKey: .instanceFlexibilityPolicy)
      try container.encode(self.instanceGroup, forKey: .instanceGroup)
      try container.encode(self.instanceLifecyclePolicy, forKey: .instanceLifecyclePolicy)
      try container.encode(self.instanceTemplate, forKey: .instanceTemplate)
      try container.encode(self.kind, forKey: .kind)
      try container.encode(self.listManagedInstancesResults, forKey: .listManagedInstancesResults)
      try container.encode(self.name, forKey: .name)
      try container.encode(self.namedPorts, forKey: .namedPorts)
      try container.encode(self.region, forKey: .region)
      try container.encode(self.resourcePolicies, forKey: .resourcePolicies)
      try container.encode(self.satisfiesPzi, forKey: .satisfiesPzi)
      try container.encode(self.satisfiesPzs, forKey: .satisfiesPzs)
      try container.encode(self.selfLink, forKey: .selfLink)
      try container.encode(self.standbyPolicy, forKey: .standbyPolicy)
      try container.encode(self.statefulPolicy, forKey: .statefulPolicy)
      try container.encode(self.status, forKey: .status)
      try container.encode(self.targetPools, forKey: .targetPools)
      try container.encode(self.targetSize, forKey: .targetSize)
      try container.encode(self.targetSizePolicy, forKey: .targetSizePolicy)
      try container.encode(self.targetStoppedSize, forKey: .targetStoppedSize)
      try container.encode(self.targetSuspendedSize, forKey: .targetSuspendedSize)
      try container.encode(self.updatePolicy, forKey: .updatePolicy)
      try container.encode(self.versions, forKey: .versions)
      try container.encode(self.zone, forKey: .zone)
    }

    /// The enumerated type for the [listManagedInstancesResults][google.cloud.compute.v1.InstanceGroupManager.listManagedInstancesResults] field.
    ///
    /// [google.cloud.compute.v1.InstanceGroupManager.listManagedInstancesResults]: <doc:InstanceGroupManager/ListManagedInstancesResults>
    public enum ListManagedInstancesResults: Codable, Equatable, Sendable {
      /// (Default) Pagination is disabled for the group'slistManagedInstances API method. maxResults
      /// and pageToken query parameters are ignored and all
      /// instances are returned in a single response.
      case pageless
      /// Pagination is enabled for the group's listManagedInstances
      /// API method. maxResults and pageToken query
      /// parameters are respected.
      case paginated
      /// 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 = .pageless
      }

      /// 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 .pageless: return 0
        case .paginated: 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 .pageless: return "PAGELESS"
        case .paginated: return "PAGINATED"
        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:ListManagedInstancesResults/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "PAGELESS": self = .pageless
        case "PAGINATED": self = .paginated
        default: self = .unknownStringValue(stringValue)
        }
      }

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