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

  public struct RouterBgp: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// User-specified flag to indicate which mode to use for advertisement.
    /// The options are DEFAULT or CUSTOM.
    public var advertiseMode: RouterBgp.AdvertiseMode? = nil

    /// User-specified list of prefix groups to advertise in custom mode.
    /// This field can only be populated if advertise_mode is CUSTOM and
    /// is advertised to all peers of the router.
    /// These groups will be advertised in addition to any specified prefixes.
    /// Leave this field blank to advertise no custom groups.
    public var advertisedGroups: [RouterBgp.AdvertisedGroups] = []

    /// User-specified list of individual IP ranges to advertise in custom mode.
    /// This field can only be populated if advertise_mode is CUSTOM and
    /// is advertised to all peers of the router.
    /// These IP ranges will be advertised in addition to any specified groups.
    /// Leave this field blank to advertise no custom IP ranges.
    public var advertisedIpRanges: [RouterAdvertisedIpRange] = []

    /// Local BGP Autonomous System Number (ASN).
    /// Must be anRFC6996 private ASN, either 16-bit or 32-bit. The
    /// value will be fixed for this router resource. All VPN tunnels that link
    /// to this router will have the same local ASN.
    public var asn: Swift.UInt32? = nil

    /// Explicitly specifies a range of valid BGP Identifiers for this Router. It
    /// is provided as a link-local IPv4 range (from 169.254.0.0/16), of size at
    /// least /30, even if the BGP sessions are over IPv6. It must not overlap
    /// with any IPv4 BGP session ranges.
    ///
    ///
    /// Other vendors commonly call this "router ID".
    public var identifierRange: Swift.String? = nil

    /// The interval in seconds between BGP keepalive messages that are
    /// sent to the peer.
    ///
    ///
    /// Hold time is three times the interval at which keepalive messages are
    /// sent, and the hold time is the maximum number of seconds allowed to
    /// elapse between successive keepalive messages that BGP receives from a
    /// peer.
    ///
    ///
    /// BGP will use the smaller of either the local hold time value or the
    /// peer's hold time value as the hold time for the BGP connection between
    /// the two peers.
    ///
    ///
    /// If set, this value must be between 20 and 60. The default is 20.
    public var keepaliveInterval: Swift.UInt32? = nil

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

    /// The enumerated type for the [advertiseMode][google.cloud.compute.v1.RouterBgp.advertiseMode] field.
    ///
    /// [google.cloud.compute.v1.RouterBgp.advertiseMode]: <doc:RouterBgp/AdvertiseMode>
    public enum AdvertiseMode: Codable, Equatable, Sendable {
      case custom
      case `default`
      /// 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 = .custom
      }

      /// 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 .custom: return 0
        case .`default`: 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 .custom: return "CUSTOM"
        case .`default`: return "DEFAULT"
        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:AdvertiseMode/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "CUSTOM": self = .custom
        case "DEFAULT": self = .`default`
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:AdvertiseMode/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .custom
        case 1: self = .`default`
        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 .custom: return try container.encode(0)
        case .`default`: 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 [advertisedGroups][google.cloud.compute.v1.RouterBgp.advertisedGroups] field.
    ///
    /// [google.cloud.compute.v1.RouterBgp.advertisedGroups]: <doc:RouterBgp/AdvertisedGroups>
    public enum AdvertisedGroups: Codable, Equatable, Sendable {
      /// Advertise all available subnets (including peer VPC subnets).
      case allSubnets
      /// 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 = .allSubnets
      }

      /// 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 .allSubnets: return 0
        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 .allSubnets: return "ALL_SUBNETS"
        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:AdvertisedGroups/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "ALL_SUBNETS": self = .allSubnets
        default: self = .unknownStringValue(stringValue)
        }
      }

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