// 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 FirewallPolicies || NetworkFirewallPolicies || RegionNetworkFirewallPolicies
  import Foundation
  import GoogleCloudWkt

  /// Represents a Firewall Policy resource.
  public struct FirewallPolicy: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// A list of associations that belong to this firewall policy.
    public var associations: [FirewallPolicyAssociation] = []

    /// Output only. [Output Only] Creation timestamp inRFC3339
    /// text format.
    public var creationTimestamp: Swift.String? = nil

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

    /// Deprecated, please use short name instead. User-provided name of the
    /// Organization firewall policy. The name should be unique in the organization
    /// in which the firewall policy is created.
    /// This field is not applicable to network firewall policies.
    /// This name must be set on creation and cannot be changed.
    /// The name must be 1-63 characters long, and comply
    /// with RFC1035. Specifically, the name must be 1-63 characters
    /// long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which
    /// means the first character must be a lowercase letter, and all following
    /// characters must be a dash, lowercase letter, or digit, except the last
    /// character, which cannot be a dash.
    @available(*, deprecated)
    public var displayName: Swift.String? = nil

    /// Specifies a fingerprint for this resource, which is essentially a hash of
    /// the metadata's contents and used for optimistic locking. The
    /// fingerprint is initially generated by Compute Engine and changes after
    /// every request to modify or update metadata. You must always provide an
    /// up-to-date fingerprint hash in order to update or change metadata,
    /// otherwise the request will fail with error412 conditionNotMet.
    ///
    /// To see the latest fingerprint, make get() request to the
    /// firewall policy.
    public var fingerprint: Foundation.Data? = nil

    /// [Output Only] The unique identifier for the resource. This identifier is
    /// defined by the server.
    public var id: Swift.UInt64? = nil

    /// Output only. [Output only] Type of the resource. Alwayscompute#firewallPolicyfor firewall policies
    public var kind: Swift.String? = nil

    /// Name of the resource. For Organization Firewall Policies it's a
    /// [Output Only] numeric ID allocated by Google Cloud which uniquely
    /// identifies the Organization Firewall Policy.
    public var name: Swift.String? = nil

    /// A list of packet mirroring rules that belong to this policy.
    public var packetMirroringRules: [FirewallPolicyRule] = []

    /// Output only. [Output Only] The parent of the firewall policy.
    /// This field is not applicable to network firewall policies.
    public var parent: Swift.String? = nil

    /// The type of the firewall policy. This field can be one of
    /// VPC_POLICY, RDMA_ROCE_POLICY or ULL_POLICY.
    ///
    /// Note: if not specified then VPC_POLICY will be used.
    public var policyType: FirewallPolicy.PolicyType? = nil

    /// Output only. [Output Only] URL of the region where the regional firewall policy resides.
    /// This field is not applicable to global firewall policies.
    /// You must specify this field as part of the HTTP request URL. It is
    /// not settable as a field in the request body.
    public var region: Swift.String? = nil

    /// Output only. [Output Only] Total count of all firewall policy rule tuples. A firewall
    /// policy can not exceed a set number of tuples.
    public var ruleTupleCount: Swift.Int32? = nil

    /// A list of rules that belong to this policy.
    /// There must always be a default rule (rule with priority 2147483647 and
    /// match "*"). If no rules are provided when creating a firewall policy, a
    /// default rule with action "allow" will be added.
    public var rules: [FirewallPolicyRule] = []

    /// [Output Only] Server-defined URL for the resource.
    public var selfLink: Swift.String? = nil

    /// Output only. [Output Only] Server-defined URL for this resource with the resource id.
    public var selfLinkWithId: Swift.String? = nil

    /// User-provided name of the Organization firewall policy. The name should be
    /// unique in the organization in which the firewall policy is created.
    /// This field is not applicable to network firewall policies.
    /// This name must be set on creation and cannot be changed. The name must be
    /// 1-63 characters long, and comply with RFC1035.
    /// Specifically, the name must be 1-63 characters long and match the regular
    /// expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first
    /// character must be a lowercase letter, and all following characters must
    /// be a dash, lowercase letter, or digit, except the last character, which
    /// cannot be a dash.
    public var shortName: Swift.String? = nil

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

    private enum CodingKeys: Swift.String, CodingKey {
      case associations = "associations"
      case creationTimestamp = "creationTimestamp"
      case description = "description"
      case displayName = "displayName"
      case fingerprint = "fingerprint"
      case id = "id"
      case kind = "kind"
      case name = "name"
      case packetMirroringRules = "packetMirroringRules"
      case parent = "parent"
      case policyType = "policyType"
      case region = "region"
      case ruleTupleCount = "ruleTupleCount"
      case rules = "rules"
      case selfLink = "selfLink"
      case selfLinkWithId = "selfLinkWithId"
      case shortName = "shortName"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.associations = try container.decode(
        [FirewallPolicyAssociation].self, forKey: .associations)
      self.creationTimestamp = try container.decodeIfPresent(
        Swift.String.self, forKey: .creationTimestamp)
      self.description = try container.decodeIfPresent(Swift.String.self, forKey: .description)
      self.displayName = try container.decodeIfPresent(Swift.String.self, forKey: .displayName)
      if let s = try container.decodeIfPresent(Swift.String.self, forKey: .fingerprint) {
        guard let v = GoogleCloudWkt._DiscoveryBase64.decode(s) else {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath, debugDescription: "Expected url-safe encoded value")
          )
        }
        self.fingerprint = v
      }
      self.id = try container.decodeIfPresent(Swift.UInt64.self, forKey: .id)
      self.kind = try container.decodeIfPresent(Swift.String.self, forKey: .kind)
      self.name = try container.decodeIfPresent(Swift.String.self, forKey: .name)
      self.packetMirroringRules = try container.decode(
        [FirewallPolicyRule].self, forKey: .packetMirroringRules)
      self.parent = try container.decodeIfPresent(Swift.String.self, forKey: .parent)
      self.policyType = try container.decodeIfPresent(
        FirewallPolicy.PolicyType.self, forKey: .policyType)
      self.region = try container.decodeIfPresent(Swift.String.self, forKey: .region)
      self.ruleTupleCount = try container.decodeIfPresent(Swift.Int32.self, forKey: .ruleTupleCount)
      self.rules = try container.decode([FirewallPolicyRule].self, forKey: .rules)
      self.selfLink = try container.decodeIfPresent(Swift.String.self, forKey: .selfLink)
      self.selfLinkWithId = try container.decodeIfPresent(
        Swift.String.self, forKey: .selfLinkWithId)
      self.shortName = try container.decodeIfPresent(Swift.String.self, forKey: .shortName)
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)
      try container.encode(self.associations, forKey: .associations)
      try container.encode(self.creationTimestamp, forKey: .creationTimestamp)
      try container.encode(self.description, forKey: .description)
      try container.encode(self.displayName, forKey: .displayName)
      if let v = fingerprint {
        try container.encode(
          GoogleCloudWkt._DiscoveryBase64.encode(v), forKey: .fingerprint
        )
      }
      try container.encode(self.id, forKey: .id)
      try container.encode(self.kind, forKey: .kind)
      try container.encode(self.name, forKey: .name)
      try container.encode(self.packetMirroringRules, forKey: .packetMirroringRules)
      try container.encode(self.parent, forKey: .parent)
      try container.encode(self.policyType, forKey: .policyType)
      try container.encode(self.region, forKey: .region)
      try container.encode(self.ruleTupleCount, forKey: .ruleTupleCount)
      try container.encode(self.rules, forKey: .rules)
      try container.encode(self.selfLink, forKey: .selfLink)
      try container.encode(self.selfLinkWithId, forKey: .selfLinkWithId)
      try container.encode(self.shortName, forKey: .shortName)
    }

    /// The enumerated type for the [policyType][google.cloud.compute.v1.FirewallPolicy.policyType] field.
    ///
    /// [google.cloud.compute.v1.FirewallPolicy.policyType]: <doc:FirewallPolicy/PolicyType>
    public enum PolicyType: Codable, Equatable, Sendable {
      case rdmaRocePolicy
      case ullPolicy
      case vpcPolicy
      /// 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 = .rdmaRocePolicy
      }

      /// 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 .rdmaRocePolicy: return 0
        case .ullPolicy: return 1
        case .vpcPolicy: 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 .rdmaRocePolicy: return "RDMA_ROCE_POLICY"
        case .ullPolicy: return "ULL_POLICY"
        case .vpcPolicy: return "VPC_POLICY"
        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:PolicyType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "RDMA_ROCE_POLICY": self = .rdmaRocePolicy
        case "ULL_POLICY": self = .ullPolicy
        case "VPC_POLICY": self = .vpcPolicy
        default: self = .unknownStringValue(stringValue)
        }
      }

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