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

  /// The available logging options for this subnetwork.
  public struct SubnetworkLogConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Can only be specified if VPC flow logging for this subnetwork is enabled.
    /// Toggles the aggregation interval for collecting flow logs. Increasing the
    /// interval time will reduce the amount of generated flow logs for long
    /// lasting connections. Default is an interval of 5 seconds per connection.
    public var aggregationInterval: SubnetworkLogConfig.AggregationInterval? = nil

    /// Whether to enable flow logging for this subnetwork. If this field is not
    /// explicitly set, it will not appear in get listings. If not
    /// set the default behavior is determined by the org policy, if there is no
    /// org policy specified, then it will default to disabled.
    /// Flow logging isn't supported if the subnet purpose field is
    /// set to REGIONAL_MANAGED_PROXY.
    public var enable: Swift.Bool? = nil

    /// Can only be specified if VPC flow logs for this subnetwork is enabled.
    /// The filter expression is used to define which VPC flow logs should be
    /// exported to Cloud Logging.
    public var filterExpr: Swift.String? = nil

    /// Can only be specified if VPC flow logging for this subnetwork is enabled.
    /// The value of the field must be in [0, 1]. Set the sampling rate of VPC
    /// flow logs within the subnetwork where 1.0 means all collected logs are
    /// reported and 0.0 means no logs are reported. Default is 0.5 unless
    /// otherwise specified by the org policy, which means half of all collected
    /// logs are reported.
    public var flowSampling: Swift.Float? = nil

    /// Can only be specified if VPC flow logs for this subnetwork is enabled.
    /// Configures whether all, none or a subset of metadata fields should be
    /// added to the reported VPC flow logs. Default isEXCLUDE_ALL_METADATA.
    public var metadata: SubnetworkLogConfig.Metadata? = nil

    /// Can only be specified if VPC flow logs for this subnetwork is enabled and
    /// "metadata" was set to CUSTOM_METADATA.
    public var metadataFields: [Swift.String] = []

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

    /// The enumerated type for the [aggregationInterval][google.cloud.compute.v1.SubnetworkLogConfig.aggregationInterval] field.
    ///
    /// [google.cloud.compute.v1.SubnetworkLogConfig.aggregationInterval]: <doc:SubnetworkLogConfig/AggregationInterval>
    public enum AggregationInterval: Codable, Equatable, Sendable {
      case interval10Min
      case interval15Min
      case interval1Min
      case interval30Sec
      case interval5Min
      case interval5Sec
      /// 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 = .interval10Min
      }

      /// 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 .interval10Min: return 0
        case .interval15Min: return 1
        case .interval1Min: return 2
        case .interval30Sec: return 3
        case .interval5Min: return 4
        case .interval5Sec: 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 .interval10Min: return "INTERVAL_10_MIN"
        case .interval15Min: return "INTERVAL_15_MIN"
        case .interval1Min: return "INTERVAL_1_MIN"
        case .interval30Sec: return "INTERVAL_30_SEC"
        case .interval5Min: return "INTERVAL_5_MIN"
        case .interval5Sec: return "INTERVAL_5_SEC"
        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:AggregationInterval/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "INTERVAL_10_MIN": self = .interval10Min
        case "INTERVAL_15_MIN": self = .interval15Min
        case "INTERVAL_1_MIN": self = .interval1Min
        case "INTERVAL_30_SEC": self = .interval30Sec
        case "INTERVAL_5_MIN": self = .interval5Min
        case "INTERVAL_5_SEC": self = .interval5Sec
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:AggregationInterval/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .interval10Min
        case 1: self = .interval15Min
        case 2: self = .interval1Min
        case 3: self = .interval30Sec
        case 4: self = .interval5Min
        case 5: self = .interval5Sec
        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 .interval10Min: return try container.encode(0)
        case .interval15Min: return try container.encode(1)
        case .interval1Min: return try container.encode(2)
        case .interval30Sec: return try container.encode(3)
        case .interval5Min: return try container.encode(4)
        case .interval5Sec: return try container.encode(5)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

    /// The enumerated type for the [metadata][google.cloud.compute.v1.SubnetworkLogConfig.metadata] field.
    ///
    /// [google.cloud.compute.v1.SubnetworkLogConfig.metadata]: <doc:SubnetworkLogConfig/Metadata>
    public enum Metadata: Codable, Equatable, Sendable {
      case customMetadata
      case excludeAllMetadata
      case includeAllMetadata
      /// 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 = .customMetadata
      }

      /// 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 .customMetadata: return 0
        case .excludeAllMetadata: return 1
        case .includeAllMetadata: 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 .customMetadata: return "CUSTOM_METADATA"
        case .excludeAllMetadata: return "EXCLUDE_ALL_METADATA"
        case .includeAllMetadata: return "INCLUDE_ALL_METADATA"
        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:Metadata/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "CUSTOM_METADATA": self = .customMetadata
        case "EXCLUDE_ALL_METADATA": self = .excludeAllMetadata
        case "INCLUDE_ALL_METADATA": self = .includeAllMetadata
        default: self = .unknownStringValue(stringValue)
        }
      }

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