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

/// API for working with the system policy.
///
/// @Snippet(path: "SystemPolicyV1Quickstart")
public class SystemPolicyV1Client: Clients.SystemPolicyV1Protocol {
  let inner: any Clients.SystemPolicyV1Stub

  /// Creates a new `SystemPolicyV1Client` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.SystemPolicyV1Stub = try Clients.SystemPolicyV1Transport(options)
    inner = Clients.SystemPolicyV1Retry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.SystemPolicyV1Logging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Gets the current system policy in the specified location.
  ///
  /// @Snippet(path: "SystemPolicyV1_GetSystemPolicy")
  public func getSystemPolicy(
    request: GetSystemPolicyRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudBinaryAuthorizationV1.Policy {
    try await self.inner.getSystemPolicy(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: "SystemPolicyV1_SetIamPolicy")
  public func setIamPolicy(
    request: GoogleIAMV1.SetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMV1.Policy {
    try await self.inner.setIamPolicy(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: "SystemPolicyV1_GetIamPolicy")
  public func getIamPolicy(
    request: GoogleIAMV1.GetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMV1.Policy {
    try await self.inner.getIamPolicy(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: "SystemPolicyV1_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 `SystemPolicyV1Client`.
  ///
  /// To mock `SystemPolicyV1Client` change your functions to receive
  /// `some SystemPolicyV1Protocol` or `any SystemPolicyV1Protocol`
  /// and pass a mock implementation in your tests.
  public protocol SystemPolicyV1Protocol {
    /// See `SystemPolicyV1Client.getSystemPolicy`.
    func getSystemPolicy(request: GetSystemPolicyRequest) async throws
      -> GoogleCloudBinaryAuthorizationV1.Policy

    /// See `SystemPolicyV1Client.getSystemPolicy`.
    func getSystemPolicy(
      name: Swift.String,
    ) async throws -> GoogleCloudBinaryAuthorizationV1.Policy

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

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

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

    /// See `SystemPolicyV1Client.getSystemPolicy`.
    func getSystemPolicy(
      request: GetSystemPolicyRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudBinaryAuthorizationV1.Policy

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

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

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

// Default implementations
extension Clients.SystemPolicyV1Protocol {
  public func getSystemPolicy(request: GetSystemPolicyRequest) async throws
    -> GoogleCloudBinaryAuthorizationV1.Policy
  {
    try await self.getSystemPolicy(request: request, options: .init())
  }

  public func getSystemPolicy(
    request: GetSystemPolicyRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudBinaryAuthorizationV1.Policy {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func getSystemPolicy(
    name: Swift.String,
  ) async throws -> GoogleCloudBinaryAuthorizationV1.Policy {
    let request = GetSystemPolicyRequest().with {
      $0.name = name
    }
    return try await self.getSystemPolicy(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 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 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
  }
}
