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

extension Clients {
  final class BinauthzManagementServiceV1Logging: BinauthzManagementServiceV1Stub {
    let inner: any BinauthzManagementServiceV1Stub
    let logger: Logger

    public init(_ inner: any BinauthzManagementServiceV1Stub, logger: Logger) {
      var logger = logger
      logger[metadataKey: "gcp.artifact.id"] = "google-cloud-binaryauthorization-v1"
      logger[metadataKey: "gcp.client.service"] = "binaryauthorization"
      logger[metadataKey: "gcp.experimental.swift.client"] = "BinauthzManagementServiceV1"
      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 getPolicy(
      request: GetPolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudBinaryAuthorizationV1.Policy {
      try await self._intercept(
        request: request,
        options: options,
        name: "getPolicy",
        action: {
          (r: GetPolicyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudBinaryAuthorizationV1.Policy
          in
          return try await self.inner.getPolicy(request: r, options: o)
        })
    }

    public func updatePolicy(
      request: UpdatePolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudBinaryAuthorizationV1.Policy {
      try await self._intercept(
        request: request,
        options: options,
        name: "updatePolicy",
        action: {
          (r: UpdatePolicyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudBinaryAuthorizationV1.Policy
          in
          return try await self.inner.updatePolicy(request: r, options: o)
        })
    }

    public func createAttestor(
      request: CreateAttestorRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudBinaryAuthorizationV1.Attestor {
      try await self._intercept(
        request: request,
        options: options,
        name: "createAttestor",
        action: {
          (r: CreateAttestorRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudBinaryAuthorizationV1.Attestor
          in
          return try await self.inner.createAttestor(request: r, options: o)
        })
    }

    public func getAttestor(
      request: GetAttestorRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudBinaryAuthorizationV1.Attestor {
      try await self._intercept(
        request: request,
        options: options,
        name: "getAttestor",
        action: {
          (r: GetAttestorRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudBinaryAuthorizationV1.Attestor
          in
          return try await self.inner.getAttestor(request: r, options: o)
        })
    }

    public func updateAttestor(
      request: UpdateAttestorRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudBinaryAuthorizationV1.Attestor {
      try await self._intercept(
        request: request,
        options: options,
        name: "updateAttestor",
        action: {
          (r: UpdateAttestorRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudBinaryAuthorizationV1.Attestor
          in
          return try await self.inner.updateAttestor(request: r, options: o)
        })
    }

    public func listAttestors(
      request: ListAttestorsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudBinaryAuthorizationV1.ListAttestorsResponse {
      try await self._intercept(
        request: request,
        options: options,
        name: "listAttestors",
        action: {
          (r: ListAttestorsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleCloudBinaryAuthorizationV1.ListAttestorsResponse
          in
          return try await self.inner.listAttestors(request: r, options: o)
        })
    }

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

    public func setIamPolicy(
      request: GoogleIAMV1.SetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMV1.Policy {
      try await self._intercept(
        request: request,
        options: options,
        name: "setIamPolicy",
        action: {
          (r: GoogleIAMV1.SetIamPolicyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleIAMV1.Policy
          in
          return try await self.inner.setIamPolicy(request: r, options: o)
        })
    }

    public func getIamPolicy(
      request: GoogleIAMV1.GetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMV1.Policy {
      try await self._intercept(
        request: request,
        options: options,
        name: "getIamPolicy",
        action: {
          (r: GoogleIAMV1.GetIamPolicyRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleIAMV1.Policy
          in
          return try await self.inner.getIamPolicy(request: r, options: o)
        })
    }

    public func testIamPermissions(
      request: GoogleIAMV1.TestIamPermissionsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMV1.TestIamPermissionsResponse {
      try await self._intercept(
        request: request,
        options: options,
        name: "testIamPermissions",
        action: {
          (r: GoogleIAMV1.TestIamPermissionsRequest, o: GoogleCloudGax.RequestOptions) async throws
            -> GoogleIAMV1.TestIamPermissionsResponse
          in
          return try await self.inner.testIamPermissions(request: r, options: o)
        })
    }
  }
}
