// 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 GoogleRpc
import GoogleCloudGax
import struct Logging.Logger

extension Clients {
  final class ApiKeysLogging: ApiKeysStub {
    let inner: any ApiKeysStub
    let logger: Logger

    public init(_ inner: any ApiKeysStub, logger: Logger) {
      var logger = logger
      logger[metadataKey: "gcp.artifact.id"] = "google-api-apikeys-v2"
      logger[metadataKey: "gcp.client.service"] = "apikeys"
      logger[metadataKey: "gcp.experimental.swift.client"] = "ApiKeys"
      self.inner = inner
      self.logger = logger
    }

    func _intercept<Input, Output>(
      request: Input,
      options: GoogleCloudGax.RequestOptions,
      name: Swift.String,
      action: (Input, GoogleCloudGax.RequestOptions) async throws -> Output,
    ) async throws -> Output {
      var logger = logger
      logger[metadataKey: "gcp.experimental.swift.request.id"] = "\(UUID())"
      logger[metadataKey: "gcp.experimental.swift.method"] = .string(name)
      logger.debug("enter  : \(request) \(options)")
      do {
        let output = try await action(request, options)
        logger.debug("success: \(request) \(options) \(output)")
        return output
      } catch let error {
        logger.debug("error  : \(request) \(options) \(error)")
        throw error
      }
    }

    public func createKey(
      request: CreateKeyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        name: "createKey",
        action: {
          (r: CreateKeyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.createKey(request: r, options: o)
        })
    }

    public func listKeys(
      request: ListKeysRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApiApiKeysV1.ListKeysResponse {
      try await self._intercept(
        request: request,
        options: options,
        name: "listKeys",
        action: {
          (r: ListKeysRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleApiApiKeysV1.ListKeysResponse
          in
          return try await self.inner.listKeys(request: r, options: o)
        })
    }

    public func getKey(
      request: GetKeyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApiApiKeysV1.Key {
      try await self._intercept(
        request: request,
        options: options,
        name: "getKey",
        action: {
          (r: GetKeyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleApiApiKeysV1.Key
          in
          return try await self.inner.getKey(request: r, options: o)
        })
    }

    public func getKeyString(
      request: GetKeyStringRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApiApiKeysV1.GetKeyStringResponse {
      try await self._intercept(
        request: request,
        options: options,
        name: "getKeyString",
        action: {
          (r: GetKeyStringRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleApiApiKeysV1.GetKeyStringResponse
          in
          return try await self.inner.getKeyString(request: r, options: o)
        })
    }

    public func updateKey(
      request: UpdateKeyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        name: "updateKey",
        action: {
          (r: UpdateKeyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.updateKey(request: r, options: o)
        })
    }

    public func deleteKey(
      request: DeleteKeyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        name: "deleteKey",
        action: {
          (r: DeleteKeyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.deleteKey(request: r, options: o)
        })
    }

    public func undeleteKey(
      request: UndeleteKeyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        name: "undeleteKey",
        action: {
          (r: UndeleteKeyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.undeleteKey(request: r, options: o)
        })
    }

    public func lookupKey(
      request: LookupKeyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleApiApiKeysV1.LookupKeyResponse {
      try await self._intercept(
        request: request,
        options: options,
        name: "lookupKey",
        action: {
          (r: LookupKeyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleApiApiKeysV1.LookupKeyResponse
          in
          return try await self.inner.lookupKey(request: r, options: o)
        })
    }

    public func getOperation(
      request: GoogleLongRunning.GetOperationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.Operation {
      try await self._intercept(
        request: request,
        options: options,
        name: "getOperation",
        action: {
          (r: GoogleLongRunning.GetOperationRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleLongRunning.Operation
          in
          return try await self.inner.getOperation(request: r, options: o)
        })
    }
  }
}
