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

import Foundation
#if canImport(FoundationNetworking)
  import FoundationNetworking
#endif
import GoogleCloudWkt
import GoogleLongRunning
import GoogleCloudGax

/// Firewall resources are used to define a collection of access control rules
/// for an Application. Each rule is defined with a position which specifies
/// the rule's order in the sequence of rules, an IP range to be matched against
/// requests, and an action to take upon matching requests.
///
/// Every request is evaluated against the Firewall rules in priority order.
/// Processesing stops at the first rule which matches the request's IP address.
/// A final rule always specifies an action that applies to all remaining
/// IP addresses. The default final rule for a newly-created application will be
/// set to "allow" if not otherwise specified by the user.
///
/// @Snippet(path: "FirewallQuickstart")
public class FirewallClient: Clients.FirewallProtocol {
  let inner: any Clients.FirewallStub

  /// Creates a new `FirewallClient` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.FirewallStub = try Clients.FirewallTransport(options)
    inner = Clients.FirewallRetry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.FirewallLogging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Lists the firewall rules of an application.
  ///
  /// @Snippet(path: "Firewall_ListIngressRules")
  public func listIngressRules(
    request: ListIngressRulesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleAppEngineV1.ListIngressRulesResponse {
    try await self.inner.listIngressRules(request: request, options: options)
  }

  /// Lists the firewall rules of an application.
  ///
  /// @Snippet(path: "Firewall_ListIngressRules")
  public func listIngressRules(
    byItem: ListIngressRulesRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<FirewallRule, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleAppEngineV1.ListIngressRulesResponse in
      var request = byItem
      request.pageToken = token
      return try await self.listIngressRules(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  /// Replaces the entire firewall ruleset in one bulk operation. This overrides
  /// and replaces the rules of an existing firewall with the new rules.
  ///
  /// If the final rule does not match traffic with the '*' wildcard IP range,
  /// then an "allow all" rule is explicitly added to the end of the list.
  ///
  /// @Snippet(path: "Firewall_BatchUpdateIngressRules")
  public func batchUpdateIngressRules(
    request: BatchUpdateIngressRulesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleAppEngineV1.BatchUpdateIngressRulesResponse {
    try await self.inner.batchUpdateIngressRules(request: request, options: options)
  }

  /// Creates a firewall rule for the application.
  ///
  /// @Snippet(path: "Firewall_CreateIngressRule")
  public func createIngressRule(
    request: CreateIngressRuleRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleAppEngineV1.FirewallRule {
    try await self.inner.createIngressRule(request: request, options: options)
  }

  /// Gets the specified firewall rule.
  ///
  /// @Snippet(path: "Firewall_GetIngressRule")
  public func getIngressRule(
    request: GetIngressRuleRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleAppEngineV1.FirewallRule {
    try await self.inner.getIngressRule(request: request, options: options)
  }

  /// Updates the specified firewall rule.
  ///
  /// @Snippet(path: "Firewall_UpdateIngressRule")
  public func updateIngressRule(
    request: UpdateIngressRuleRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleAppEngineV1.FirewallRule {
    try await self.inner.updateIngressRule(request: request, options: options)
  }

  /// Deletes the specified firewall rule.
  ///
  /// @Snippet(path: "Firewall_DeleteIngressRule")
  public func deleteIngressRule(
    request: DeleteIngressRuleRequest, options: GoogleCloudGax.RequestOptions
  ) async throws {
    try await self.inner.deleteIngressRule(request: request, options: options)
  }

  /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
  ///
  /// [google.longrunning.Operations]: https://www.google.com/search?q=Swift+google.longrunning+Operations
  ///
  /// @Snippet(path: "Firewall_ListOperations")
  public func listOperations(
    request: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.ListOperationsResponse {
    try await self.inner.listOperations(request: request, options: options)
  }

  /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
  ///
  /// [google.longrunning.Operations]: https://www.google.com/search?q=Swift+google.longrunning+Operations
  ///
  /// @Snippet(path: "Firewall_ListOperations")
  public func listOperations(
    byItem: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleLongRunning.ListOperationsResponse in
      var request = byItem
      request.pageToken = token
      return try await self.listOperations(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
  ///
  /// [google.longrunning.Operations]: https://www.google.com/search?q=Swift+google.longrunning+Operations
  ///
  /// @Snippet(path: "Firewall_GetOperation")
  func getOperation(
    request: GoogleLongRunning.GetOperationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.Operation {
    try await self.inner.getOperation(request: request, options: options)
  }
}

extension Clients {
  /// A Swift protocol to mock `FirewallClient`.
  ///
  /// To mock `FirewallClient` change your functions to receive
  /// `some FirewallProtocol` or `any FirewallProtocol`
  /// and pass a mock implementation in your tests.
  public protocol FirewallProtocol {
    /// See `FirewallClient.listIngressRules`.
    func listIngressRules(request: ListIngressRulesRequest) async throws
      -> GoogleAppEngineV1.ListIngressRulesResponse

    /// See `FirewallClient.listIngressRules`.
    func listIngressRules(
      byItem: ListIngressRulesRequest
    ) throws -> any AsyncSequence<FirewallRule, Swift.Error>

    /// See `FirewallClient.batchUpdateIngressRules`.
    func batchUpdateIngressRules(request: BatchUpdateIngressRulesRequest) async throws
      -> GoogleAppEngineV1.BatchUpdateIngressRulesResponse

    /// See `FirewallClient.createIngressRule`.
    func createIngressRule(request: CreateIngressRuleRequest) async throws
      -> GoogleAppEngineV1.FirewallRule

    /// See `FirewallClient.getIngressRule`.
    func getIngressRule(request: GetIngressRuleRequest) async throws
      -> GoogleAppEngineV1.FirewallRule

    /// See `FirewallClient.updateIngressRule`.
    func updateIngressRule(request: UpdateIngressRuleRequest) async throws
      -> GoogleAppEngineV1.FirewallRule

    /// See `FirewallClient.deleteIngressRule`.
    func deleteIngressRule(request: DeleteIngressRuleRequest) async throws

    /// See `FirewallClient.listOperations`.
    func listOperations(request: GoogleLongRunning.ListOperationsRequest) async throws
      -> GoogleLongRunning.ListOperationsResponse

    /// See `FirewallClient.listOperations`.
    func listOperations(
      byItem: GoogleLongRunning.ListOperationsRequest
    ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error>

    /// See `FirewallClient.listOperations`.
    func listOperations(
      name: Swift.String,
      filter: Swift.String,
    ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error>

    /// See `FirewallClient.listIngressRules`.
    func listIngressRules(
      request: ListIngressRulesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleAppEngineV1.ListIngressRulesResponse

    /// See `FirewallClient.listIngressRules`.
    func listIngressRules(
      byItem: ListIngressRulesRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<FirewallRule, Swift.Error>

    /// See `FirewallClient.batchUpdateIngressRules`.
    func batchUpdateIngressRules(
      request: BatchUpdateIngressRulesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleAppEngineV1.BatchUpdateIngressRulesResponse

    /// See `FirewallClient.createIngressRule`.
    func createIngressRule(
      request: CreateIngressRuleRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleAppEngineV1.FirewallRule

    /// See `FirewallClient.getIngressRule`.
    func getIngressRule(
      request: GetIngressRuleRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleAppEngineV1.FirewallRule

    /// See `FirewallClient.updateIngressRule`.
    func updateIngressRule(
      request: UpdateIngressRuleRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleAppEngineV1.FirewallRule

    /// See `FirewallClient.deleteIngressRule`.
    func deleteIngressRule(
      request: DeleteIngressRuleRequest, options: GoogleCloudGax.RequestOptions
    ) async throws

    /// See `FirewallClient.listOperations`.
    func listOperations(
      request: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.ListOperationsResponse

    /// See `FirewallClient.listOperations`.
    func listOperations(
      byItem: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error>
  }
}

// Default implementations
extension Clients.FirewallProtocol {
  public func listIngressRules(request: ListIngressRulesRequest) async throws
    -> GoogleAppEngineV1.ListIngressRulesResponse
  {
    try await self.listIngressRules(request: request, options: .init())
  }

  public func listIngressRules(
    request: ListIngressRulesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleAppEngineV1.ListIngressRulesResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func listIngressRules(
    byItem: ListIngressRulesRequest
  ) throws -> any AsyncSequence<FirewallRule, Swift.Error> {
    try self.listIngressRules(byItem: byItem, options: .init())
  }

  public func listIngressRules(
    byItem: ListIngressRulesRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<FirewallRule, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleAppEngineV1.ListIngressRulesResponse in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func batchUpdateIngressRules(request: BatchUpdateIngressRulesRequest) async throws
    -> GoogleAppEngineV1.BatchUpdateIngressRulesResponse
  {
    try await self.batchUpdateIngressRules(request: request, options: .init())
  }

  public func batchUpdateIngressRules(
    request: BatchUpdateIngressRulesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleAppEngineV1.BatchUpdateIngressRulesResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func createIngressRule(request: CreateIngressRuleRequest) async throws
    -> GoogleAppEngineV1.FirewallRule
  {
    try await self.createIngressRule(request: request, options: .init())
  }

  public func createIngressRule(
    request: CreateIngressRuleRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleAppEngineV1.FirewallRule {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func getIngressRule(request: GetIngressRuleRequest) async throws
    -> GoogleAppEngineV1.FirewallRule
  {
    try await self.getIngressRule(request: request, options: .init())
  }

  public func getIngressRule(
    request: GetIngressRuleRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleAppEngineV1.FirewallRule {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func updateIngressRule(request: UpdateIngressRuleRequest) async throws
    -> GoogleAppEngineV1.FirewallRule
  {
    try await self.updateIngressRule(request: request, options: .init())
  }

  public func updateIngressRule(
    request: UpdateIngressRuleRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleAppEngineV1.FirewallRule {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func deleteIngressRule(request: DeleteIngressRuleRequest) async throws {
    try await self.deleteIngressRule(request: request, options: .init())
  }

  public func deleteIngressRule(
    request: DeleteIngressRuleRequest, options: GoogleCloudGax.RequestOptions
  ) async throws {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func listOperations(request: GoogleLongRunning.ListOperationsRequest) async throws
    -> GoogleLongRunning.ListOperationsResponse
  {
    try await self.listOperations(request: request, options: .init())
  }

  public func listOperations(
    request: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.ListOperationsResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func listOperations(
    byItem: GoogleLongRunning.ListOperationsRequest
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    try self.listOperations(byItem: byItem, options: .init())
  }

  public func listOperations(
    byItem: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleLongRunning.ListOperationsResponse in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func listOperations(
    name: Swift.String,
    filter: Swift.String,
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    let request = GoogleLongRunning.ListOperationsRequest().with {
      $0.name = name
      $0.filter = filter
    }
    return try self.listOperations(byItem: request)
  }

  public func getOperation(request: GoogleLongRunning.GetOperationRequest) async throws
    -> GoogleLongRunning.Operation
  {
    try await self.getOperation(request: request, options: .init())
  }

  public func getOperation(
    request: GoogleLongRunning.GetOperationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.Operation {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func getOperation(
    name: Swift.String,
  ) async throws -> GoogleLongRunning.Operation {
    let request = GoogleLongRunning.GetOperationRequest().with {
      $0.name = name
    }
    return try await self.getOperation(request: request)
  }
}
