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

/// Service for search.
///
/// This feature is only available for users who have Retail Search enabled.
/// Enable Retail Search on Cloud Console before using this feature.
///
/// @Snippet(path: "SearchServiceQuickstart")
public class SearchServiceClient: Clients.SearchServiceProtocol {
  let inner: any Clients.SearchServiceStub

  /// Creates a new `SearchServiceClient` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.SearchServiceStub = try Clients.SearchServiceTransport(options)
    inner = Clients.SearchServiceRetry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.SearchServiceLogging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Performs a search.
  ///
  /// This feature is only available for users who have Retail Search enabled.
  /// Enable Retail Search on Cloud Console before using this feature.
  ///
  /// @Snippet(path: "SearchService_Search")
  public func search(
    request: SearchRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudRetailV2.SearchResponse {
    try await self.inner.search(request: request, options: options)
  }

  /// Performs a search.
  ///
  /// This feature is only available for users who have Retail Search enabled.
  /// Enable Retail Search on Cloud Console before using this feature.
  ///
  /// @Snippet(path: "SearchService_Search")
  public func search(
    byItem: SearchRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<SearchResponse.SearchResult, Swift.Error> {
    let listRpc = { (token: Swift.String) async throws -> GoogleCloudRetailV2.SearchResponse in
      var request = byItem
      request.pageToken = token
      return try await self.search(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  /// 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: "SearchService_ListOperations")
  public func listOperations(
    request: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.ListOperationsResponse {
    try await self.inner.listOperations(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: "SearchService_ListOperations")
  public func listOperations(
    byItem: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleLongRunning.ListOperationsResponse in
      var request = byItem
      request.pageToken = token
      return try await self.listOperations(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  /// 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: "SearchService_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 `SearchServiceClient`.
  ///
  /// To mock `SearchServiceClient` change your functions to receive
  /// `some SearchServiceProtocol` or `any SearchServiceProtocol`
  /// and pass a mock implementation in your tests.
  public protocol SearchServiceProtocol {
    /// See `SearchServiceClient.search`.
    func search(request: SearchRequest) async throws -> GoogleCloudRetailV2.SearchResponse

    /// See `SearchServiceClient.search`.
    func search(
      byItem: SearchRequest
    ) throws -> any AsyncSequence<SearchResponse.SearchResult, Swift.Error>

    /// See `SearchServiceClient.listOperations`.
    func listOperations(request: GoogleLongRunning.ListOperationsRequest) async throws
      -> GoogleLongRunning.ListOperationsResponse

    /// See `SearchServiceClient.listOperations`.
    func listOperations(
      byItem: GoogleLongRunning.ListOperationsRequest
    ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error>

    /// See `SearchServiceClient.listOperations`.
    func listOperations(
      name: Swift.String,
      filter: Swift.String,
    ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error>

    /// See `SearchServiceClient.search`.
    func search(
      request: SearchRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudRetailV2.SearchResponse

    /// See `SearchServiceClient.search`.
    func search(
      byItem: SearchRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<SearchResponse.SearchResult, Swift.Error>

    /// See `SearchServiceClient.listOperations`.
    func listOperations(
      request: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleLongRunning.ListOperationsResponse

    /// See `SearchServiceClient.listOperations`.
    func listOperations(
      byItem: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error>
  }
}

// Default implementations
extension Clients.SearchServiceProtocol {
  public func search(request: SearchRequest) async throws -> GoogleCloudRetailV2.SearchResponse {
    try await self.search(request: request, options: .init())
  }

  public func search(
    request: SearchRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudRetailV2.SearchResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func search(
    byItem: SearchRequest
  ) throws -> any AsyncSequence<SearchResponse.SearchResult, Swift.Error> {
    try self.search(byItem: byItem, options: .init())
  }

  public func search(
    byItem: SearchRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<SearchResponse.SearchResult, Swift.Error> {
    let listRpc = { (token: Swift.String) async throws -> GoogleCloudRetailV2.SearchResponse in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func listOperations(request: GoogleLongRunning.ListOperationsRequest) async throws
    -> GoogleLongRunning.ListOperationsResponse
  {
    try await self.listOperations(request: request, options: .init())
  }

  public func listOperations(
    request: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.ListOperationsResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func listOperations(
    byItem: GoogleLongRunning.ListOperationsRequest
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    try self.listOperations(byItem: byItem, options: .init())
  }

  public func listOperations(
    byItem: GoogleLongRunning.ListOperationsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleLongRunning.ListOperationsResponse in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func listOperations(
    name: Swift.String,
    filter: Swift.String,
  ) throws -> any AsyncSequence<GoogleLongRunning.Operation, Swift.Error> {
    let request = GoogleLongRunning.ListOperationsRequest().with {
      $0.name = name
      $0.filter = filter
    }
    return try self.listOperations(byItem: 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)
  }
}
