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

/// Returns information about the resources in an org that are protected by a
/// given Cloud KMS key via CMEK.
///
/// @Snippet(path: "KeyTrackingServiceQuickstart")
public class KeyTrackingServiceClient: Clients.KeyTrackingServiceProtocol {
  let inner: any Clients.KeyTrackingServiceStub

  /// Creates a new `KeyTrackingServiceClient` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.KeyTrackingServiceStub = try Clients.KeyTrackingServiceTransport(options)
    inner = Clients.KeyTrackingServiceRetry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.KeyTrackingServiceLogging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Returns aggregate information about the resources protected by the given
  /// Cloud KMS [CryptoKey][google.cloud.kms.v1.CryptoKey]. By default,
  /// summary of resources within the same Cloud organization as the key will be
  /// returned, which requires the KMS organization service account to be
  /// configured(refer
  /// https://docs.cloud.google.com/kms/docs/view-key-usage#required-roles).
  /// If the KMS organization service account is not configured or key's project
  /// is not part of an organization, set
  /// [fallback_scope][google.cloud.kms.inventory.v1.GetProtectedResourcesSummaryRequest.fallback_scope]
  /// to `FALLBACK_SCOPE_PROJECT` to retrieve a summary of protected resources
  /// within the key's project.
  ///
  /// [google.cloud.kms.inventory.v1.GetProtectedResourcesSummaryRequest.fallback_scope]: <doc:GetProtectedResourcesSummaryRequest/fallbackScope>
  /// [google.cloud.kms.v1.CryptoKey]: https://www.google.com/search?q=Swift+google.cloud.kms.v1+GoogleCloudKMSV1.CryptoKey
  ///
  /// @Snippet(path: "KeyTrackingService_GetProtectedResourcesSummary")
  public func getProtectedResourcesSummary(
    request: GetProtectedResourcesSummaryRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudKMSInventoryV1.ProtectedResourcesSummary {
    try await self.inner.getProtectedResourcesSummary(request: request, options: options)
  }

  /// Returns metadata about the resources protected by the given Cloud KMS
  /// [CryptoKey][google.cloud.kms.v1.CryptoKey] in the given Cloud
  /// organization/project.
  ///
  /// [google.cloud.kms.v1.CryptoKey]: https://www.google.com/search?q=Swift+google.cloud.kms.v1+GoogleCloudKMSV1.CryptoKey
  ///
  /// @Snippet(path: "KeyTrackingService_SearchProtectedResources")
  public func searchProtectedResources(
    request: SearchProtectedResourcesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudKMSInventoryV1.SearchProtectedResourcesResponse {
    try await self.inner.searchProtectedResources(request: request, options: options)
  }

  /// Returns metadata about the resources protected by the given Cloud KMS
  /// [CryptoKey][google.cloud.kms.v1.CryptoKey] in the given Cloud
  /// organization/project.
  ///
  /// [google.cloud.kms.v1.CryptoKey]: https://www.google.com/search?q=Swift+google.cloud.kms.v1+GoogleCloudKMSV1.CryptoKey
  ///
  /// @Snippet(path: "KeyTrackingService_SearchProtectedResources")
  public func searchProtectedResources(
    byItem: SearchProtectedResourcesRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<ProtectedResource, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws
        -> GoogleCloudKMSInventoryV1.SearchProtectedResourcesResponse in
      var request = byItem
      request.pageToken = token
      return try await self.searchProtectedResources(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }
}

extension Clients {
  /// A Swift protocol to mock `KeyTrackingServiceClient`.
  ///
  /// To mock `KeyTrackingServiceClient` change your functions to receive
  /// `some KeyTrackingServiceProtocol` or `any KeyTrackingServiceProtocol`
  /// and pass a mock implementation in your tests.
  public protocol KeyTrackingServiceProtocol {
    /// See `KeyTrackingServiceClient.getProtectedResourcesSummary`.
    func getProtectedResourcesSummary(request: GetProtectedResourcesSummaryRequest) async throws
      -> GoogleCloudKMSInventoryV1.ProtectedResourcesSummary

    /// See `KeyTrackingServiceClient.getProtectedResourcesSummary`.
    func getProtectedResourcesSummary(
      name: Swift.String,
    ) async throws -> GoogleCloudKMSInventoryV1.ProtectedResourcesSummary

    /// See `KeyTrackingServiceClient.searchProtectedResources`.
    func searchProtectedResources(request: SearchProtectedResourcesRequest) async throws
      -> GoogleCloudKMSInventoryV1.SearchProtectedResourcesResponse

    /// See `KeyTrackingServiceClient.searchProtectedResources`.
    func searchProtectedResources(
      byItem: SearchProtectedResourcesRequest
    ) throws -> any AsyncSequence<ProtectedResource, Swift.Error>

    /// See `KeyTrackingServiceClient.searchProtectedResources`.
    func searchProtectedResources(
      scope: Swift.String,
      cryptoKey: Swift.String,
    ) throws -> any AsyncSequence<ProtectedResource, Swift.Error>

    /// See `KeyTrackingServiceClient.getProtectedResourcesSummary`.
    func getProtectedResourcesSummary(
      request: GetProtectedResourcesSummaryRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudKMSInventoryV1.ProtectedResourcesSummary

    /// See `KeyTrackingServiceClient.searchProtectedResources`.
    func searchProtectedResources(
      request: SearchProtectedResourcesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudKMSInventoryV1.SearchProtectedResourcesResponse

    /// See `KeyTrackingServiceClient.searchProtectedResources`.
    func searchProtectedResources(
      byItem: SearchProtectedResourcesRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<ProtectedResource, Swift.Error>
  }
}

// Default implementations
extension Clients.KeyTrackingServiceProtocol {
  public func getProtectedResourcesSummary(request: GetProtectedResourcesSummaryRequest)
    async throws -> GoogleCloudKMSInventoryV1.ProtectedResourcesSummary
  {
    try await self.getProtectedResourcesSummary(request: request, options: .init())
  }

  public func getProtectedResourcesSummary(
    request: GetProtectedResourcesSummaryRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudKMSInventoryV1.ProtectedResourcesSummary {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func getProtectedResourcesSummary(
    name: Swift.String,
  ) async throws -> GoogleCloudKMSInventoryV1.ProtectedResourcesSummary {
    let request = GetProtectedResourcesSummaryRequest().with {
      $0.name = name
    }
    return try await self.getProtectedResourcesSummary(request: request)
  }

  public func searchProtectedResources(request: SearchProtectedResourcesRequest) async throws
    -> GoogleCloudKMSInventoryV1.SearchProtectedResourcesResponse
  {
    try await self.searchProtectedResources(request: request, options: .init())
  }

  public func searchProtectedResources(
    request: SearchProtectedResourcesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudKMSInventoryV1.SearchProtectedResourcesResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func searchProtectedResources(
    byItem: SearchProtectedResourcesRequest
  ) throws -> any AsyncSequence<ProtectedResource, Swift.Error> {
    try self.searchProtectedResources(byItem: byItem, options: .init())
  }

  public func searchProtectedResources(
    byItem: SearchProtectedResourcesRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<ProtectedResource, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws
        -> GoogleCloudKMSInventoryV1.SearchProtectedResourcesResponse in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func searchProtectedResources(
    scope: Swift.String,
    cryptoKey: Swift.String,
  ) throws -> any AsyncSequence<ProtectedResource, Swift.Error> {
    let request = SearchProtectedResourcesRequest().with {
      $0.scope = scope
      $0.cryptoKey = cryptoKey
    }
    return try self.searchProtectedResources(byItem: request)
  }
}
