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

/// Service for ingesting and querying logs.
///
/// @Snippet(path: "LoggingServiceV2Quickstart")
public class LoggingServiceV2Client: Clients.LoggingServiceV2Protocol {
  let inner: any Clients.LoggingServiceV2Stub

  /// Creates a new `LoggingServiceV2Client` instance.
  public init(_ options: GoogleCloudGax.ClientOptions = .init()) throws {
    var inner: any Clients.LoggingServiceV2Stub = try Clients.LoggingServiceV2Transport(options)
    inner = Clients.LoggingServiceV2Retry(inner, options: options)
    if let logger = options.logger {
      inner = Clients.LoggingServiceV2Logging(inner, logger: logger)
    }
    self.inner = inner
  }

  /// Deletes all the log entries in a log for the _Default Log Bucket. The log
  /// reappears if it receives new entries. Log entries written shortly before
  /// the delete operation might not be deleted. Entries received after the
  /// delete operation with a timestamp before the operation will be deleted.
  ///
  /// @Snippet(path: "LoggingServiceV2_DeleteLog")
  public func deleteLog(
    request: DeleteLogRequest, options: GoogleCloudGax.RequestOptions
  ) async throws {
    try await self.inner.deleteLog(request: request, options: options)
  }

  /// Writes log entries to Logging. This API method is the
  /// only way to send log entries to Logging. This method
  /// is used, directly or indirectly, by the Logging agent
  /// (fluentd) and all logging libraries configured to use Logging.
  /// A single request may contain log entries for a maximum of 1000
  /// different resources (projects, organizations, billing accounts or
  /// folders)
  ///
  /// @Snippet(path: "LoggingServiceV2_WriteLogEntries")
  public func writeLogEntries(
    request: WriteLogEntriesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.WriteLogEntriesResponse {
    try await self.inner.writeLogEntries(request: request, options: options)
  }

  /// Lists log entries.  Use this method to retrieve log entries that originated
  /// from a project/folder/organization/billing account.  For ways to export log
  /// entries, see [Exporting
  /// Logs](https://cloud.google.com/logging/docs/export).
  ///
  /// @Snippet(path: "LoggingServiceV2_ListLogEntries")
  public func listLogEntries(
    request: ListLogEntriesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.ListLogEntriesResponse {
    try await self.inner.listLogEntries(request: request, options: options)
  }

  /// Lists log entries.  Use this method to retrieve log entries that originated
  /// from a project/folder/organization/billing account.  For ways to export log
  /// entries, see [Exporting
  /// Logs](https://cloud.google.com/logging/docs/export).
  ///
  /// @Snippet(path: "LoggingServiceV2_ListLogEntries")
  public func listLogEntries(
    byItem: ListLogEntriesRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<LogEntry, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleCloudLoggingV2.ListLogEntriesResponse in
      var request = byItem
      request.pageToken = token
      return try await self.listLogEntries(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  /// Lists the descriptors for monitored resource types used by Logging.
  ///
  /// @Snippet(path: "LoggingServiceV2_ListMonitoredResourceDescriptors")
  public func listMonitoredResourceDescriptors(
    request: ListMonitoredResourceDescriptorsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.ListMonitoredResourceDescriptorsResponse {
    try await self.inner.listMonitoredResourceDescriptors(request: request, options: options)
  }

  /// Lists the descriptors for monitored resource types used by Logging.
  ///
  /// @Snippet(path: "LoggingServiceV2_ListMonitoredResourceDescriptors")
  public func listMonitoredResourceDescriptors(
    byItem: ListMonitoredResourceDescriptorsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<GoogleApi.MonitoredResourceDescriptor, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws
        -> GoogleCloudLoggingV2.ListMonitoredResourceDescriptorsResponse in
      var request = byItem
      request.pageToken = token
      return try await self.listMonitoredResourceDescriptors(request: request, options: options)
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  /// Lists the logs in projects, organizations, folders, or billing accounts.
  /// Only logs that have entries are listed.
  ///
  /// @Snippet(path: "LoggingServiceV2_ListLogs")
  public func listLogs(
    request: ListLogsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.ListLogsResponse {
    try await self.inner.listLogs(request: request, options: options)
  }

  /// Streaming read of log entries as they are ingested. Until the stream is
  /// terminated, it will continue reading logs.
  ///
  /// @Snippet(path: "LoggingServiceV2_TailLogEntries")
  public func tailLogEntries(
    request: TailLogEntriesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.TailLogEntriesResponse {
    try await self.inner.tailLogEntries(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: "LoggingServiceV2_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: "LoggingServiceV2_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: "LoggingServiceV2_GetOperation")
  func getOperation(
    request: GoogleLongRunning.GetOperationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleLongRunning.Operation {
    try await self.inner.getOperation(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: "LoggingServiceV2_CancelOperation")
  public func cancelOperation(
    request: GoogleLongRunning.CancelOperationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws {
    try await self.inner.cancelOperation(request: request, options: options)
  }
}

extension Clients {
  /// A Swift protocol to mock `LoggingServiceV2Client`.
  ///
  /// To mock `LoggingServiceV2Client` change your functions to receive
  /// `some LoggingServiceV2Protocol` or `any LoggingServiceV2Protocol`
  /// and pass a mock implementation in your tests.
  public protocol LoggingServiceV2Protocol {
    /// See `LoggingServiceV2Client.deleteLog`.
    func deleteLog(request: DeleteLogRequest) async throws

    /// See `LoggingServiceV2Client.deleteLog`.
    func deleteLog(
      logName: Swift.String,
    ) async throws

    /// See `LoggingServiceV2Client.writeLogEntries`.
    func writeLogEntries(request: WriteLogEntriesRequest) async throws
      -> GoogleCloudLoggingV2.WriteLogEntriesResponse

    /// See `LoggingServiceV2Client.writeLogEntries`.
    func writeLogEntries(
      logName: Swift.String,
      resource: GoogleApi.MonitoredResource?,
      labels: [Swift.String: Swift.String],
      entries: [LogEntry],
    ) async throws -> GoogleCloudLoggingV2.WriteLogEntriesResponse

    /// See `LoggingServiceV2Client.listLogEntries`.
    func listLogEntries(request: ListLogEntriesRequest) async throws
      -> GoogleCloudLoggingV2.ListLogEntriesResponse

    /// See `LoggingServiceV2Client.listLogEntries`.
    func listLogEntries(
      byItem: ListLogEntriesRequest
    ) throws -> any AsyncSequence<LogEntry, Swift.Error>

    /// See `LoggingServiceV2Client.listLogEntries`.
    func listLogEntries(
      resourceNames: [Swift.String],
      filter: Swift.String,
      orderBy: Swift.String,
    ) throws -> any AsyncSequence<LogEntry, Swift.Error>

    /// See `LoggingServiceV2Client.listMonitoredResourceDescriptors`.
    func listMonitoredResourceDescriptors(request: ListMonitoredResourceDescriptorsRequest)
      async throws -> GoogleCloudLoggingV2.ListMonitoredResourceDescriptorsResponse

    /// See `LoggingServiceV2Client.listMonitoredResourceDescriptors`.
    func listMonitoredResourceDescriptors(
      byItem: ListMonitoredResourceDescriptorsRequest
    ) throws -> any AsyncSequence<GoogleApi.MonitoredResourceDescriptor, Swift.Error>

    /// See `LoggingServiceV2Client.listLogs`.
    func listLogs(request: ListLogsRequest) async throws -> GoogleCloudLoggingV2.ListLogsResponse

    /// See `LoggingServiceV2Client.listLogs`.
    func listLogs(
      parent: Swift.String,
    ) async throws -> GoogleCloudLoggingV2.ListLogsResponse

    /// See `LoggingServiceV2Client.tailLogEntries`.
    func tailLogEntries(request: TailLogEntriesRequest) async throws
      -> GoogleCloudLoggingV2.TailLogEntriesResponse

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

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

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

    /// See `LoggingServiceV2Client.cancelOperation`.
    func cancelOperation(request: GoogleLongRunning.CancelOperationRequest) async throws

    /// See `LoggingServiceV2Client.cancelOperation`.
    func cancelOperation(
      name: Swift.String,
    ) async throws

    /// See `LoggingServiceV2Client.deleteLog`.
    func deleteLog(
      request: DeleteLogRequest, options: GoogleCloudGax.RequestOptions
    ) async throws

    /// See `LoggingServiceV2Client.writeLogEntries`.
    func writeLogEntries(
      request: WriteLogEntriesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLoggingV2.WriteLogEntriesResponse

    /// See `LoggingServiceV2Client.listLogEntries`.
    func listLogEntries(
      request: ListLogEntriesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLoggingV2.ListLogEntriesResponse

    /// See `LoggingServiceV2Client.listLogEntries`.
    func listLogEntries(
      byItem: ListLogEntriesRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<LogEntry, Swift.Error>

    /// See `LoggingServiceV2Client.listMonitoredResourceDescriptors`.
    func listMonitoredResourceDescriptors(
      request: ListMonitoredResourceDescriptorsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLoggingV2.ListMonitoredResourceDescriptorsResponse

    /// See `LoggingServiceV2Client.listMonitoredResourceDescriptors`.
    func listMonitoredResourceDescriptors(
      byItem: ListMonitoredResourceDescriptorsRequest, options: GoogleCloudGax.RequestOptions
    ) throws -> any AsyncSequence<GoogleApi.MonitoredResourceDescriptor, Swift.Error>

    /// See `LoggingServiceV2Client.listLogs`.
    func listLogs(
      request: ListLogsRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLoggingV2.ListLogsResponse

    /// See `LoggingServiceV2Client.tailLogEntries`.
    func tailLogEntries(
      request: TailLogEntriesRequest, options: GoogleCloudGax.RequestOptions
    ) async throws -> GoogleCloudLoggingV2.TailLogEntriesResponse

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

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

    /// See `LoggingServiceV2Client.cancelOperation`.
    func cancelOperation(
      request: GoogleLongRunning.CancelOperationRequest, options: GoogleCloudGax.RequestOptions
    ) async throws
  }
}

// Default implementations
extension Clients.LoggingServiceV2Protocol {
  public func deleteLog(request: DeleteLogRequest) async throws {
    try await self.deleteLog(request: request, options: .init())
  }

  public func deleteLog(
    request: DeleteLogRequest, options: GoogleCloudGax.RequestOptions
  ) async throws {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func deleteLog(
    logName: Swift.String,
  ) async throws {
    let request = DeleteLogRequest().with {
      $0.logName = logName
    }
    try await self.deleteLog(request: request)
  }

  public func writeLogEntries(request: WriteLogEntriesRequest) async throws
    -> GoogleCloudLoggingV2.WriteLogEntriesResponse
  {
    try await self.writeLogEntries(request: request, options: .init())
  }

  public func writeLogEntries(
    request: WriteLogEntriesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.WriteLogEntriesResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func writeLogEntries(
    logName: Swift.String,
    resource: GoogleApi.MonitoredResource?,
    labels: [Swift.String: Swift.String],
    entries: [LogEntry],
  ) async throws -> GoogleCloudLoggingV2.WriteLogEntriesResponse {
    let request = WriteLogEntriesRequest().with {
      $0.logName = logName
      $0.resource = resource
      $0.labels = labels
      $0.entries = entries
    }
    return try await self.writeLogEntries(request: request)
  }

  public func listLogEntries(request: ListLogEntriesRequest) async throws
    -> GoogleCloudLoggingV2.ListLogEntriesResponse
  {
    try await self.listLogEntries(request: request, options: .init())
  }

  public func listLogEntries(
    request: ListLogEntriesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.ListLogEntriesResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func listLogEntries(
    byItem: ListLogEntriesRequest
  ) throws -> any AsyncSequence<LogEntry, Swift.Error> {
    try self.listLogEntries(byItem: byItem, options: .init())
  }

  public func listLogEntries(
    byItem: ListLogEntriesRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<LogEntry, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws -> GoogleCloudLoggingV2.ListLogEntriesResponse in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func listLogEntries(
    resourceNames: [Swift.String],
    filter: Swift.String,
    orderBy: Swift.String,
  ) throws -> any AsyncSequence<LogEntry, Swift.Error> {
    let request = ListLogEntriesRequest().with {
      $0.resourceNames = resourceNames
      $0.filter = filter
      $0.orderBy = orderBy
    }
    return try self.listLogEntries(byItem: request)
  }

  public func listMonitoredResourceDescriptors(request: ListMonitoredResourceDescriptorsRequest)
    async throws -> GoogleCloudLoggingV2.ListMonitoredResourceDescriptorsResponse
  {
    try await self.listMonitoredResourceDescriptors(request: request, options: .init())
  }

  public func listMonitoredResourceDescriptors(
    request: ListMonitoredResourceDescriptorsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.ListMonitoredResourceDescriptorsResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func listMonitoredResourceDescriptors(
    byItem: ListMonitoredResourceDescriptorsRequest
  ) throws -> any AsyncSequence<GoogleApi.MonitoredResourceDescriptor, Swift.Error> {
    try self.listMonitoredResourceDescriptors(byItem: byItem, options: .init())
  }

  public func listMonitoredResourceDescriptors(
    byItem: ListMonitoredResourceDescriptorsRequest, options: GoogleCloudGax.RequestOptions
  ) throws -> any AsyncSequence<GoogleApi.MonitoredResourceDescriptor, Swift.Error> {
    let listRpc = {
      (token: Swift.String) async throws
        -> GoogleCloudLoggingV2.ListMonitoredResourceDescriptorsResponse in
      throw GoogleCloudGax.RequestError.unimplemented
    }
    return GoogleCloudGax.PaginatedResponseSequence(listRpc: listRpc)
  }

  public func listLogs(request: ListLogsRequest) async throws
    -> GoogleCloudLoggingV2.ListLogsResponse
  {
    try await self.listLogs(request: request, options: .init())
  }

  public func listLogs(
    request: ListLogsRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.ListLogsResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func listLogs(
    parent: Swift.String,
  ) async throws -> GoogleCloudLoggingV2.ListLogsResponse {
    let request = ListLogsRequest().with {
      $0.parent = parent
    }
    return try await self.listLogs(request: request)
  }

  public func tailLogEntries(request: TailLogEntriesRequest) async throws
    -> GoogleCloudLoggingV2.TailLogEntriesResponse
  {
    try await self.tailLogEntries(request: request, options: .init())
  }

  public func tailLogEntries(
    request: TailLogEntriesRequest, options: GoogleCloudGax.RequestOptions
  ) async throws -> GoogleCloudLoggingV2.TailLogEntriesResponse {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  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)
  }

  public func cancelOperation(request: GoogleLongRunning.CancelOperationRequest) async throws {
    try await self.cancelOperation(request: request, options: .init())
  }

  public func cancelOperation(
    request: GoogleLongRunning.CancelOperationRequest, options: GoogleCloudGax.RequestOptions
  ) async throws {
    throw GoogleCloudGax.RequestError.unimplemented
  }

  public func cancelOperation(
    name: Swift.String,
  ) async throws {
    let request = GoogleLongRunning.CancelOperationRequest().with {
      $0.name = name
    }
    try await self.cancelOperation(request: request)
  }
}
