# frozen_string_literal: true

# The MIT License (MIT)
#
# Copyright <YEAR> <COPYRIGHT HOLDER>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# Auto-generated by gapic-generator-ruby. DO NOT EDIT!

require "google/showcase/v1beta1/echo_pb"

module Google
  module Showcase
    module V1beta1
      module Echo
        ##
        # Client for the Echo service.
        #
        # This service is used showcase the four main types of rpcs - unary, server
        # side streaming, client side streaming, and bidirectional streaming. This
        # service also exposes methods that explicitly implement server delay, and
        # paginated calls. Set the 'showcase-trailer' metadata key on any method
        # to have the values echoed in the response trailers.
        #
        class Client
          # @private
          attr_reader :echo_stub

          ##
          # Configure the Echo Client class.
          #
          # See {::Google::Showcase::V1beta1::Echo::Client::Configuration}
          # for a description of the configuration fields.
          #
          # @example
          #
          #   # Modify the configuration for all Echo clients
          #   ::Google::Showcase::V1beta1::Echo::Client.configure do |config|
          #     config.timeout = 10.0
          #   end
          #
          # @yield [config] Configure the Client client.
          # @yieldparam config [Client::Configuration]
          #
          # @return [Client::Configuration]
          #
          def self.configure
            @configure ||= begin
              default_config = Client::Configuration.new

              default_config
            end
            yield @configure if block_given?
            @configure
          end

          ##
          # Configure the Echo Client instance.
          #
          # The configuration is set to the derived mode, meaning that values can be changed,
          # but structural changes (adding new fields, etc.) are not allowed. Structural changes
          # should be made on {Client.configure}.
          #
          # See {::Google::Showcase::V1beta1::Echo::Client::Configuration}
          # for a description of the configuration fields.
          #
          # @yield [config] Configure the Client client.
          # @yieldparam config [Client::Configuration]
          #
          # @return [Client::Configuration]
          #
          def configure
            yield @config if block_given?
            @config
          end

          ##
          # Create a new Echo client object.
          #
          # @example
          #
          #   # Create a client using the default configuration
          #   client = ::Google::Showcase::V1beta1::Echo::Client.new
          #
          #   # Create a client using a custom configuration
          #   client = ::Google::Showcase::V1beta1::Echo::Client.new do |config|
          #     config.timeout = 10.0
          #   end
          #
          # @yield [config] Configure the Echo client.
          # @yieldparam config [Client::Configuration]
          #
          def initialize
            # These require statements are intentionally placed here to initialize
            # the gRPC module only when it's required.
            # See https://github.com/googleapis/toolkit/issues/446
            require "gapic/grpc"
            require "google/showcase/v1beta1/echo_services_pb"

            # Create the configuration object
            @config = Configuration.new Client.configure

            # Yield the configuration if needed
            yield @config if block_given?

            # Create credentials
            credentials = @config.credentials
            # Use self-signed JWT if the endpoint is unchanged from default,
            # but only if the default endpoint does not have a region prefix.
            enable_self_signed_jwt = @config.endpoint == Client.configure.endpoint &&
                                     !@config.endpoint.split(".").first.include?("-")
            credentials ||= Credentials.default scope: @config.scope,
                                                enable_self_signed_jwt: enable_self_signed_jwt
            if credentials.is_a?(::String) || credentials.is_a?(::Hash)
              credentials = Credentials.new credentials, scope: @config.scope
            end
            @quota_project_id = @config.quota_project
            @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id

            @operations_client = Operations.new do |config|
              config.credentials = credentials
              config.quota_project = @quota_project_id
              config.endpoint = @config.endpoint
            end

            @echo_stub = ::Gapic::ServiceStub.new(
              ::Google::Showcase::V1beta1::Echo::Stub,
              credentials:  credentials,
              endpoint:     @config.endpoint,
              channel_args: @config.channel_args,
              interceptors: @config.interceptors
            )
          end

          ##
          # Get the associated client for long-running operations.
          #
          # @return [::Google::Showcase::V1beta1::Echo::Operations]
          #
          attr_reader :operations_client

          # Service calls

          ##
          # This method simply echos the request. This method is showcases unary rpcs.
          #
          # @overload echo(request, options = nil)
          #   Pass arguments to `echo` via a request object, either of type
          #   {::Google::Showcase::V1beta1::EchoRequest} or an equivalent Hash.
          #
          #   @param request [::Google::Showcase::V1beta1::EchoRequest, ::Hash]
          #     A request object representing the call parameters. Required. To specify no
          #     parameters, or to keep all the default parameter values, pass an empty Hash.
          #   @param options [::Gapic::CallOptions, ::Hash]
          #     Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
          #
          # @overload echo(content: nil, error: nil)
          #   Pass arguments to `echo` via keyword arguments. Note that at
          #   least one keyword argument is required. To specify no parameters, or to keep all
          #   the default parameter values, pass an empty Hash as a request object (see above).
          #
          #   @param content [::String]
          #     The content to be echoed by the server.
          #   @param error [::Google::Rpc::Status, ::Hash]
          #     The error to be thrown by the server.
          #
          # @yield [response, operation] Access the result along with the RPC operation
          # @yieldparam response [::Google::Showcase::V1beta1::EchoResponse]
          # @yieldparam operation [::GRPC::ActiveCall::Operation]
          #
          # @return [::Google::Showcase::V1beta1::EchoResponse]
          #
          # @raise [::GRPC::BadStatus] if the RPC is aborted.
          #
          # @example Basic example
          #   require "google/showcase/v1beta1"
          #
          #   # Create a client object. The client can be reused for multiple calls.
          #   client = Google::Showcase::V1beta1::Echo::Client.new
          #
          #   # Create a request. To set request fields, pass in keyword arguments.
          #   request = Google::Showcase::V1beta1::EchoRequest.new
          #
          #   # Call the echo method.
          #   result = client.echo request
          #
          #   # The returned object is of type Google::Showcase::V1beta1::EchoResponse.
          #   p result
          #
          def echo request, options = nil
            raise ::ArgumentError, "request must be provided" if request.nil?

            request = ::Gapic::Protobuf.coerce request, to: ::Google::Showcase::V1beta1::EchoRequest

            # Converts hash and nil to an options object
            options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

            # Customize the options with defaults
            metadata = @config.rpcs.echo.metadata.to_h

            # Set x-goog-api-client and x-goog-user-project headers
            metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
              lib_name: @config.lib_name, lib_version: @config.lib_version,
              gapic_version: ::Google::Showcase::VERSION
            metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

            options.apply_defaults timeout:      @config.rpcs.echo.timeout,
                                   metadata:     metadata,
                                   retry_policy: @config.rpcs.echo.retry_policy

            options.apply_defaults timeout:      @config.timeout,
                                   metadata:     @config.metadata,
                                   retry_policy: @config.retry_policy

            @echo_stub.call_rpc :echo, request, options: options do |response, operation|
              yield response, operation if block_given?
              return response
            end
          end

          ##
          # This method split the given content into words and will pass each word back
          # through the stream. This method showcases server-side streaming rpcs.
          #
          # @overload expand(request, options = nil)
          #   Pass arguments to `expand` via a request object, either of type
          #   {::Google::Showcase::V1beta1::ExpandRequest} or an equivalent Hash.
          #
          #   @param request [::Google::Showcase::V1beta1::ExpandRequest, ::Hash]
          #     A request object representing the call parameters. Required. To specify no
          #     parameters, or to keep all the default parameter values, pass an empty Hash.
          #   @param options [::Gapic::CallOptions, ::Hash]
          #     Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
          #
          # @overload expand(content: nil, error: nil)
          #   Pass arguments to `expand` via keyword arguments. Note that at
          #   least one keyword argument is required. To specify no parameters, or to keep all
          #   the default parameter values, pass an empty Hash as a request object (see above).
          #
          #   @param content [::String]
          #     The content that will be split into words and returned on the stream.
          #   @param error [::Google::Rpc::Status, ::Hash]
          #     The error that is thrown after all words are sent on the stream.
          #
          # @yield [response, operation] Access the result along with the RPC operation
          # @yieldparam response [::Enumerable<::Google::Showcase::V1beta1::EchoResponse>]
          # @yieldparam operation [::GRPC::ActiveCall::Operation]
          #
          # @return [::Enumerable<::Google::Showcase::V1beta1::EchoResponse>]
          #
          # @raise [::GRPC::BadStatus] if the RPC is aborted.
          #
          # @example Basic example
          #   require "google/showcase/v1beta1"
          #
          #   # Create a client object. The client can be reused for multiple calls.
          #   client = Google::Showcase::V1beta1::Echo::Client.new
          #
          #   # Create a request. To set request fields, pass in keyword arguments.
          #   request = Google::Showcase::V1beta1::ExpandRequest.new
          #
          #   # Call the expand method.
          #   result = client.expand request
          #
          #   # The returned object is a streamed enumerable yielding elements of
          #   # type ::Google::Showcase::V1beta1::EchoResponse.
          #   result.each do |response|
          #     p response
          #   end
          #
          def expand request, options = nil
            raise ::ArgumentError, "request must be provided" if request.nil?

            request = ::Gapic::Protobuf.coerce request, to: ::Google::Showcase::V1beta1::ExpandRequest

            # Converts hash and nil to an options object
            options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

            # Customize the options with defaults
            metadata = @config.rpcs.expand.metadata.to_h

            # Set x-goog-api-client and x-goog-user-project headers
            metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
              lib_name: @config.lib_name, lib_version: @config.lib_version,
              gapic_version: ::Google::Showcase::VERSION
            metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

            options.apply_defaults timeout:      @config.rpcs.expand.timeout,
                                   metadata:     metadata,
                                   retry_policy: @config.rpcs.expand.retry_policy

            options.apply_defaults timeout:      @config.timeout,
                                   metadata:     @config.metadata,
                                   retry_policy: @config.retry_policy

            @echo_stub.call_rpc :expand, request, options: options do |response, operation|
              yield response, operation if block_given?
              return response
            end
          end

          ##
          # This method will collect the words given to it. When the stream is closed
          # by the client, this method will return the a concatenation of the strings
          # passed to it. This method showcases client-side streaming rpcs.
          #
          # @param request [::Gapic::StreamInput, ::Enumerable<::Google::Showcase::V1beta1::EchoRequest, ::Hash>]
          #   An enumerable of {::Google::Showcase::V1beta1::EchoRequest} instances.
          # @param options [::Gapic::CallOptions, ::Hash]
          #   Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
          #
          # @yield [response, operation] Access the result along with the RPC operation
          # @yieldparam response [::Google::Showcase::V1beta1::EchoResponse]
          # @yieldparam operation [::GRPC::ActiveCall::Operation]
          #
          # @return [::Google::Showcase::V1beta1::EchoResponse]
          #
          # @raise [::GRPC::BadStatus] if the RPC is aborted.
          #
          # @example Basic example
          #   require "google/showcase/v1beta1"
          #
          #   # Create a client object. The client can be reused for multiple calls.
          #   client = Google::Showcase::V1beta1::Echo::Client.new
          #
          #   # Create a stream of requests, as an Enumerator.
          #   # For each request, pass in keyword arguments to set fields.
          #   request = [
          #     Google::Showcase::V1beta1::EchoRequest.new,
          #     Google::Showcase::V1beta1::EchoRequest.new
          #   ].to_enum
          #
          #   # Call the collect method.
          #   result = client.collect request
          #
          #   # The returned object is of type Google::Showcase::V1beta1::EchoResponse.
          #   p result
          #
          def collect request, options = nil
            unless request.is_a? ::Enumerable
              raise ::ArgumentError, "request must be an Enumerable" unless request.respond_to? :to_enum
              request = request.to_enum
            end

            request = request.lazy.map do |req|
              ::Gapic::Protobuf.coerce req, to: ::Google::Showcase::V1beta1::EchoRequest
            end

            # Converts hash and nil to an options object
            options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

            # Customize the options with defaults
            metadata = @config.rpcs.collect.metadata.to_h

            # Set x-goog-api-client and x-goog-user-project headers
            metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
              lib_name: @config.lib_name, lib_version: @config.lib_version,
              gapic_version: ::Google::Showcase::VERSION
            metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

            options.apply_defaults timeout:      @config.rpcs.collect.timeout,
                                   metadata:     metadata,
                                   retry_policy: @config.rpcs.collect.retry_policy

            options.apply_defaults timeout:      @config.timeout,
                                   metadata:     @config.metadata,
                                   retry_policy: @config.retry_policy

            @echo_stub.call_rpc :collect, request, options: options do |response, operation|
              yield response, operation if block_given?
              return response
            end
          end

          ##
          # This method, upon receiving a request on the stream, the same content will
          # be passed  back on the stream. This method showcases bidirectional
          # streaming rpcs.
          #
          # @param request [::Gapic::StreamInput, ::Enumerable<::Google::Showcase::V1beta1::EchoRequest, ::Hash>]
          #   An enumerable of {::Google::Showcase::V1beta1::EchoRequest} instances.
          # @param options [::Gapic::CallOptions, ::Hash]
          #   Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
          #
          # @yield [response, operation] Access the result along with the RPC operation
          # @yieldparam response [::Enumerable<::Google::Showcase::V1beta1::EchoResponse>]
          # @yieldparam operation [::GRPC::ActiveCall::Operation]
          #
          # @return [::Enumerable<::Google::Showcase::V1beta1::EchoResponse>]
          #
          # @raise [::GRPC::BadStatus] if the RPC is aborted.
          #
          # @example Basic example
          #   require "google/showcase/v1beta1"
          #
          #   # Create a client object. The client can be reused for multiple calls.
          #   client = Google::Showcase::V1beta1::Echo::Client.new
          #
          #   # Create an input stream
          #   input = Gapic::StreamInput.new
          #
          #   # Call the chat method to start streaming.
          #   output = client.chat input
          #
          #   # Send requests on the stream. For each request, pass in keyword
          #   # arguments to set fields. Be sure to close the stream when done.
          #   input << Google::Showcase::V1beta1::EchoRequest.new
          #   input << Google::Showcase::V1beta1::EchoRequest.new
          #   input.close
          #
          #   # Handle streamed responses. These may be interleaved with inputs.
          #   # Each response is of type ::Google::Showcase::V1beta1::EchoResponse.
          #   output.each do |response|
          #     p response
          #   end
          #
          def chat request, options = nil
            unless request.is_a? ::Enumerable
              raise ::ArgumentError, "request must be an Enumerable" unless request.respond_to? :to_enum
              request = request.to_enum
            end

            request = request.lazy.map do |req|
              ::Gapic::Protobuf.coerce req, to: ::Google::Showcase::V1beta1::EchoRequest
            end

            # Converts hash and nil to an options object
            options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

            # Customize the options with defaults
            metadata = @config.rpcs.chat.metadata.to_h

            # Set x-goog-api-client and x-goog-user-project headers
            metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
              lib_name: @config.lib_name, lib_version: @config.lib_version,
              gapic_version: ::Google::Showcase::VERSION
            metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

            options.apply_defaults timeout:      @config.rpcs.chat.timeout,
                                   metadata:     metadata,
                                   retry_policy: @config.rpcs.chat.retry_policy

            options.apply_defaults timeout:      @config.timeout,
                                   metadata:     @config.metadata,
                                   retry_policy: @config.retry_policy

            @echo_stub.call_rpc :chat, request, options: options do |response, operation|
              yield response, operation if block_given?
              return response
            end
          end

          ##
          # This is similar to the Expand method but instead of returning a stream of
          # expanded words, this method returns a paged list of expanded words.
          #
          # @overload paged_expand(request, options = nil)
          #   Pass arguments to `paged_expand` via a request object, either of type
          #   {::Google::Showcase::V1beta1::PagedExpandRequest} or an equivalent Hash.
          #
          #   @param request [::Google::Showcase::V1beta1::PagedExpandRequest, ::Hash]
          #     A request object representing the call parameters. Required. To specify no
          #     parameters, or to keep all the default parameter values, pass an empty Hash.
          #   @param options [::Gapic::CallOptions, ::Hash]
          #     Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
          #
          # @overload paged_expand(content: nil, page_size: nil, page_token: nil)
          #   Pass arguments to `paged_expand` via keyword arguments. Note that at
          #   least one keyword argument is required. To specify no parameters, or to keep all
          #   the default parameter values, pass an empty Hash as a request object (see above).
          #
          #   @param content [::String]
          #     The string to expand.
          #   @param page_size [::Integer]
          #     The amount of words to returned in each page.
          #   @param page_token [::String]
          #     The position of the page to be returned.
          #
          # @yield [response, operation] Access the result along with the RPC operation
          # @yieldparam response [::Gapic::PagedEnumerable<::Google::Showcase::V1beta1::EchoResponse>]
          # @yieldparam operation [::GRPC::ActiveCall::Operation]
          #
          # @return [::Gapic::PagedEnumerable<::Google::Showcase::V1beta1::EchoResponse>]
          #
          # @raise [::GRPC::BadStatus] if the RPC is aborted.
          #
          # @example Basic example
          #   require "google/showcase/v1beta1"
          #
          #   # Create a client object. The client can be reused for multiple calls.
          #   client = Google::Showcase::V1beta1::Echo::Client.new
          #
          #   # Create a request. To set request fields, pass in keyword arguments.
          #   request = Google::Showcase::V1beta1::PagedExpandRequest.new
          #
          #   # Call the paged_expand method.
          #   result = client.paged_expand request
          #
          #   # The returned object is of type Gapic::PagedEnumerable. You can
          #   # iterate over all elements by calling #each, and the enumerable
          #   # will lazily make API calls to fetch subsequent pages. Other
          #   # methods are also available for managing paging directly.
          #   result.each do |response|
          #     # Each element is of type ::Google::Showcase::V1beta1::EchoResponse.
          #     p response
          #   end
          #
          def paged_expand request, options = nil
            raise ::ArgumentError, "request must be provided" if request.nil?

            request = ::Gapic::Protobuf.coerce request, to: ::Google::Showcase::V1beta1::PagedExpandRequest

            # Converts hash and nil to an options object
            options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

            # Customize the options with defaults
            metadata = @config.rpcs.paged_expand.metadata.to_h

            # Set x-goog-api-client and x-goog-user-project headers
            metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
              lib_name: @config.lib_name, lib_version: @config.lib_version,
              gapic_version: ::Google::Showcase::VERSION
            metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

            options.apply_defaults timeout:      @config.rpcs.paged_expand.timeout,
                                   metadata:     metadata,
                                   retry_policy: @config.rpcs.paged_expand.retry_policy

            options.apply_defaults timeout:      @config.timeout,
                                   metadata:     @config.metadata,
                                   retry_policy: @config.retry_policy

            @echo_stub.call_rpc :paged_expand, request, options: options do |response, operation|
              response = ::Gapic::PagedEnumerable.new @echo_stub, :paged_expand, request, response, operation, options
              yield response, operation if block_given?
              return response
            end
          end

          ##
          # This method will wait the requested amount of and then return.
          # This method showcases how a client handles a request timing out.
          #
          # @overload wait(request, options = nil)
          #   Pass arguments to `wait` via a request object, either of type
          #   {::Google::Showcase::V1beta1::WaitRequest} or an equivalent Hash.
          #
          #   @param request [::Google::Showcase::V1beta1::WaitRequest, ::Hash]
          #     A request object representing the call parameters. Required. To specify no
          #     parameters, or to keep all the default parameter values, pass an empty Hash.
          #   @param options [::Gapic::CallOptions, ::Hash]
          #     Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
          #
          # @overload wait(end_time: nil, ttl: nil, error: nil, success: nil)
          #   Pass arguments to `wait` via keyword arguments. Note that at
          #   least one keyword argument is required. To specify no parameters, or to keep all
          #   the default parameter values, pass an empty Hash as a request object (see above).
          #
          #   @param end_time [::Google::Protobuf::Timestamp, ::Hash]
          #     The time that this operation will complete.
          #   @param ttl [::Google::Protobuf::Duration, ::Hash]
          #     The duration of this operation.
          #   @param error [::Google::Rpc::Status, ::Hash]
          #     The error that will be returned by the server. If this code is specified
          #     to be the OK rpc code, an empty response will be returned.
          #   @param success [::Google::Showcase::V1beta1::WaitResponse, ::Hash]
          #     The response to be returned on operation completion.
          #
          # @yield [response, operation] Access the result along with the RPC operation
          # @yieldparam response [::Gapic::Operation]
          # @yieldparam operation [::GRPC::ActiveCall::Operation]
          #
          # @return [::Gapic::Operation]
          #
          # @raise [::GRPC::BadStatus] if the RPC is aborted.
          #
          # @example Basic example
          #   require "google/showcase/v1beta1"
          #
          #   # Create a client object. The client can be reused for multiple calls.
          #   client = Google::Showcase::V1beta1::Echo::Client.new
          #
          #   # Create a request. To set request fields, pass in keyword arguments.
          #   request = Google::Showcase::V1beta1::WaitRequest.new
          #
          #   # Call the wait method.
          #   result = client.wait request
          #
          #   # The returned object is of type Gapic::Operation. You can use this
          #   # object to check the status of an operation, cancel it, or wait
          #   # for results. Here is how to block until completion:
          #   result.wait_until_done! timeout: 60
          #   if result.response?
          #     p result.response
          #   else
          #     puts "Error!"
          #   end
          #
          def wait request, options = nil
            raise ::ArgumentError, "request must be provided" if request.nil?

            request = ::Gapic::Protobuf.coerce request, to: ::Google::Showcase::V1beta1::WaitRequest

            # Converts hash and nil to an options object
            options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

            # Customize the options with defaults
            metadata = @config.rpcs.wait.metadata.to_h

            # Set x-goog-api-client and x-goog-user-project headers
            metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
              lib_name: @config.lib_name, lib_version: @config.lib_version,
              gapic_version: ::Google::Showcase::VERSION
            metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

            options.apply_defaults timeout:      @config.rpcs.wait.timeout,
                                   metadata:     metadata,
                                   retry_policy: @config.rpcs.wait.retry_policy

            options.apply_defaults timeout:      @config.timeout,
                                   metadata:     @config.metadata,
                                   retry_policy: @config.retry_policy

            @echo_stub.call_rpc :wait, request, options: options do |response, operation|
              response = ::Gapic::Operation.new response, @operations_client, options: options
              yield response, operation if block_given?
              return response
            end
          end

          ##
          # This method will block (wait) for the requested amount of time
          # and then return the response or error.
          # This method showcases how a client handles delays or retries.
          #
          # @overload block(request, options = nil)
          #   Pass arguments to `block` via a request object, either of type
          #   {::Google::Showcase::V1beta1::BlockRequest} or an equivalent Hash.
          #
          #   @param request [::Google::Showcase::V1beta1::BlockRequest, ::Hash]
          #     A request object representing the call parameters. Required. To specify no
          #     parameters, or to keep all the default parameter values, pass an empty Hash.
          #   @param options [::Gapic::CallOptions, ::Hash]
          #     Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
          #
          # @overload block(response_delay: nil, error: nil, success: nil)
          #   Pass arguments to `block` via keyword arguments. Note that at
          #   least one keyword argument is required. To specify no parameters, or to keep all
          #   the default parameter values, pass an empty Hash as a request object (see above).
          #
          #   @param response_delay [::Google::Protobuf::Duration, ::Hash]
          #     The amount of time to block before returning a response.
          #   @param error [::Google::Rpc::Status, ::Hash]
          #     The error that will be returned by the server. If this code is specified
          #     to be the OK rpc code, an empty response will be returned.
          #   @param success [::Google::Showcase::V1beta1::BlockResponse, ::Hash]
          #     The response to be returned that will signify successful method call.
          #
          # @yield [response, operation] Access the result along with the RPC operation
          # @yieldparam response [::Google::Showcase::V1beta1::BlockResponse]
          # @yieldparam operation [::GRPC::ActiveCall::Operation]
          #
          # @return [::Google::Showcase::V1beta1::BlockResponse]
          #
          # @raise [::GRPC::BadStatus] if the RPC is aborted.
          #
          # @example Basic example
          #   require "google/showcase/v1beta1"
          #
          #   # Create a client object. The client can be reused for multiple calls.
          #   client = Google::Showcase::V1beta1::Echo::Client.new
          #
          #   # Create a request. To set request fields, pass in keyword arguments.
          #   request = Google::Showcase::V1beta1::BlockRequest.new
          #
          #   # Call the block method.
          #   result = client.block request
          #
          #   # The returned object is of type Google::Showcase::V1beta1::BlockResponse.
          #   p result
          #
          def block request, options = nil
            raise ::ArgumentError, "request must be provided" if request.nil?

            request = ::Gapic::Protobuf.coerce request, to: ::Google::Showcase::V1beta1::BlockRequest

            # Converts hash and nil to an options object
            options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

            # Customize the options with defaults
            metadata = @config.rpcs.block.metadata.to_h

            # Set x-goog-api-client and x-goog-user-project headers
            metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
              lib_name: @config.lib_name, lib_version: @config.lib_version,
              gapic_version: ::Google::Showcase::VERSION
            metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

            options.apply_defaults timeout:      @config.rpcs.block.timeout,
                                   metadata:     metadata,
                                   retry_policy: @config.rpcs.block.retry_policy

            options.apply_defaults timeout:      @config.timeout,
                                   metadata:     @config.metadata,
                                   retry_policy: @config.retry_policy

            @echo_stub.call_rpc :block, request, options: options do |response, operation|
              yield response, operation if block_given?
              return response
            end
          end

          ##
          # Configuration class for the Echo API.
          #
          # This class represents the configuration for Echo,
          # providing control over timeouts, retry behavior, logging, transport
          # parameters, and other low-level controls. Certain parameters can also be
          # applied individually to specific RPCs. See
          # {::Google::Showcase::V1beta1::Echo::Client::Configuration::Rpcs}
          # for a list of RPCs that can be configured independently.
          #
          # Configuration can be applied globally to all clients, or to a single client
          # on construction.
          #
          # @example
          #
          #   # Modify the global config, setting the timeout for
          #   # echo to 20 seconds,
          #   # and all remaining timeouts to 10 seconds.
          #   ::Google::Showcase::V1beta1::Echo::Client.configure do |config|
          #     config.timeout = 10.0
          #     config.rpcs.echo.timeout = 20.0
          #   end
          #
          #   # Apply the above configuration only to a new client.
          #   client = ::Google::Showcase::V1beta1::Echo::Client.new do |config|
          #     config.timeout = 10.0
          #     config.rpcs.echo.timeout = 20.0
          #   end
          #
          # @!attribute [rw] endpoint
          #   The hostname or hostname:port of the service endpoint.
          #   Defaults to `"localhost:7469"`.
          #   @return [::String]
          # @!attribute [rw] credentials
          #   Credentials to send with calls. You may provide any of the following types:
          #    *  (`String`) The path to a service account key file in JSON format
          #    *  (`Hash`) A service account key as a Hash
          #    *  (`Google::Auth::Credentials`) A googleauth credentials object
          #       (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
          #    *  (`Signet::OAuth2::Client`) A signet oauth2 client object
          #       (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
          #    *  (`GRPC::Core::Channel`) a gRPC channel with included credentials
          #    *  (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
          #    *  (`nil`) indicating no credentials
          #   @return [::Object]
          # @!attribute [rw] scope
          #   The OAuth scopes
          #   @return [::Array<::String>]
          # @!attribute [rw] lib_name
          #   The library name as recorded in instrumentation and logging
          #   @return [::String]
          # @!attribute [rw] lib_version
          #   The library version as recorded in instrumentation and logging
          #   @return [::String]
          # @!attribute [rw] channel_args
          #   Extra parameters passed to the gRPC channel. Note: this is ignored if a
          #   `GRPC::Core::Channel` object is provided as the credential.
          #   @return [::Hash]
          # @!attribute [rw] interceptors
          #   An array of interceptors that are run before calls are executed.
          #   @return [::Array<::GRPC::ClientInterceptor>]
          # @!attribute [rw] timeout
          #   The call timeout in seconds.
          #   @return [::Numeric]
          # @!attribute [rw] metadata
          #   Additional gRPC headers to be sent with the call.
          #   @return [::Hash{::Symbol=>::String}]
          # @!attribute [rw] retry_policy
          #   The retry policy. The value is a hash with the following keys:
          #    *  `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
          #    *  `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
          #    *  `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
          #    *  `:retry_codes` (*type:* `Array<String>`) - The error codes that should
          #       trigger a retry.
          #   @return [::Hash]
          # @!attribute [rw] quota_project
          #   A separate project against which to charge quota.
          #   @return [::String]
          #
          class Configuration
            extend ::Gapic::Config

            config_attr :endpoint,      "localhost:7469", ::String
            config_attr :credentials,   nil do |value|
              allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
              allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
              allowed.any? { |klass| klass === value }
            end
            config_attr :scope,         nil, ::String, ::Array, nil
            config_attr :lib_name,      nil, ::String, nil
            config_attr :lib_version,   nil, ::String, nil
            config_attr(:channel_args,  { "grpc.service_config_disable_resolution" => 1 }, ::Hash, nil)
            config_attr :interceptors,  nil, ::Array, nil
            config_attr :timeout,       nil, ::Numeric, nil
            config_attr :metadata,      nil, ::Hash, nil
            config_attr :retry_policy,  nil, ::Hash, ::Proc, nil
            config_attr :quota_project, nil, ::String, nil

            # @private
            def initialize parent_config = nil
              @parent_config = parent_config unless parent_config.nil?

              yield self if block_given?
            end

            ##
            # Configurations for individual RPCs
            # @return [Rpcs]
            #
            def rpcs
              @rpcs ||= begin
                parent_rpcs = nil
                parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
                Rpcs.new parent_rpcs
              end
            end

            ##
            # Configuration RPC class for the Echo API.
            #
            # Includes fields providing the configuration for each RPC in this service.
            # Each configuration object is of type `Gapic::Config::Method` and includes
            # the following configuration fields:
            #
            #  *  `timeout` (*type:* `Numeric`) - The call timeout in seconds
            #  *  `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
            #  *  `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
            #     include the following keys:
            #      *  `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
            #      *  `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
            #      *  `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
            #      *  `:retry_codes` (*type:* `Array<String>`) - The error codes that should
            #         trigger a retry.
            #
            class Rpcs
              ##
              # RPC-specific configuration for `echo`
              # @return [::Gapic::Config::Method]
              #
              attr_reader :echo
              ##
              # RPC-specific configuration for `expand`
              # @return [::Gapic::Config::Method]
              #
              attr_reader :expand
              ##
              # RPC-specific configuration for `collect`
              # @return [::Gapic::Config::Method]
              #
              attr_reader :collect
              ##
              # RPC-specific configuration for `chat`
              # @return [::Gapic::Config::Method]
              #
              attr_reader :chat
              ##
              # RPC-specific configuration for `paged_expand`
              # @return [::Gapic::Config::Method]
              #
              attr_reader :paged_expand
              ##
              # RPC-specific configuration for `wait`
              # @return [::Gapic::Config::Method]
              #
              attr_reader :wait
              ##
              # RPC-specific configuration for `block`
              # @return [::Gapic::Config::Method]
              #
              attr_reader :block

              # @private
              def initialize parent_rpcs = nil
                echo_config = parent_rpcs.echo if parent_rpcs.respond_to? :echo
                @echo = ::Gapic::Config::Method.new echo_config
                expand_config = parent_rpcs.expand if parent_rpcs.respond_to? :expand
                @expand = ::Gapic::Config::Method.new expand_config
                collect_config = parent_rpcs.collect if parent_rpcs.respond_to? :collect
                @collect = ::Gapic::Config::Method.new collect_config
                chat_config = parent_rpcs.chat if parent_rpcs.respond_to? :chat
                @chat = ::Gapic::Config::Method.new chat_config
                paged_expand_config = parent_rpcs.paged_expand if parent_rpcs.respond_to? :paged_expand
                @paged_expand = ::Gapic::Config::Method.new paged_expand_config
                wait_config = parent_rpcs.wait if parent_rpcs.respond_to? :wait
                @wait = ::Gapic::Config::Method.new wait_config
                block_config = parent_rpcs.block if parent_rpcs.respond_to? :block
                @block = ::Gapic::Config::Method.new block_config

                yield self if block_given?
              end
            end
          end
        end
      end
    end
  end
end
