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

/// A service account is a special type of Google account that belongs to your
/// application or a virtual machine (VM), instead of to an individual end user.
/// Your application assumes the identity of the service account to call Google
/// APIs, so that the users aren't directly involved.
///
/// Service account credentials are used to temporarily assume the identity
/// of the service account. Supported credential types include OAuth 2.0 access
/// tokens, OpenID Connect ID tokens, self-signed JSON Web Tokens (JWTs), and
/// more.
///
/// @Snippet(path: "IAMCredentialsQuickstart")
public class IAMCredentialsClient: Clients.IAMCredentialsProtocol {
  let inner: any Clients.IAMCredentialsStub

  /// Creates a new `IAMCredentialsClient` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.IAMCredentialsStub = try Clients.IAMCredentialsTransport(options)
    inner = Clients.IAMCredentialsRetry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.IAMCredentialsLogging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Generates an OAuth 2.0 access token for a service account.
  ///
  /// @Snippet(path: "IAMCredentials_GenerateAccessToken")
  public func generateAccessToken(
    request: GenerateAccessTokenRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMCredentialsV1.GenerateAccessTokenResponse {
    try await self.inner.generateAccessToken(request: request, options: options)
  }

  /// Generates an OpenID Connect ID token for a service account.
  ///
  /// @Snippet(path: "IAMCredentials_GenerateIdToken")
  public func generateIdToken(
    request: GenerateIdTokenRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMCredentialsV1.GenerateIdTokenResponse {
    try await self.inner.generateIdToken(request: request, options: options)
  }

  /// Signs a blob using a service account's system-managed private key.
  ///
  /// @Snippet(path: "IAMCredentials_SignBlob")
  public func signBlob(
    request: SignBlobRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMCredentialsV1.SignBlobResponse {
    try await self.inner.signBlob(request: request, options: options)
  }

  /// Signs a JWT using a service account's system-managed private key.
  ///
  /// @Snippet(path: "IAMCredentials_SignJwt")
  public func signJwt(
    request: SignJwtRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMCredentialsV1.SignJwtResponse {
    try await self.inner.signJwt(request: request, options: options)
  }
}

extension Clients {
  /// A Swift protocol to mock `IAMCredentialsClient`.
  ///
  /// To mock `IAMCredentialsClient` change your functions to receive
  /// `some IAMCredentialsProtocol` or `any IAMCredentialsProtocol`
  /// and pass a mock implementation in your tests.
  public protocol IAMCredentialsProtocol {
    /// See `IAMCredentialsClient.generateAccessToken`.
    func generateAccessToken(request: GenerateAccessTokenRequest) async throws
      -> GoogleIAMCredentialsV1.GenerateAccessTokenResponse

    /// See `IAMCredentialsClient.generateAccessToken`.
    func generateAccessToken(
      name: Swift.String,
      delegates: [Swift.String],
      scope: [Swift.String],
      lifetime: GoogleCloudWkt.Duration?,
    ) async throws -> GoogleIAMCredentialsV1.GenerateAccessTokenResponse

    /// See `IAMCredentialsClient.generateIdToken`.
    func generateIdToken(request: GenerateIdTokenRequest) async throws
      -> GoogleIAMCredentialsV1.GenerateIdTokenResponse

    /// See `IAMCredentialsClient.generateIdToken`.
    func generateIdToken(
      name: Swift.String,
      delegates: [Swift.String],
      audience: Swift.String,
      includeEmail: Swift.Bool,
    ) async throws -> GoogleIAMCredentialsV1.GenerateIdTokenResponse

    /// See `IAMCredentialsClient.signBlob`.
    func signBlob(request: SignBlobRequest) async throws -> GoogleIAMCredentialsV1.SignBlobResponse

    /// See `IAMCredentialsClient.signBlob`.
    func signBlob(
      name: Swift.String,
      delegates: [Swift.String],
      payload: Foundation.Data,
    ) async throws -> GoogleIAMCredentialsV1.SignBlobResponse

    /// See `IAMCredentialsClient.signJwt`.
    func signJwt(request: SignJwtRequest) async throws -> GoogleIAMCredentialsV1.SignJwtResponse

    /// See `IAMCredentialsClient.signJwt`.
    func signJwt(
      name: Swift.String,
      delegates: [Swift.String],
      payload: Swift.String,
    ) async throws -> GoogleIAMCredentialsV1.SignJwtResponse

    /// See `IAMCredentialsClient.generateAccessToken`.
    func generateAccessToken(
      request: GenerateAccessTokenRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMCredentialsV1.GenerateAccessTokenResponse

    /// See `IAMCredentialsClient.generateIdToken`.
    func generateIdToken(
      request: GenerateIdTokenRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMCredentialsV1.GenerateIdTokenResponse

    /// See `IAMCredentialsClient.signBlob`.
    func signBlob(
      request: SignBlobRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMCredentialsV1.SignBlobResponse

    /// See `IAMCredentialsClient.signJwt`.
    func signJwt(
      request: SignJwtRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleIAMCredentialsV1.SignJwtResponse
  }
}

// Default implementations
extension Clients.IAMCredentialsProtocol {
  public func generateAccessToken(request: GenerateAccessTokenRequest) async throws
    -> GoogleIAMCredentialsV1.GenerateAccessTokenResponse
  {
    try await self.generateAccessToken(request: request, options: .init())
  }

  public func generateAccessToken(
    request: GenerateAccessTokenRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMCredentialsV1.GenerateAccessTokenResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func generateAccessToken(
    name: Swift.String,
    delegates: [Swift.String],
    scope: [Swift.String],
    lifetime: GoogleCloudWkt.Duration?,
  ) async throws -> GoogleIAMCredentialsV1.GenerateAccessTokenResponse {
    let request = GenerateAccessTokenRequest().with {
      $0.name = name
      $0.delegates = delegates
      $0.scope = scope
      $0.lifetime = lifetime
    }
    return try await self.generateAccessToken(request: request)
  }

  public func generateIdToken(request: GenerateIdTokenRequest) async throws
    -> GoogleIAMCredentialsV1.GenerateIdTokenResponse
  {
    try await self.generateIdToken(request: request, options: .init())
  }

  public func generateIdToken(
    request: GenerateIdTokenRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMCredentialsV1.GenerateIdTokenResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func generateIdToken(
    name: Swift.String,
    delegates: [Swift.String],
    audience: Swift.String,
    includeEmail: Swift.Bool,
  ) async throws -> GoogleIAMCredentialsV1.GenerateIdTokenResponse {
    let request = GenerateIdTokenRequest().with {
      $0.name = name
      $0.delegates = delegates
      $0.audience = audience
      $0.includeEmail = includeEmail
    }
    return try await self.generateIdToken(request: request)
  }

  public func signBlob(request: SignBlobRequest) async throws
    -> GoogleIAMCredentialsV1.SignBlobResponse
  {
    try await self.signBlob(request: request, options: .init())
  }

  public func signBlob(
    request: SignBlobRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMCredentialsV1.SignBlobResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func signBlob(
    name: Swift.String,
    delegates: [Swift.String],
    payload: Foundation.Data,
  ) async throws -> GoogleIAMCredentialsV1.SignBlobResponse {
    let request = SignBlobRequest().with {
      $0.name = name
      $0.delegates = delegates
      $0.payload = payload
    }
    return try await self.signBlob(request: request)
  }

  public func signJwt(request: SignJwtRequest) async throws
    -> GoogleIAMCredentialsV1.SignJwtResponse
  {
    try await self.signJwt(request: request, options: .init())
  }

  public func signJwt(
    request: SignJwtRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMCredentialsV1.SignJwtResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func signJwt(
    name: Swift.String,
    delegates: [Swift.String],
    payload: Swift.String,
  ) async throws -> GoogleIAMCredentialsV1.SignJwtResponse {
    let request = SignJwtRequest().with {
      $0.name = name
      $0.delegates = delegates
      $0.payload = payload
    }
    return try await self.signJwt(request: request)
  }
}
