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

  /// Subnetwork which the current user has compute.subnetworks.use permission on.
  public struct UsableSubnetwork: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Output only. [Output Only] The external IPv6 address range that is assigned to this
    /// subnetwork.
    public var externalIpv6Prefix: Swift.String? = nil

    /// Output only. [Output Only] The internal IPv6 address range that is assigned to this
    /// subnetwork.
    public var internalIpv6Prefix: Swift.String? = nil

    /// The range of internal addresses that are owned by this subnetwork.
    public var ipCidrRange: Swift.String? = nil

    /// The access type of IPv6 address this subnet holds. It's immutable and can
    /// only be specified during creation or the first time the subnet is updated
    /// into IPV4_IPV6 dual stack.
    public var ipv6AccessType: UsableSubnetwork.Ipv6AccessType? = nil

    /// Network URL.
    public var network: Swift.String? = nil

    public var purpose: UsableSubnetwork.Purpose? = nil

    /// The role of subnetwork. Currently, this field is only used when
    /// purpose is set to GLOBAL_MANAGED_PROXY orREGIONAL_MANAGED_PROXY. The value can be set toACTIVE or BACKUP. An ACTIVE
    /// subnetwork is one that is currently being used for Envoy-based load
    /// balancers in a region. A BACKUP subnetwork is one that is
    /// ready to be promoted to ACTIVE or is currently draining.
    /// This field can be updated with a patch request.
    public var role: UsableSubnetwork.Role? = nil

    /// Secondary IP ranges.
    public var secondaryIpRanges: [UsableSubnetworkSecondaryRange] = []

    /// The stack type for the subnet. If set to IPV4_ONLY, new VMs
    /// in the subnet are assigned IPv4 addresses only. If set toIPV4_IPV6, new VMs in the subnet can be assigned both IPv4 and
    /// IPv6 addresses. If not specified, IPV4_ONLY is used.
    ///
    /// This field can be both set at resource creation time and updated usingpatch.
    public var stackType: UsableSubnetwork.StackType? = nil

    /// Subnetwork URL.
    public var subnetwork: Swift.String? = nil

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

    /// The enumerated type for the [ipv6AccessType][google.cloud.compute.v1.UsableSubnetwork.ipv6AccessType] field.
    ///
    /// [google.cloud.compute.v1.UsableSubnetwork.ipv6AccessType]: <doc:UsableSubnetwork/Ipv6AccessType>
    public enum Ipv6AccessType: Codable, Equatable, Sendable {
      /// VMs on this subnet will be assigned IPv6 addresses that are accessible
      /// via the Internet, as well as the VPC network.
      case external
      /// VMs on this subnet will be assigned IPv6 addresses that are only
      /// accessible over the VPC network.
      case `internal`
      /// 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 = .external
      }

      /// 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 .external: return 0
        case .`internal`: 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 .external: return "EXTERNAL"
        case .`internal`: return "INTERNAL"
        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:Ipv6AccessType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "EXTERNAL": self = .external
        case "INTERNAL": self = .`internal`
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Ipv6AccessType/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .external
        case 1: self = .`internal`
        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 .external: return try container.encode(0)
        case .`internal`: 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 [purpose][google.cloud.compute.v1.UsableSubnetwork.purpose] field.
    ///
    /// [google.cloud.compute.v1.UsableSubnetwork.purpose]: <doc:UsableSubnetwork/Purpose>
    public enum Purpose: Codable, Equatable, Sendable {
      /// Subnet reserved for Global Envoy-based Load Balancing.
      case globalManagedProxy
      /// Subnet reserved for Internal HTTP(S) Load Balancing. This is a legacy
      /// purpose, please use REGIONAL_MANAGED_PROXY instead.
      case internalHttpsLoadBalancer
      /// Subnetwork will be used for Migration from one peered VPC to another.
      /// (a transient state of subnetwork
      /// while migrating resources from one project to another).
      case peerMigration
      /// Regular user created or automatically created subnet.
      case `private`
      /// Subnetwork used as source range for Private NAT Gateways.
      case privateNat
      /// Regular user created or automatically created subnet.
      case privateRfc1918
      /// Subnetworks created for Private Service Connect in the producer network.
      case privateServiceConnect
      /// Subnetwork used for Regional Envoy-based Load Balancing.
      case regionalManagedProxy
      /// 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 = .globalManagedProxy
      }

      /// 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 .globalManagedProxy: return 0
        case .internalHttpsLoadBalancer: return 1
        case .peerMigration: return 2
        case .`private`: return 3
        case .privateNat: return 4
        case .privateRfc1918: return 5
        case .privateServiceConnect: return 6
        case .regionalManagedProxy: return 7
        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 .globalManagedProxy: return "GLOBAL_MANAGED_PROXY"
        case .internalHttpsLoadBalancer: return "INTERNAL_HTTPS_LOAD_BALANCER"
        case .peerMigration: return "PEER_MIGRATION"
        case .`private`: return "PRIVATE"
        case .privateNat: return "PRIVATE_NAT"
        case .privateRfc1918: return "PRIVATE_RFC_1918"
        case .privateServiceConnect: return "PRIVATE_SERVICE_CONNECT"
        case .regionalManagedProxy: return "REGIONAL_MANAGED_PROXY"
        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:Purpose/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "GLOBAL_MANAGED_PROXY": self = .globalManagedProxy
        case "INTERNAL_HTTPS_LOAD_BALANCER": self = .internalHttpsLoadBalancer
        case "PEER_MIGRATION": self = .peerMigration
        case "PRIVATE": self = .`private`
        case "PRIVATE_NAT": self = .privateNat
        case "PRIVATE_RFC_1918": self = .privateRfc1918
        case "PRIVATE_SERVICE_CONNECT": self = .privateServiceConnect
        case "REGIONAL_MANAGED_PROXY": self = .regionalManagedProxy
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Purpose/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .globalManagedProxy
        case 1: self = .internalHttpsLoadBalancer
        case 2: self = .peerMigration
        case 3: self = .`private`
        case 4: self = .privateNat
        case 5: self = .privateRfc1918
        case 6: self = .privateServiceConnect
        case 7: self = .regionalManagedProxy
        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 .globalManagedProxy: return try container.encode(0)
        case .internalHttpsLoadBalancer: return try container.encode(1)
        case .peerMigration: return try container.encode(2)
        case .`private`: return try container.encode(3)
        case .privateNat: return try container.encode(4)
        case .privateRfc1918: return try container.encode(5)
        case .privateServiceConnect: return try container.encode(6)
        case .regionalManagedProxy: return try container.encode(7)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

    /// The enumerated type for the [role][google.cloud.compute.v1.UsableSubnetwork.role] field.
    ///
    /// [google.cloud.compute.v1.UsableSubnetwork.role]: <doc:UsableSubnetwork/Role>
    public enum Role: Codable, Equatable, Sendable {
      /// The ACTIVE subnet that is currently used.
      case active
      /// The BACKUP subnet that could be promoted to ACTIVE.
      case backup
      /// 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 = .active
      }

      /// 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 .active: return 0
        case .backup: 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 .active: return "ACTIVE"
        case .backup: return "BACKUP"
        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:Role/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "ACTIVE": self = .active
        case "BACKUP": self = .backup
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Role/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .active
        case 1: self = .backup
        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 .active: return try container.encode(0)
        case .backup: 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 [stackType][google.cloud.compute.v1.UsableSubnetwork.stackType] field.
    ///
    /// [google.cloud.compute.v1.UsableSubnetwork.stackType]: <doc:UsableSubnetwork/StackType>
    public enum StackType: Codable, Equatable, Sendable {
      /// New VMs in this subnet can have both IPv4 and IPv6 addresses.
      case ipv4Ipv6
      /// New VMs in this subnet will only be assigned IPv4 addresses.
      case ipv4Only
      /// New VMs in this subnet will only be assigned IPv6 addresses.
      case ipv6Only
      /// 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 = .ipv4Ipv6
      }

      /// 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 .ipv4Ipv6: return 0
        case .ipv4Only: return 1
        case .ipv6Only: 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 .ipv4Ipv6: return "IPV4_IPV6"
        case .ipv4Only: return "IPV4_ONLY"
        case .ipv6Only: return "IPV6_ONLY"
        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:StackType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "IPV4_IPV6": self = .ipv4Ipv6
        case "IPV4_ONLY": self = .ipv4Only
        case "IPV6_ONLY": self = .ipv6Only
        default: self = .unknownStringValue(stringValue)
        }
      }

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