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

  public struct PerInstanceConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Fingerprint of this per-instance config. This field can be used in
    /// optimistic locking. It is ignored when inserting a per-instance
    /// config. An up-to-date fingerprint must be provided in order to update an
    /// existing per-instance configuration or the field needs to be unset.
    public var fingerprint: Foundation.Data? = nil

    /// The name of a per-instance configuration and its corresponding instance.
    /// Serves as a merge key during UpdatePerInstanceConfigs
    /// operations, that is, if a per-instance configuration with the same name
    /// exists then it will be updated, otherwise a new one will be created for the
    /// VM instance with the same name. An attempt to create a per-instance
    /// configuration for a VM instance that either doesn't exist or is not part
    /// of the group will result in an error.
    public var name: Swift.String? = nil

    /// The intended preserved state for the given instance. Does not contain
    /// preserved state generated from a stateful policy.
    public var preservedState: PreservedState? = nil

    /// The status of applying this per-instance configuration on the corresponding
    /// managed instance.
    public var status: PerInstanceConfig.Status? = nil

    /// Initialize a new instance of `PerInstanceConfig`.
    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 = PerInstanceConfig().with { $0.fingerprint = ... }
    /// ```
    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 fingerprint = "fingerprint"
      case name = "name"
      case preservedState = "preservedState"
      case status = "status"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      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.name = try container.decodeIfPresent(Swift.String.self, forKey: .name)
      self.preservedState = try container.decodeIfPresent(
        PreservedState.self, forKey: .preservedState)
      self.status = try container.decodeIfPresent(PerInstanceConfig.Status.self, forKey: .status)
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)
      if let v = fingerprint {
        try container.encode(
          GoogleCloudWkt._DiscoveryBase64.encode(v), forKey: .fingerprint
        )
      }
      try container.encode(self.name, forKey: .name)
      try container.encode(self.preservedState, forKey: .preservedState)
      try container.encode(self.status, forKey: .status)
    }

    /// The enumerated type for the [status][google.cloud.compute.v1.PerInstanceConfig.status] field.
    ///
    /// [google.cloud.compute.v1.PerInstanceConfig.status]: <doc:PerInstanceConfig/Status>
    public enum Status: Codable, Equatable, Sendable {
      /// The per-instance configuration is being applied to the instance, but is
      /// not yet effective, possibly waiting for the instance to, for example,REFRESH.
      case applying
      /// The per-instance configuration deletion is being applied on the instance,
      /// possibly waiting for the instance to, for example, REFRESH.
      case deleting
      /// The per-instance configuration is effective on the instance, meaning that
      /// all disks, ips and metadata specified in this configuration are attached
      /// or set on the instance.
      case effective
      /// *[Default]* The default status, when no per-instance configuration
      /// exists.
      case `none`
      /// The per-instance configuration is set on an instance but not been applied
      /// yet.
      case unapplied
      /// The per-instance configuration has been deleted, but the deletion is not
      /// yet applied.
      case unappliedDeletion
      /// 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 = .applying
      }

      /// 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 .applying: return 0
        case .deleting: return 1
        case .effective: return 2
        case .`none`: return 3
        case .unapplied: return 4
        case .unappliedDeletion: return 5
        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 .applying: return "APPLYING"
        case .deleting: return "DELETING"
        case .effective: return "EFFECTIVE"
        case .`none`: return "NONE"
        case .unapplied: return "UNAPPLIED"
        case .unappliedDeletion: return "UNAPPLIED_DELETION"
        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:Status/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "APPLYING": self = .applying
        case "DELETING": self = .deleting
        case "EFFECTIVE": self = .effective
        case "NONE": self = .`none`
        case "UNAPPLIED": self = .unapplied
        case "UNAPPLIED_DELETION": self = .unappliedDeletion
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Status/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .applying
        case 1: self = .deleting
        case 2: self = .effective
        case 3: self = .`none`
        case 4: self = .unapplied
        case 5: self = .unappliedDeletion
        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 .applying: return try container.encode(0)
        case .deleting: return try container.encode(1)
        case .effective: return try container.encode(2)
        case .`none`: return try container.encode(3)
        case .unapplied: return try container.encode(4)
        case .unappliedDeletion: return try container.encode(5)
        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.PerInstanceConfig"
    }
    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
