// 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 InstanceTemplates || Instances || MachineImages || RegionInstanceTemplates || RegionInstances
  import Foundation
  import GoogleCloudWkt

  /// Sets the scheduling options for an Instance.
  public struct Scheduling: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Specifies whether the instance should be automatically restarted if it is
    /// terminated by Compute Engine (not terminated by a user). You can only set
    /// the automatic restart option for standard instances.Preemptible instances
    /// cannot be automatically restarted.
    ///
    /// By default, this is set to true so an instance is
    /// automatically restarted if it is terminated by Compute Engine.
    public var automaticRestart: Swift.Bool? = nil

    /// Specifies the availability domain to place the instance in. The value
    /// must be a number between 1 and the number of availability domains
    /// specified in the spread placement policy attached to the instance.
    public var availabilityDomain: Swift.Int32? = nil

    public var gracefulShutdown: SchedulingGracefulShutdown? = nil

    /// Specify the time in seconds for host error detection, the value must be
    /// within the range of [90, 330] with the increment of 30, if unset, the
    /// default behavior of host error recovery will be used.
    public var hostErrorTimeoutSeconds: Swift.Int32? = nil

    /// Specifies the termination action for the instance.
    public var instanceTerminationAction: Scheduling.InstanceTerminationAction? = nil

    /// Specifies the maximum amount of time a Local Ssd Vm should wait while
    /// recovery of the Local Ssd state is attempted. Its value should be in
    /// between 0 and 168 hours with hour granularity and the default value being 1
    /// hour.
    public var localSsdRecoveryTimeout: Duration? = nil

    /// An opaque location hint used to place the instance close to other
    /// resources.
    /// This field is for use by internal tools that use the public API.
    public var locationHint: Swift.String? = nil

    /// Specifies the max run duration for the given instance. If specified,
    /// the instance termination action will be performed at the end of the run
    /// duration.
    public var maxRunDuration: Duration? = nil

    /// The minimum number of virtual CPUs this instance will consume when running
    /// on a sole-tenant node.
    public var minNodeCpus: Swift.Int32? = nil

    /// A set of node affinity and anti-affinity configurations. Refer toConfiguring node
    /// affinity for more information.
    /// Overrides reservationAffinity.
    public var nodeAffinities: [SchedulingNodeAffinity] = []

    /// Defines the maintenance behavior for this instance. For standard instances,
    /// the default behavior is MIGRATE. Forpreemptible instances,
    /// the default and only possible behavior is TERMINATE. For more
    /// information, see
    ///  Set
    ///  VM host maintenance policy.
    public var onHostMaintenance: Scheduling.OnHostMaintenance? = nil

    public var onInstanceStopAction: SchedulingOnInstanceStopAction? = nil

    /// Defines whether the instance is preemptible. This can only be set during
    /// instance creation or while the instance isstopped and
    /// therefore, in a `TERMINATED` state. SeeInstance Life
    /// Cycle for more information on the possible instance states.
    public var preemptible: Swift.Bool? = nil

    /// Specifies the Metadata Service preemption notice duration before the GCE ACPI G2
    /// Soft Off signal is triggered for Spot VMs only. If not specified,
    /// there will be no wait before the G2 Soft Off signal is triggered.
    public var preemptionNoticeDuration: Duration? = nil

    /// Specifies the provisioning model of the instance.
    public var provisioningModel: Scheduling.ProvisioningModel? = nil

    /// Default is false and there will be 120 seconds between GCE ACPI G2 Soft
    /// Off and ACPI G3 Mechanical
    /// Off for Standard VMs and 30 seconds for Spot VMs.
    public var skipGuestOsShutdown: Swift.Bool? = nil

    /// Specifies the timestamp, when the instance will be terminated, inRFC3339 text format. If specified, the instance
    /// termination action will be performed at the termination time.
    public var terminationTime: Swift.String? = nil

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

    /// The enumerated type for the [instanceTerminationAction][google.cloud.compute.v1.Scheduling.instanceTerminationAction] field.
    ///
    /// [google.cloud.compute.v1.Scheduling.instanceTerminationAction]: <doc:Scheduling/InstanceTerminationAction>
    public enum InstanceTerminationAction: Codable, Equatable, Sendable {
      /// Delete the VM.
      case delete
      /// Default value. This value is unused.
      case unspecified
      /// Stop the VM without storing in-memory content. default action.
      case stop
      /// 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 = .delete
      }

      /// 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 .delete: return 0
        case .unspecified: return 1
        case .stop: 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 .delete: return "DELETE"
        case .unspecified: return "INSTANCE_TERMINATION_ACTION_UNSPECIFIED"
        case .stop: return "STOP"
        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:InstanceTerminationAction/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "DELETE": self = .delete
        case "INSTANCE_TERMINATION_ACTION_UNSPECIFIED": self = .unspecified
        case "STOP": self = .stop
        default: self = .unknownStringValue(stringValue)
        }
      }

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

    /// The enumerated type for the [onHostMaintenance][google.cloud.compute.v1.Scheduling.onHostMaintenance] field.
    ///
    /// [google.cloud.compute.v1.Scheduling.onHostMaintenance]: <doc:Scheduling/OnHostMaintenance>
    public enum OnHostMaintenance: Codable, Equatable, Sendable {
      /// *[Default]* Allows Compute Engine to automatically migrate instances
      /// out of the way of maintenance events.
      case migrate
      /// Tells Compute Engine to terminate and (optionally) restart the instance
      /// away from the maintenance activity. If you would like your instance to be
      /// restarted, set the automaticRestart flag to true. Your
      /// instance may be restarted more than once, and it may be restarted outside
      /// the window of maintenance events.
      case terminate
      /// 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 = .migrate
      }

      /// 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 .migrate: return 0
        case .terminate: 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 .migrate: return "MIGRATE"
        case .terminate: return "TERMINATE"
        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:OnHostMaintenance/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "MIGRATE": self = .migrate
        case "TERMINATE": self = .terminate
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:OnHostMaintenance/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .migrate
        case 1: self = .terminate
        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 .migrate: return try container.encode(0)
        case .terminate: 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 [provisioningModel][google.cloud.compute.v1.Scheduling.provisioningModel] field.
    ///
    /// [google.cloud.compute.v1.Scheduling.provisioningModel]: <doc:Scheduling/ProvisioningModel>
    public enum ProvisioningModel: Codable, Equatable, Sendable {
      /// Instance is provisioned using the Flex Start provisioning model and
      /// has a limited runtime.
      case flexStart
      /// Bound to the lifecycle of the reservation in which it is provisioned.
      case reservationBound
      /// Heavily discounted, no guaranteed runtime.
      case spot
      /// Standard provisioning with user controlled runtime, no discounts.
      case standard
      /// 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 = .flexStart
      }

      /// 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 .flexStart: return 0
        case .reservationBound: return 1
        case .spot: return 2
        case .standard: 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 .flexStart: return "FLEX_START"
        case .reservationBound: return "RESERVATION_BOUND"
        case .spot: return "SPOT"
        case .standard: return "STANDARD"
        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:ProvisioningModel/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "FLEX_START": self = .flexStart
        case "RESERVATION_BOUND": self = .reservationBound
        case "SPOT": self = .spot
        case "STANDARD": self = .standard
        default: self = .unknownStringValue(stringValue)
        }
      }

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