// 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 BackendServices || RegionBackendServices
  import Foundation
  import GoogleCloudWkt

  /// Message containing information of one individual backend.
  public struct Backend: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Specifies how to determine whether the backend of a load balancer can
    /// handle additional traffic or is fully loaded. For usage guidelines, see
    /// Connection balancing mode.
    ///
    /// Backends must use compatible balancing modes. For more information, see
    /// Supported balancing modes and target capacity settings and
    /// Restrictions and guidance for instance groups.
    ///
    /// Note: Currently, if you use the API to configure incompatible balancing
    /// modes, the configuration might be accepted even though it has no impact
    /// and is ignored. Specifically, Backend.maxUtilization is ignored when
    /// Backend.balancingMode is RATE. In the future, this incompatible combination
    /// will be rejected.
    public var balancingMode: Backend.BalancingMode? = nil

    /// A multiplier applied to the backend's target capacity of its balancing
    /// mode.
    /// The default value is 1, which means the group serves up to
    /// 100% of its configured capacity (depending onbalancingMode). A setting of 0 means the group is
    /// completely drained, offering 0% of its available capacity. The valid ranges
    /// are 0.0 and [0.1,1.0].
    /// You cannot configure a setting larger than 0 and smaller than0.1.
    /// You cannot configure a setting of 0 when there is only one
    /// backend attached to the backend service.
    ///
    /// Not available with backends that don't support using abalancingMode. This includes backends such as global
    /// internet NEGs, regional serverless NEGs, and PSC NEGs.
    public var capacityScaler: Swift.Float? = nil

    /// List of custom metrics that are used for CUSTOM_METRICS
    /// BalancingMode.
    public var customMetrics: [BackendCustomMetric] = []

    /// An optional description of this resource. Provide this property when you
    /// create the resource.
    public var description: Swift.String? = nil

    /// This field designates whether this is a failover backend. More than one
    /// failover backend can be configured for a given BackendService.
    public var failover: Swift.Bool? = nil

    /// The fully-qualified URL of aninstance
    /// group or network endpoint
    /// group (NEG) resource. To determine what types of backends a load
    /// balancer supports, see the [Backend services
    /// overview](https://cloud.google.com/load-balancing/docs/backend-service#backends).
    ///
    /// You must use the *fully-qualified* URL (starting withhttps://www.googleapis.com/) to specify the instance group
    /// or NEG. Partial URLs are not supported.
    ///
    /// If haPolicy is specified, backends must refer to NEG resources of type
    /// GCE_VM_IP.
    public var group: Swift.String? = nil

    /// Defines a target maximum number of simultaneous connections. For usage
    /// guidelines, seeConnection
    /// balancing mode and Utilization
    /// balancing mode. Not available if the backend'sbalancingMode is RATE.
    public var maxConnections: Swift.Int32? = nil

    /// Defines a target maximum number of simultaneous connections.  For usage
    /// guidelines, seeConnection
    /// balancing mode and Utilization
    /// balancing mode.
    ///
    /// Not available if the backend's balancingMode isRATE.
    public var maxConnectionsPerEndpoint: Swift.Int32? = nil

    /// Defines a target maximum number of simultaneous connections.
    /// For usage guidelines, seeConnection
    /// balancing mode and Utilization
    /// balancing mode.
    ///
    /// Not available if the backend's balancingMode isRATE.
    public var maxConnectionsPerInstance: Swift.Int32? = nil

    /// Defines a maximum number of in-flight requests for the whole NEG or
    /// instance group. Not available if backend's balancingMode isRATE or CONNECTION.
    public var maxInFlightRequests: Swift.Int32? = nil

    /// Defines a maximum number of in-flight requests for a single endpoint.
    /// Not available if backend's balancingMode is RATE
    /// or CONNECTION.
    public var maxInFlightRequestsPerEndpoint: Swift.Int32? = nil

    /// Defines a maximum number of in-flight requests for a single VM.
    /// Not available if backend's balancingMode is RATE
    /// or CONNECTION.
    public var maxInFlightRequestsPerInstance: Swift.Int32? = nil

    /// Defines a maximum number of HTTP requests per second (RPS). For
    /// usage guidelines, seeRate
    /// balancing mode and Utilization
    /// balancing mode.
    ///
    /// Not available if the backend's balancingMode isCONNECTION.
    public var maxRate: Swift.Int32? = nil

    /// Defines a maximum target for requests per second (RPS). For usage
    /// guidelines, seeRate
    /// balancing mode and Utilization
    /// balancing mode.
    ///
    /// Not available if the backend's balancingMode isCONNECTION.
    public var maxRatePerEndpoint: Swift.Float? = nil

    /// Defines a maximum target for requests per second (RPS). For usage
    /// guidelines, seeRate
    /// balancing mode and Utilization
    /// balancing mode.
    ///
    /// Not available if the backend's balancingMode isCONNECTION.
    public var maxRatePerInstance: Swift.Float? = nil

    /// Optional parameter to define a target capacity for theUTILIZATION balancing mode. The valid range is[0.0, 1.0].
    ///
    /// For usage guidelines, seeUtilization
    /// balancing mode.
    public var maxUtilization: Swift.Float? = nil

    /// Information about the resource or system that manages the backend.
    public var orchestrationInfo: BackendBackendOrchestrationInfo? = nil

    /// This field indicates whether this backend should be fully utilized before
    /// sending traffic to backends with default preference. The possible values
    /// are:
    ///
    ///    - PREFERRED: Backends with this preference level will be
    ///    filled up to their capacity limits first, based on RTT.
    ///    - DEFAULT:  If preferred backends don't have enough
    ///    capacity, backends in this layer would be used and traffic would be
    ///    assigned based on the load balancing algorithm you use. This is the
    ///    default
    public var preference: Backend.Preference? = nil

    public var trafficDuration: Backend.TrafficDuration? = nil

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

    /// The enumerated type for the [balancingMode][google.cloud.compute.v1.Backend.balancingMode] field.
    ///
    /// [google.cloud.compute.v1.Backend.balancingMode]: <doc:Backend/BalancingMode>
    public enum BalancingMode: Codable, Equatable, Sendable {
      /// Balance based on the number of simultaneous connections.
      case connection
      /// Based on custom defined and reported metrics.
      case customMetrics
      /// Balance based on the number of in-flight requests.
      case inFlight
      /// Balance based on requests per second (RPS).
      case rate
      /// Balance based on the backend utilization.
      case utilization
      /// 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 = .connection
      }

      /// 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 .connection: return 0
        case .customMetrics: return 1
        case .inFlight: return 2
        case .rate: return 3
        case .utilization: return 4
        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 .connection: return "CONNECTION"
        case .customMetrics: return "CUSTOM_METRICS"
        case .inFlight: return "IN_FLIGHT"
        case .rate: return "RATE"
        case .utilization: return "UTILIZATION"
        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:BalancingMode/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "CONNECTION": self = .connection
        case "CUSTOM_METRICS": self = .customMetrics
        case "IN_FLIGHT": self = .inFlight
        case "RATE": self = .rate
        case "UTILIZATION": self = .utilization
        default: self = .unknownStringValue(stringValue)
        }
      }

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

    /// The enumerated type for the [preference][google.cloud.compute.v1.Backend.preference] field.
    ///
    /// [google.cloud.compute.v1.Backend.preference]: <doc:Backend/Preference>
    public enum Preference: Codable, Equatable, Sendable {
      /// No preference.
      case `default`
      /// If preference is unspecified, we set it to the DEFAULT value
      case unspecified
      /// Traffic will be sent to this backend first.
      case preferred
      /// 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 = .`default`
      }

      /// 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 .`default`: return 0
        case .unspecified: return 1
        case .preferred: 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 .`default`: return "DEFAULT"
        case .unspecified: return "PREFERENCE_UNSPECIFIED"
        case .preferred: return "PREFERRED"
        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:Preference/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "DEFAULT": self = .`default`
        case "PREFERENCE_UNSPECIFIED": self = .unspecified
        case "PREFERRED": self = .preferred
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Preference/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .`default`
        case 1: self = .unspecified
        case 2: self = .preferred
        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 .`default`: return try container.encode(0)
        case .unspecified: return try container.encode(1)
        case .preferred: 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 [trafficDuration][google.cloud.compute.v1.Backend.trafficDuration] field.
    ///
    /// [google.cloud.compute.v1.Backend.trafficDuration]: <doc:Backend/TrafficDuration>
    public enum TrafficDuration: Codable, Equatable, Sendable {
      /// Most of the requests are expected to take more than multiple seconds to
      /// finish.
      case long
      /// Most requests are expected to finish with a sub-second latency.
      case short
      /// Traffic duration is unspecified.
      case unspecified
      /// 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 = .long
      }

      /// 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 .long: return 0
        case .short: return 1
        case .unspecified: 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 .long: return "LONG"
        case .short: return "SHORT"
        case .unspecified: return "TRAFFIC_DURATION_UNSPECIFIED"
        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:TrafficDuration/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "LONG": self = .long
        case "SHORT": self = .short
        case "TRAFFIC_DURATION_UNSPECIFIED": self = .unspecified
        default: self = .unknownStringValue(stringValue)
        }
      }

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