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

/// Allows users to manage their organization resources.
///
/// @Snippet(path: "OrganizationsQuickstart")
public class OrganizationsClient: Clients.OrganizationsProtocol {
  let inner: any Clients.OrganizationsStub

  /// Creates a new `OrganizationsClient` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.OrganizationsStub = try Clients.OrganizationsTransport(options)
    inner = Clients.OrganizationsRetry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.OrganizationsLogging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Fetches an organization resource identified by the specified resource name.
  ///
  /// @Snippet(path: "Organizations_GetOrganization")
  public func getOrganization(
    request: GetOrganizationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudResourceManagerV3.Organization {
    try await self.inner.getOrganization(request: request, options: options)
  }

  /// Searches organization resources that are visible to the user and satisfy
  /// the specified filter. This method returns organizations in an unspecified
  /// order. New organizations do not necessarily appear at the end of the
  /// results, and may take a small amount of time to appear.
  ///
  /// Search will only return organizations on which the user has the permission
  /// `resourcemanager.organizations.get`
  ///
  /// @Snippet(path: "Organizations_SearchOrganizations")
  public func searchOrganizations(
    request: SearchOrganizationsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudResourceManagerV3.SearchOrganizationsResponse {
    try await self.inner.searchOrganizations(request: request, options: options)
  }

  /// Searches organization resources that are visible to the user and satisfy
  /// the specified filter. This method returns organizations in an unspecified
  /// order. New organizations do not necessarily appear at the end of the
  /// results, and may take a small amount of time to appear.
  ///
  /// Search will only return organizations on which the user has the permission
  /// `resourcemanager.organizations.get`
  ///
  /// @Snippet(path: "Organizations_SearchOrganizations")
  public func searchOrganizations(
    byItem: SearchOrganizationsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<Organization, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleCloudResourceManagerV3.SearchOrganizationsResponse
      in
      var request = byItem
      request.pageToken = token
      return try await self.searchOrganizations(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  /// Gets the access control policy for an organization resource. The policy may
  /// be empty if no such policy or resource exists. The `resource` field should
  /// be the organization's resource name, for example: "organizations/123".
  ///
  /// Authorization requires the IAM permission
  /// `resourcemanager.organizations.getIamPolicy` on the specified organization.
  ///
  /// @Snippet(path: "Organizations_GetIamPolicy")
  public func getIamPolicy(
    request: GoogleIAMV1.GetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMV1.Policy {
    try await self.inner.getIamPolicy(request: request, options: options)
  }

  /// Sets the access control policy on an organization resource. Replaces any
  /// existing policy. The `resource` field should be the organization's resource
  /// name, for example: "organizations/123".
  ///
  /// Authorization requires the IAM permission
  /// `resourcemanager.organizations.setIamPolicy` on the specified organization.
  ///
  /// @Snippet(path: "Organizations_SetIamPolicy")
  public func setIamPolicy(
    request: GoogleIAMV1.SetIamPolicyRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMV1.Policy {
    try await self.inner.setIamPolicy(request: request, options: options)
  }

  /// Returns the permissions that a caller has on the specified organization.
  /// The `resource` field should be the organization's resource name,
  /// for example: "organizations/123".
  ///
  /// There are no permissions required for making this API call.
  ///
  /// @Snippet(path: "Organizations_TestIamPermissions")
  public func testIamPermissions(
    request: GoogleIAMV1.TestIamPermissionsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleIAMV1.TestIamPermissionsResponse {
    try await self.inner.testIamPermissions(request: request, options: options)
  }

  /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
  ///
  /// [google.longrunning.Operations]: https://www.google.com/search?q=Swift+google.longrunning+Operations
  ///
  /// @Snippet(path: "Organizations_GetOperation")
  func getOperation(
    request: GoogleLongRunning.GetOperationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.Operation {
    try await self.inner.getOperation(request: request, options: options)
  }
}

extension Clients {
  /// A Swift protocol to mock `OrganizationsClient`.
  ///
  /// To mock `OrganizationsClient` change your functions to receive
  /// `some OrganizationsProtocol` or `any OrganizationsProtocol`
  /// and pass a mock implementation in your tests.
  public protocol OrganizationsProtocol {
    /// See `OrganizationsClient.getOrganization`.
    func getOrganization(request: GetOrganizationRequest) async throws
      -> GoogleCloudResourceManagerV3.Organization

    /// See `OrganizationsClient.getOrganization`.
    func getOrganization(
      name: Swift.String,
    ) async throws -> GoogleCloudResourceManagerV3.Organization

    /// See `OrganizationsClient.searchOrganizations`.
    func searchOrganizations(request: SearchOrganizationsRequest) async throws
      -> GoogleCloudResourceManagerV3.SearchOrganizationsResponse

    /// See `OrganizationsClient.searchOrganizations`.
    func searchOrganizations(
      byItem: SearchOrganizationsRequest
    ) throws -> any AsyncSequence<Organization, Swift.Error>

    /// See `OrganizationsClient.searchOrganizations`.
    func searchOrganizations(
      query: Swift.String,
    ) throws -> any AsyncSequence<Organization, Swift.Error>

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

    /// See `OrganizationsClient.getIamPolicy`.
    func getIamPolicy(
      resource: Swift.String,
    ) async throws -> GoogleIAMV1.Policy

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

    /// See `OrganizationsClient.setIamPolicy`.
    func setIamPolicy(
      resource: Swift.String,
    ) async throws -> GoogleIAMV1.Policy

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

    /// See `OrganizationsClient.testIamPermissions`.
    func testIamPermissions(
      resource: Swift.String,
      permissions: [Swift.String],
    ) async throws -> GoogleIAMV1.TestIamPermissionsResponse

    /// See `OrganizationsClient.getOrganization`.
    func getOrganization(
      request: GetOrganizationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudResourceManagerV3.Organization

    /// See `OrganizationsClient.searchOrganizations`.
    func searchOrganizations(
      request: SearchOrganizationsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudResourceManagerV3.SearchOrganizationsResponse

    /// See `OrganizationsClient.searchOrganizations`.
    func searchOrganizations(
      byItem: SearchOrganizationsRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<Organization, Swift.Error>

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

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

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

// Default implementations
extension Clients.OrganizationsProtocol {
  public func getOrganization(request: GetOrganizationRequest) async throws
    -> GoogleCloudResourceManagerV3.Organization
  {
    try await self.getOrganization(request: request, options: .init())
  }

  public func getOrganization(
    request: GetOrganizationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudResourceManagerV3.Organization {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func getOrganization(
    name: Swift.String,
  ) async throws -> GoogleCloudResourceManagerV3.Organization {
    let request = GetOrganizationRequest().with {
      $0.name = name
    }
    return try await self.getOrganization(request: request)
  }

  public func searchOrganizations(request: SearchOrganizationsRequest) async throws
    -> GoogleCloudResourceManagerV3.SearchOrganizationsResponse
  {
    try await self.searchOrganizations(request: request, options: .init())
  }

  public func searchOrganizations(
    request: SearchOrganizationsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudResourceManagerV3.SearchOrganizationsResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func searchOrganizations(
    byItem: SearchOrganizationsRequest
  ) throws -> any AsyncSequence<Organization, Swift.Error> {
    try self.searchOrganizations(byItem: byItem, options: .init())
  }

  public func searchOrganizations(
    byItem: SearchOrganizationsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<Organization, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleCloudResourceManagerV3.SearchOrganizationsResponse
      in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func searchOrganizations(
    query: Swift.String,
  ) throws -> any AsyncSequence<Organization, Swift.Error> {
    let request = SearchOrganizationsRequest().with {
      $0.query = query
    }
    return try self.searchOrganizations(byItem: request)
  }

  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 getIamPolicy(
    resource: Swift.String,
  ) async throws -> GoogleIAMV1.Policy {
    let request = GoogleIAMV1.GetIamPolicyRequest().with {
      $0.resource = resource
    }
    return try await self.getIamPolicy(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 setIamPolicy(
    resource: Swift.String,
  ) async throws -> GoogleIAMV1.Policy {
    let request = GoogleIAMV1.SetIamPolicyRequest().with {
      $0.resource = resource
    }
    return try await self.setIamPolicy(request: request)
  }

  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
  }

  public func testIamPermissions(
    resource: Swift.String,
    permissions: [Swift.String],
  ) async throws -> GoogleIAMV1.TestIamPermissionsResponse {
    let request = GoogleIAMV1.TestIamPermissionsRequest().with {
      $0.resource = resource
      $0.permissions = permissions
    }
    return try await self.testIamPermissions(request: request)
  }

  public func getOperation(request: GoogleLongRunning.GetOperationRequest) async throws
    -> GoogleLongRunning.Operation
  {
    try await self.getOperation(request: request, options: .init())
  }

  public func getOperation(
    request: GoogleLongRunning.GetOperationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.Operation {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func getOperation(
    name: Swift.String,
  ) async throws -> GoogleLongRunning.Operation {
    let request = GoogleLongRunning.GetOperationRequest().with {
      $0.name = name
    }
    return try await self.getOperation(request: request)
  }
}
