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

/// Namespace for instance state enums.
public struct Instance: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Initialize a new instance of `Instance`.
  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 = Instance().with { $0.<placeholder> = ... }
  /// ```
  public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
    var copy = self
    try config(&copy)
    return copy
  }

  /// Patch state of an instance.
  public enum PatchState: Codable, Equatable, Sendable {
    /// Unspecified.
    case unspecified
    /// The instance is not yet notified.
    case pending
    /// Instance is inactive and cannot be patched.
    case inactive
    /// The instance is notified that it should be patched.
    case notified
    /// The instance has started the patching process.
    case started
    /// The instance is downloading patches.
    case downloadingPatches
    /// The instance is applying patches.
    case applyingPatches
    /// The instance is rebooting.
    case rebooting
    /// The instance has completed applying patches.
    case succeeded
    /// The instance has completed applying patches but a reboot is required.
    case succeededRebootRequired
    /// The instance has failed to apply the patch.
    case failed
    /// The instance acked the notification and will start shortly.
    case acked
    /// The instance exceeded the time out while applying the patch.
    case timedOut
    /// The instance is running the pre-patch step.
    case runningPrePatchStep
    /// The instance is running the post-patch step.
    case runningPostPatchStep
    /// The service could not detect the presence of the agent. Check to ensure
    /// that the agent is installed, running, and able to communicate with the
    /// service.
    case noAgentDetected
    /// 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 = .unspecified
    }

    /// 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 .unspecified: return 0
      case .pending: return 1
      case .inactive: return 2
      case .notified: return 3
      case .started: return 4
      case .downloadingPatches: return 5
      case .applyingPatches: return 6
      case .rebooting: return 7
      case .succeeded: return 8
      case .succeededRebootRequired: return 9
      case .failed: return 10
      case .acked: return 11
      case .timedOut: return 12
      case .runningPrePatchStep: return 13
      case .runningPostPatchStep: return 14
      case .noAgentDetected: return 15
      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 .unspecified: return "PATCH_STATE_UNSPECIFIED"
      case .pending: return "PENDING"
      case .inactive: return "INACTIVE"
      case .notified: return "NOTIFIED"
      case .started: return "STARTED"
      case .downloadingPatches: return "DOWNLOADING_PATCHES"
      case .applyingPatches: return "APPLYING_PATCHES"
      case .rebooting: return "REBOOTING"
      case .succeeded: return "SUCCEEDED"
      case .succeededRebootRequired: return "SUCCEEDED_REBOOT_REQUIRED"
      case .failed: return "FAILED"
      case .acked: return "ACKED"
      case .timedOut: return "TIMED_OUT"
      case .runningPrePatchStep: return "RUNNING_PRE_PATCH_STEP"
      case .runningPostPatchStep: return "RUNNING_POST_PATCH_STEP"
      case .noAgentDetected: return "NO_AGENT_DETECTED"
      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:PatchState/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "PATCH_STATE_UNSPECIFIED": self = .unspecified
      case "PENDING": self = .pending
      case "INACTIVE": self = .inactive
      case "NOTIFIED": self = .notified
      case "STARTED": self = .started
      case "DOWNLOADING_PATCHES": self = .downloadingPatches
      case "APPLYING_PATCHES": self = .applyingPatches
      case "REBOOTING": self = .rebooting
      case "SUCCEEDED": self = .succeeded
      case "SUCCEEDED_REBOOT_REQUIRED": self = .succeededRebootRequired
      case "FAILED": self = .failed
      case "ACKED": self = .acked
      case "TIMED_OUT": self = .timedOut
      case "RUNNING_PRE_PATCH_STEP": self = .runningPrePatchStep
      case "RUNNING_POST_PATCH_STEP": self = .runningPostPatchStep
      case "NO_AGENT_DETECTED": self = .noAgentDetected
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:PatchState/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .pending
      case 2: self = .inactive
      case 3: self = .notified
      case 4: self = .started
      case 5: self = .downloadingPatches
      case 6: self = .applyingPatches
      case 7: self = .rebooting
      case 8: self = .succeeded
      case 9: self = .succeededRebootRequired
      case 10: self = .failed
      case 11: self = .acked
      case 12: self = .timedOut
      case 13: self = .runningPrePatchStep
      case 14: self = .runningPostPatchStep
      case 15: self = .noAgentDetected
      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 .unspecified: return try container.encode(0)
      case .pending: return try container.encode(1)
      case .inactive: return try container.encode(2)
      case .notified: return try container.encode(3)
      case .started: return try container.encode(4)
      case .downloadingPatches: return try container.encode(5)
      case .applyingPatches: return try container.encode(6)
      case .rebooting: return try container.encode(7)
      case .succeeded: return try container.encode(8)
      case .succeededRebootRequired: return try container.encode(9)
      case .failed: return try container.encode(10)
      case .acked: return try container.encode(11)
      case .timedOut: return try container.encode(12)
      case .runningPrePatchStep: return try container.encode(13)
      case .runningPostPatchStep: return try container.encode(14)
      case .noAgentDetected: return try container.encode(15)
      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.osconfig.v1.Instance"
  }
  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)
  }
}
