// 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 GoogleIAMV1
import GoogleCloudGax

/// Manages external data source connections and credentials.
///
/// @Snippet(path: "ConnectionServiceQuickstart")
public class ConnectionServiceClient: Clients.ConnectionServiceProtocol {
  let inner: any Clients.ConnectionServiceStub

  /// Creates a new `ConnectionServiceClient` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.ConnectionServiceStub = try Clients.ConnectionServiceTransport(options)
    inner = Clients.ConnectionServiceRetry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.ConnectionServiceLogging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Creates a new connection.
  ///
  /// @Snippet(path: "ConnectionService_CreateConnection")
  public func createConnection(
    request: CreateConnectionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleBigQueryConnectionV1.Connection {
    try await self.inner.createConnection(request: request, options: options)
  }

  /// Returns specified connection.
  ///
  /// @Snippet(path: "ConnectionService_GetConnection")
  public func getConnection(
    request: GetConnectionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleBigQueryConnectionV1.Connection {
    try await self.inner.getConnection(request: request, options: options)
  }

  /// Returns a list of connections in the given project.
  ///
  /// @Snippet(path: "ConnectionService_ListConnections")
  public func listConnections(
    request: ListConnectionsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleBigQueryConnectionV1.ListConnectionsResponse {
    try await self.inner.listConnections(request: request, options: options)
  }

  /// Returns a list of connections in the given project.
  ///
  /// @Snippet(path: "ConnectionService_ListConnections")
  public func listConnections(
    byItem: ListConnectionsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<Connection, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleBigQueryConnectionV1.ListConnectionsResponse in
      var request = byItem
      request.pageToken = token
      return try await self.listConnections(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  /// Updates the specified connection. For security reasons, also resets
  /// credential if connection properties are in the update field mask.
  ///
  /// @Snippet(path: "ConnectionService_UpdateConnection")
  public func updateConnection(
    request: UpdateConnectionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleBigQueryConnectionV1.Connection {
    try await self.inner.updateConnection(request: request, options: options)
  }

  /// Deletes connection and associated credential.
  ///
  /// @Snippet(path: "ConnectionService_DeleteConnection")
  public func deleteConnection(
    request: DeleteConnectionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws {
    try await self.inner.deleteConnection(request: request, options: options)
  }

  /// Gets the access control policy for a resource.
  /// Returns an empty policy if the resource exists and does not have a policy
  /// set.
  ///
  /// @Snippet(path: "ConnectionService_GetIamPolicy")
  public func getIamPolicy(
    request: GoogleIAMV1.GetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMV1.Policy {
    try await self.inner.getIamPolicy(request: request, options: options)
  }

  /// Sets the access control policy on the specified resource. Replaces any
  /// existing policy.
  ///
  /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` errors.
  ///
  /// @Snippet(path: "ConnectionService_SetIamPolicy")
  public func setIamPolicy(
    request: GoogleIAMV1.SetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMV1.Policy {
    try await self.inner.setIamPolicy(request: request, options: options)
  }

  /// Returns permissions that a caller has on the specified resource.
  /// If the resource does not exist, this will return an empty set of
  /// permissions, not a `NOT_FOUND` error.
  ///
  /// Note: This operation is designed to be used for building permission-aware
  /// UIs and command-line tools, not for authorization checking. This operation
  /// may "fail open" without warning.
  ///
  /// @Snippet(path: "ConnectionService_TestIamPermissions")
  public func testIamPermissions(
    request: GoogleIAMV1.TestIamPermissionsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMV1.TestIamPermissionsResponse {
    try await self.inner.testIamPermissions(request: request, options: options)
  }
}

extension Clients {
  /// A Swift protocol to mock `ConnectionServiceClient`.
  ///
  /// To mock `ConnectionServiceClient` change your functions to receive
  /// `some ConnectionServiceProtocol` or `any ConnectionServiceProtocol`
  /// and pass a mock implementation in your tests.
  public protocol ConnectionServiceProtocol {
    /// See `ConnectionServiceClient.createConnection`.
    func createConnection(request: CreateConnectionRequest) async throws
      -> GoogleBigQueryConnectionV1.Connection

    /// See `ConnectionServiceClient.createConnection`.
    func createConnection(
      parent: Swift.String,
      connection: Connection?,
      connectionId: Swift.String,
    ) async throws -> GoogleBigQueryConnectionV1.Connection

    /// See `ConnectionServiceClient.getConnection`.
    func getConnection(request: GetConnectionRequest) async throws
      -> GoogleBigQueryConnectionV1.Connection

    /// See `ConnectionServiceClient.getConnection`.
    func getConnection(
      name: Swift.String,
    ) async throws -> GoogleBigQueryConnectionV1.Connection

    /// See `ConnectionServiceClient.listConnections`.
    func listConnections(request: ListConnectionsRequest) async throws
      -> GoogleBigQueryConnectionV1.ListConnectionsResponse

    /// See `ConnectionServiceClient.listConnections`.
    func listConnections(
      byItem: ListConnectionsRequest
    ) throws -> any AsyncSequence<Connection, Swift.Error>

    /// See `ConnectionServiceClient.listConnections`.
    func listConnections(
      parent: Swift.String,
    ) throws -> any AsyncSequence<Connection, Swift.Error>

    /// See `ConnectionServiceClient.updateConnection`.
    func updateConnection(request: UpdateConnectionRequest) async throws
      -> GoogleBigQueryConnectionV1.Connection

    /// See `ConnectionServiceClient.updateConnection`.
    func updateConnection(
      name: Swift.String,
      connection: Connection?,
      updateMask: GoogleCloudWkt.FieldMask?,
    ) async throws -> GoogleBigQueryConnectionV1.Connection

    /// See `ConnectionServiceClient.deleteConnection`.
    func deleteConnection(request: DeleteConnectionRequest) async throws

    /// See `ConnectionServiceClient.deleteConnection`.
    func deleteConnection(
      name: Swift.String,
    ) async throws

    /// See `ConnectionServiceClient.getIamPolicy`.
    func getIamPolicy(request: GoogleIAMV1.GetIamPolicyRequest) async throws -> GoogleIAMV1.Policy

    /// See `ConnectionServiceClient.getIamPolicy`.
    func getIamPolicy(
      resource: Swift.String,
      options: GoogleIAMV1.GetPolicyOptions?,
    ) async throws -> GoogleIAMV1.Policy

    /// See `ConnectionServiceClient.setIamPolicy`.
    func setIamPolicy(request: GoogleIAMV1.SetIamPolicyRequest) async throws -> GoogleIAMV1.Policy

    /// See `ConnectionServiceClient.setIamPolicy`.
    func setIamPolicy(
      resource: Swift.String,
      policy: GoogleIAMV1.Policy?,
    ) async throws -> GoogleIAMV1.Policy

    /// See `ConnectionServiceClient.testIamPermissions`.
    func testIamPermissions(request: GoogleIAMV1.TestIamPermissionsRequest) async throws
      -> GoogleIAMV1.TestIamPermissionsResponse

    /// See `ConnectionServiceClient.testIamPermissions`.
    func testIamPermissions(
      resource: Swift.String,
      permissions: [Swift.String],
    ) async throws -> GoogleIAMV1.TestIamPermissionsResponse

    /// See `ConnectionServiceClient.createConnection`.
    func createConnection(
      request: CreateConnectionRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryConnectionV1.Connection

    /// See `ConnectionServiceClient.getConnection`.
    func getConnection(
      request: GetConnectionRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryConnectionV1.Connection

    /// See `ConnectionServiceClient.listConnections`.
    func listConnections(
      request: ListConnectionsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryConnectionV1.ListConnectionsResponse

    /// See `ConnectionServiceClient.listConnections`.
    func listConnections(
      byItem: ListConnectionsRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<Connection, Swift.Error>

    /// See `ConnectionServiceClient.updateConnection`.
    func updateConnection(
      request: UpdateConnectionRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleBigQueryConnectionV1.Connection

    /// See `ConnectionServiceClient.deleteConnection`.
    func deleteConnection(
      request: DeleteConnectionRequest, options: GoogleCloudGax.RequestOptions
    ) async throws

    /// See `ConnectionServiceClient.getIamPolicy`.
    func getIamPolicy(
      request: GoogleIAMV1.GetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMV1.Policy

    /// See `ConnectionServiceClient.setIamPolicy`.
    func setIamPolicy(
      request: GoogleIAMV1.SetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMV1.Policy

    /// See `ConnectionServiceClient.testIamPermissions`.
    func testIamPermissions(
      request: GoogleIAMV1.TestIamPermissionsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMV1.TestIamPermissionsResponse
  }
}

// Default implementations
extension Clients.ConnectionServiceProtocol {
  public func createConnection(request: CreateConnectionRequest) async throws
    -> GoogleBigQueryConnectionV1.Connection
  {
    try await self.createConnection(request: request, options: .init())
  }

  public func createConnection(
    request: CreateConnectionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleBigQueryConnectionV1.Connection {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func createConnection(
    parent: Swift.String,
    connection: Connection?,
    connectionId: Swift.String,
  ) async throws -> GoogleBigQueryConnectionV1.Connection {
    let request = CreateConnectionRequest().with {
      $0.parent = parent
      $0.connection = connection
      $0.connectionId = connectionId
    }
    return try await self.createConnection(request: request)
  }

  public func getConnection(request: GetConnectionRequest) async throws
    -> GoogleBigQueryConnectionV1.Connection
  {
    try await self.getConnection(request: request, options: .init())
  }

  public func getConnection(
    request: GetConnectionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleBigQueryConnectionV1.Connection {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func getConnection(
    name: Swift.String,
  ) async throws -> GoogleBigQueryConnectionV1.Connection {
    let request = GetConnectionRequest().with {
      $0.name = name
    }
    return try await self.getConnection(request: request)
  }

  public func listConnections(request: ListConnectionsRequest) async throws
    -> GoogleBigQueryConnectionV1.ListConnectionsResponse
  {
    try await self.listConnections(request: request, options: .init())
  }

  public func listConnections(
    request: ListConnectionsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleBigQueryConnectionV1.ListConnectionsResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func listConnections(
    byItem: ListConnectionsRequest
  ) throws -> any AsyncSequence<Connection, Swift.Error> {
    try self.listConnections(byItem: byItem, options: .init())
  }

  public func listConnections(
    byItem: ListConnectionsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<Connection, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleBigQueryConnectionV1.ListConnectionsResponse in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func listConnections(
    parent: Swift.String,
  ) throws -> any AsyncSequence<Connection, Swift.Error> {
    let request = ListConnectionsRequest().with {
      $0.parent = parent
    }
    return try self.listConnections(byItem: request)
  }

  public func updateConnection(request: UpdateConnectionRequest) async throws
    -> GoogleBigQueryConnectionV1.Connection
  {
    try await self.updateConnection(request: request, options: .init())
  }

  public func updateConnection(
    request: UpdateConnectionRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleBigQueryConnectionV1.Connection {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func updateConnection(
    name: Swift.String,
    connection: Connection?,
    updateMask: GoogleCloudWkt.FieldMask?,
  ) async throws -> GoogleBigQueryConnectionV1.Connection {
    let request = UpdateConnectionRequest().with {
      $0.name = name
      $0.connection = connection
      $0.updateMask = updateMask
    }
    return try await self.updateConnection(request: request)
  }

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

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

  public func deleteConnection(
    name: Swift.String,
  ) async throws {
    let request = DeleteConnectionRequest().with {
      $0.name = name
    }
    try await self.deleteConnection(request: request)
  }

  public func getIamPolicy(request: GoogleIAMV1.GetIamPolicyRequest) async throws
    -> GoogleIAMV1.Policy
  {
    try await self.getIamPolicy(request: request, options: .init())
  }

  public func getIamPolicy(
    request: GoogleIAMV1.GetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMV1.Policy {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func getIamPolicy(
    resource: Swift.String,
    options: GoogleIAMV1.GetPolicyOptions?,
  ) async throws -> GoogleIAMV1.Policy {
    let request = GoogleIAMV1.GetIamPolicyRequest().with {
      $0.resource = resource
      $0.options = options
    }
    return try await self.getIamPolicy(request: request)
  }

  public func setIamPolicy(request: GoogleIAMV1.SetIamPolicyRequest) async throws
    -> GoogleIAMV1.Policy
  {
    try await self.setIamPolicy(request: request, options: .init())
  }

  public func setIamPolicy(
    request: GoogleIAMV1.SetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMV1.Policy {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func setIamPolicy(
    resource: Swift.String,
    policy: GoogleIAMV1.Policy?,
  ) async throws -> GoogleIAMV1.Policy {
    let request = GoogleIAMV1.SetIamPolicyRequest().with {
      $0.resource = resource
      $0.policy = policy
    }
    return try await self.setIamPolicy(request: request)
  }

  public func testIamPermissions(request: GoogleIAMV1.TestIamPermissionsRequest) async throws
    -> GoogleIAMV1.TestIamPermissionsResponse
  {
    try await self.testIamPermissions(request: request, options: .init())
  }

  public func testIamPermissions(
    request: GoogleIAMV1.TestIamPermissionsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMV1.TestIamPermissionsResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func testIamPermissions(
    resource: Swift.String,
    permissions: [Swift.String],
  ) async throws -> GoogleIAMV1.TestIamPermissionsResponse {
    let request = GoogleIAMV1.TestIamPermissionsRequest().with {
      $0.resource = resource
      $0.permissions = permissions
    }
    return try await self.testIamPermissions(request: request)
  }
}
