# frozen_string_literal: true

# Copyright 2020 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.

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

require "google/cloud/errors"
require "google/api/servicemanagement/v1/servicemanager_pb"

module Google
  module Cloud
    module ServiceManagement
      module V1
        module ServiceManager
          ##
          # Client for the ServiceManager service.
          #
          # [Google Service Management
          # API](https://cloud.google.com/service-infrastructure/docs/overview)
          #
          class Client
            # @private
            attr_reader :service_manager_stub

            ##
            # Configure the ServiceManager Client class.
            #
            # See {::Google::Cloud::ServiceManagement::V1::ServiceManager::Client::Configuration}
            # for a description of the configuration fields.
            #
            # @example
            #
            #   # Modify the configuration for all ServiceManager clients
            #   ::Google::Cloud::ServiceManagement::V1::ServiceManager::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
                namespace = ["Google", "Cloud", "ServiceManagement", "V1"]
                parent_config = while namespace.any?
                                  parent_name = namespace.join "::"
                                  parent_const = const_get parent_name
                                  break parent_const.configure if parent_const.respond_to? :configure
                                  namespace.pop
                                end
                default_config = Client::Configuration.new parent_config

                default_config.timeout = 10.0

                default_config
              end
              yield @configure if block_given?
              @configure
            end

            ##
            # Configure the ServiceManager 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::Cloud::ServiceManagement::V1::ServiceManager::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 ServiceManager client object.
            #
            # @example
            #
            #   # Create a client using the default configuration
            #   client = ::Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a client using a custom configuration
            #   client = ::Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new do |config|
            #     config.timeout = 10.0
            #   end
            #
            # @yield [config] Configure the ServiceManager 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/api/servicemanagement/v1/servicemanager_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

              @service_manager_stub = ::Gapic::ServiceStub.new(
                ::Google::Cloud::ServiceManagement::V1::ServiceManager::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::Cloud::ServiceManagement::V1::ServiceManager::Operations]
            #
            attr_reader :operations_client

            # Service calls

            ##
            # Lists managed services.
            #
            # Returns all public services. For authenticated users, also returns all
            # services the calling user has "servicemanagement.services.get" permission
            # for.
            #
            # @overload list_services(request, options = nil)
            #   Pass arguments to `list_services` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::ListServicesRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::ListServicesRequest, ::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 list_services(producer_project_id: nil, page_size: nil, page_token: nil, consumer_id: nil)
            #   Pass arguments to `list_services` 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 producer_project_id [::String]
            #     Include services produced by the specified project.
            #   @param page_size [::Integer]
            #     The max number of items to include in the response list. Page size is 50
            #     if not specified. Maximum value is 100.
            #   @param page_token [::String]
            #     Token identifying which result to start with; returned by a previous list
            #     call.
            #   @param consumer_id [::String]
            #     Include services consumed by the specified consumer.
            #
            #     The Google Service Management implementation accepts the following
            #     forms:
            #     - project:<project_id>
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Gapic::PagedEnumerable<::Google::Cloud::ServiceManagement::V1::ManagedService>]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Gapic::PagedEnumerable<::Google::Cloud::ServiceManagement::V1::ManagedService>]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::ListServicesRequest.new
            #
            #   # Call the list_services method.
            #   result = client.list_services 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::Cloud::ServiceManagement::V1::ManagedService.
            #     p response
            #   end
            #
            def list_services request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::ListServicesRequest

              # 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.list_services.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

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

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

              @service_manager_stub.call_rpc :list_services, request, options: options do |response, operation|
                response = ::Gapic::PagedEnumerable.new @service_manager_stub, :list_services, request, response, operation, options
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Gets a managed service. Authentication is required unless the service is
            # public.
            #
            # @overload get_service(request, options = nil)
            #   Pass arguments to `get_service` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::GetServiceRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::GetServiceRequest, ::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 get_service(service_name: nil)
            #   Pass arguments to `get_service` 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 service_name [::String]
            #     Required. The name of the service.  See the `ServiceManager` overview for
            #     naming requirements.  For example: `example.googleapis.com`.
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Google::Cloud::ServiceManagement::V1::ManagedService]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Google::Cloud::ServiceManagement::V1::ManagedService]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::GetServiceRequest.new
            #
            #   # Call the get_service method.
            #   result = client.get_service request
            #
            #   # The returned object is of type Google::Cloud::ServiceManagement::V1::ManagedService.
            #   p result
            #
            def get_service request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::GetServiceRequest

              # 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.get_service.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

              header_params = {}
              if request.service_name
                header_params["service_name"] = request.service_name
              end

              request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
              metadata[:"x-goog-request-params"] ||= request_params_header

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

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

              @service_manager_stub.call_rpc :get_service, request, options: options do |response, operation|
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Creates a new managed service.
            #
            # A managed service is immutable, and is subject to mandatory 30-day
            # data retention. You cannot move a service or recreate it within 30 days
            # after deletion.
            #
            # One producer project can own no more than 500 services. For security and
            # reliability purposes, a production service should be hosted in a
            # dedicated producer project.
            #
            # Operation<response: ManagedService>
            #
            # @overload create_service(request, options = nil)
            #   Pass arguments to `create_service` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::CreateServiceRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::CreateServiceRequest, ::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 create_service(service: nil)
            #   Pass arguments to `create_service` 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 service [::Google::Cloud::ServiceManagement::V1::ManagedService, ::Hash]
            #     Required. Initial values for the service resource.
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Gapic::Operation]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Gapic::Operation]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::CreateServiceRequest.new
            #
            #   # Call the create_service method.
            #   result = client.create_service 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 create_service request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::CreateServiceRequest

              # 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.create_service.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

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

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

              @service_manager_stub.call_rpc :create_service, request, options: options do |response, operation|
                response = ::Gapic::Operation.new response, @operations_client, options: options
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Deletes a managed service. This method will change the service to the
            # `Soft-Delete` state for 30 days. Within this period, service producers may
            # call
            # {::Google::Cloud::ServiceManagement::V1::ServiceManager::Client#undelete_service UndeleteService}
            # to restore the service. After 30 days, the service will be permanently
            # deleted.
            #
            # Operation<response: google.protobuf.Empty>
            #
            # @overload delete_service(request, options = nil)
            #   Pass arguments to `delete_service` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::DeleteServiceRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::DeleteServiceRequest, ::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 delete_service(service_name: nil)
            #   Pass arguments to `delete_service` 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 service_name [::String]
            #     Required. The name of the service.  See the
            #     [overview](https://cloud.google.com/service-infrastructure/docs/overview) for naming requirements.  For
            #     example: `example.googleapis.com`.
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Gapic::Operation]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Gapic::Operation]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::DeleteServiceRequest.new
            #
            #   # Call the delete_service method.
            #   result = client.delete_service 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 delete_service request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::DeleteServiceRequest

              # 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.delete_service.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

              header_params = {}
              if request.service_name
                header_params["service_name"] = request.service_name
              end

              request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
              metadata[:"x-goog-request-params"] ||= request_params_header

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

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

              @service_manager_stub.call_rpc :delete_service, request, options: options do |response, operation|
                response = ::Gapic::Operation.new response, @operations_client, options: options
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Revives a previously deleted managed service. The method restores the
            # service using the configuration at the time the service was deleted.
            # The target service must exist and must have been deleted within the
            # last 30 days.
            #
            # Operation<response: UndeleteServiceResponse>
            #
            # @overload undelete_service(request, options = nil)
            #   Pass arguments to `undelete_service` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::UndeleteServiceRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::UndeleteServiceRequest, ::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 undelete_service(service_name: nil)
            #   Pass arguments to `undelete_service` 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 service_name [::String]
            #     Required. The name of the service. See the
            #     [overview](https://cloud.google.com/service-infrastructure/docs/overview) for naming requirements. For
            #     example: `example.googleapis.com`.
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Gapic::Operation]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Gapic::Operation]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::UndeleteServiceRequest.new
            #
            #   # Call the undelete_service method.
            #   result = client.undelete_service 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 undelete_service request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::UndeleteServiceRequest

              # 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.undelete_service.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

              header_params = {}
              if request.service_name
                header_params["service_name"] = request.service_name
              end

              request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
              metadata[:"x-goog-request-params"] ||= request_params_header

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

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

              @service_manager_stub.call_rpc :undelete_service, request, options: options do |response, operation|
                response = ::Gapic::Operation.new response, @operations_client, options: options
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Lists the history of the service configuration for a managed service,
            # from the newest to the oldest.
            #
            # @overload list_service_configs(request, options = nil)
            #   Pass arguments to `list_service_configs` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::ListServiceConfigsRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::ListServiceConfigsRequest, ::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 list_service_configs(service_name: nil, page_token: nil, page_size: nil)
            #   Pass arguments to `list_service_configs` 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 service_name [::String]
            #     Required. The name of the service.  See the
            #     [overview](https://cloud.google.com/service-infrastructure/docs/overview) for naming requirements.  For
            #     example: `example.googleapis.com`.
            #   @param page_token [::String]
            #     The token of the page to retrieve.
            #   @param page_size [::Integer]
            #     The max number of items to include in the response list. Page size is 50
            #     if not specified. Maximum value is 100.
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Gapic::PagedEnumerable<::Google::Api::Service>]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Gapic::PagedEnumerable<::Google::Api::Service>]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::ListServiceConfigsRequest.new
            #
            #   # Call the list_service_configs method.
            #   result = client.list_service_configs 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::Api::Service.
            #     p response
            #   end
            #
            def list_service_configs request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::ListServiceConfigsRequest

              # 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.list_service_configs.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

              header_params = {}
              if request.service_name
                header_params["service_name"] = request.service_name
              end

              request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
              metadata[:"x-goog-request-params"] ||= request_params_header

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

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

              @service_manager_stub.call_rpc :list_service_configs, request, options: options do |response, operation|
                response = ::Gapic::PagedEnumerable.new @service_manager_stub, :list_service_configs, request, response, operation, options
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Gets a service configuration (version) for a managed service.
            #
            # @overload get_service_config(request, options = nil)
            #   Pass arguments to `get_service_config` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::GetServiceConfigRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::GetServiceConfigRequest, ::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 get_service_config(service_name: nil, config_id: nil, view: nil)
            #   Pass arguments to `get_service_config` 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 service_name [::String]
            #     Required. The name of the service.  See the
            #     [overview](https://cloud.google.com/service-infrastructure/docs/overview) for naming requirements.  For
            #     example: `example.googleapis.com`.
            #   @param config_id [::String]
            #     Required. The id of the service configuration resource.
            #
            #     This field must be specified for the server to return all fields, including
            #     `SourceInfo`.
            #   @param view [::Google::Cloud::ServiceManagement::V1::GetServiceConfigRequest::ConfigView]
            #     Specifies which parts of the Service Config should be returned in the
            #     response.
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Google::Api::Service]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Google::Api::Service]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::GetServiceConfigRequest.new
            #
            #   # Call the get_service_config method.
            #   result = client.get_service_config request
            #
            #   # The returned object is of type Google::Api::Service.
            #   p result
            #
            def get_service_config request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::GetServiceConfigRequest

              # 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.get_service_config.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

              header_params = {}
              if request.service_name
                header_params["service_name"] = request.service_name
              end
              if request.config_id
                header_params["config_id"] = request.config_id
              end

              request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
              metadata[:"x-goog-request-params"] ||= request_params_header

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

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

              @service_manager_stub.call_rpc :get_service_config, request, options: options do |response, operation|
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Creates a new service configuration (version) for a managed service.
            # This method only stores the service configuration. To roll out the service
            # configuration to backend systems please call
            # {::Google::Cloud::ServiceManagement::V1::ServiceManager::Client#create_service_rollout CreateServiceRollout}.
            #
            # Only the 100 most recent service configurations and ones referenced by
            # existing rollouts are kept for each service. The rest will be deleted
            # eventually.
            #
            # @overload create_service_config(request, options = nil)
            #   Pass arguments to `create_service_config` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::CreateServiceConfigRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::CreateServiceConfigRequest, ::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 create_service_config(service_name: nil, service_config: nil)
            #   Pass arguments to `create_service_config` 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 service_name [::String]
            #     Required. The name of the service.  See the
            #     [overview](https://cloud.google.com/service-infrastructure/docs/overview) for naming requirements.  For
            #     example: `example.googleapis.com`.
            #   @param service_config [::Google::Api::Service, ::Hash]
            #     Required. The service configuration resource.
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Google::Api::Service]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Google::Api::Service]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::CreateServiceConfigRequest.new
            #
            #   # Call the create_service_config method.
            #   result = client.create_service_config request
            #
            #   # The returned object is of type Google::Api::Service.
            #   p result
            #
            def create_service_config request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::CreateServiceConfigRequest

              # 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.create_service_config.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

              header_params = {}
              if request.service_name
                header_params["service_name"] = request.service_name
              end

              request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
              metadata[:"x-goog-request-params"] ||= request_params_header

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

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

              @service_manager_stub.call_rpc :create_service_config, request, options: options do |response, operation|
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Creates a new service configuration (version) for a managed service based
            # on
            # user-supplied configuration source files (for example: OpenAPI
            # Specification). This method stores the source configurations as well as the
            # generated service configuration. To rollout the service configuration to
            # other services,
            # please call
            # {::Google::Cloud::ServiceManagement::V1::ServiceManager::Client#create_service_rollout CreateServiceRollout}.
            #
            # Only the 100 most recent configuration sources and ones referenced by
            # existing service configurtions are kept for each service. The rest will be
            # deleted eventually.
            #
            # Operation<response: SubmitConfigSourceResponse>
            #
            # @overload submit_config_source(request, options = nil)
            #   Pass arguments to `submit_config_source` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::SubmitConfigSourceRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::SubmitConfigSourceRequest, ::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 submit_config_source(service_name: nil, config_source: nil, validate_only: nil)
            #   Pass arguments to `submit_config_source` 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 service_name [::String]
            #     Required. The name of the service.  See the
            #     [overview](https://cloud.google.com/service-infrastructure/docs/overview) for naming requirements.  For
            #     example: `example.googleapis.com`.
            #   @param config_source [::Google::Cloud::ServiceManagement::V1::ConfigSource, ::Hash]
            #     Required. The source configuration for the service.
            #   @param validate_only [::Boolean]
            #     Optional. If set, this will result in the generation of a
            #     `google.api.Service` configuration based on the `ConfigSource` provided,
            #     but the generated config and the sources will NOT be persisted.
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Gapic::Operation]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Gapic::Operation]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::SubmitConfigSourceRequest.new
            #
            #   # Call the submit_config_source method.
            #   result = client.submit_config_source 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 submit_config_source request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::SubmitConfigSourceRequest

              # 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.submit_config_source.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

              header_params = {}
              if request.service_name
                header_params["service_name"] = request.service_name
              end

              request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
              metadata[:"x-goog-request-params"] ||= request_params_header

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

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

              @service_manager_stub.call_rpc :submit_config_source, request, options: options do |response, operation|
                response = ::Gapic::Operation.new response, @operations_client, options: options
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Lists the history of the service configuration rollouts for a managed
            # service, from the newest to the oldest.
            #
            # @overload list_service_rollouts(request, options = nil)
            #   Pass arguments to `list_service_rollouts` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::ListServiceRolloutsRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::ListServiceRolloutsRequest, ::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 list_service_rollouts(service_name: nil, page_token: nil, page_size: nil, filter: nil)
            #   Pass arguments to `list_service_rollouts` 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 service_name [::String]
            #     Required. The name of the service.  See the
            #     [overview](https://cloud.google.com/service-infrastructure/docs/overview) for naming requirements.  For
            #     example: `example.googleapis.com`.
            #   @param page_token [::String]
            #     The token of the page to retrieve.
            #   @param page_size [::Integer]
            #     The max number of items to include in the response list. Page size is 50
            #     if not specified. Maximum value is 100.
            #   @param filter [::String]
            #     Required. Use `filter` to return subset of rollouts.
            #     The following filters are supported:
            #       -- To limit the results to only those in
            #          status (google.api.servicemanagement.v1.RolloutStatus) 'SUCCESS',
            #          use filter='status=SUCCESS'
            #       -- To limit the results to those in
            #          status (google.api.servicemanagement.v1.RolloutStatus) 'CANCELLED'
            #          or 'FAILED', use filter='status=CANCELLED OR status=FAILED'
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Gapic::PagedEnumerable<::Google::Cloud::ServiceManagement::V1::Rollout>]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Gapic::PagedEnumerable<::Google::Cloud::ServiceManagement::V1::Rollout>]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::ListServiceRolloutsRequest.new
            #
            #   # Call the list_service_rollouts method.
            #   result = client.list_service_rollouts 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::Cloud::ServiceManagement::V1::Rollout.
            #     p response
            #   end
            #
            def list_service_rollouts request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::ListServiceRolloutsRequest

              # 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.list_service_rollouts.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

              header_params = {}
              if request.service_name
                header_params["service_name"] = request.service_name
              end

              request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
              metadata[:"x-goog-request-params"] ||= request_params_header

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

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

              @service_manager_stub.call_rpc :list_service_rollouts, request, options: options do |response, operation|
                response = ::Gapic::PagedEnumerable.new @service_manager_stub, :list_service_rollouts, request, response, operation, options
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Gets a service configuration
            # {::Google::Cloud::ServiceManagement::V1::Rollout rollout}.
            #
            # @overload get_service_rollout(request, options = nil)
            #   Pass arguments to `get_service_rollout` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::GetServiceRolloutRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::GetServiceRolloutRequest, ::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 get_service_rollout(service_name: nil, rollout_id: nil)
            #   Pass arguments to `get_service_rollout` 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 service_name [::String]
            #     Required. The name of the service.  See the
            #     [overview](https://cloud.google.com/service-infrastructure/docs/overview) for naming requirements.  For
            #     example: `example.googleapis.com`.
            #   @param rollout_id [::String]
            #     Required. The id of the rollout resource.
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Google::Cloud::ServiceManagement::V1::Rollout]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Google::Cloud::ServiceManagement::V1::Rollout]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::GetServiceRolloutRequest.new
            #
            #   # Call the get_service_rollout method.
            #   result = client.get_service_rollout request
            #
            #   # The returned object is of type Google::Cloud::ServiceManagement::V1::Rollout.
            #   p result
            #
            def get_service_rollout request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::GetServiceRolloutRequest

              # 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.get_service_rollout.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

              header_params = {}
              if request.service_name
                header_params["service_name"] = request.service_name
              end
              if request.rollout_id
                header_params["rollout_id"] = request.rollout_id
              end

              request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
              metadata[:"x-goog-request-params"] ||= request_params_header

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

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

              @service_manager_stub.call_rpc :get_service_rollout, request, options: options do |response, operation|
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Creates a new service configuration rollout. Based on rollout, the
            # Google Service Management will roll out the service configurations to
            # different backend services. For example, the logging configuration will be
            # pushed to Google Cloud Logging.
            #
            # Please note that any previous pending and running Rollouts and associated
            # Operations will be automatically cancelled so that the latest Rollout will
            # not be blocked by previous Rollouts.
            #
            # Only the 100 most recent (in any state) and the last 10 successful (if not
            # already part of the set of 100 most recent) rollouts are kept for each
            # service. The rest will be deleted eventually.
            #
            # Operation<response: Rollout>
            #
            # @overload create_service_rollout(request, options = nil)
            #   Pass arguments to `create_service_rollout` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::CreateServiceRolloutRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::CreateServiceRolloutRequest, ::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 create_service_rollout(service_name: nil, rollout: nil)
            #   Pass arguments to `create_service_rollout` 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 service_name [::String]
            #     Required. The name of the service.  See the
            #     [overview](https://cloud.google.com/service-infrastructure/docs/overview) for naming requirements.  For
            #     example: `example.googleapis.com`.
            #   @param rollout [::Google::Cloud::ServiceManagement::V1::Rollout, ::Hash]
            #     Required. The rollout resource. The `service_name` field is output only.
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Gapic::Operation]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Gapic::Operation]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::CreateServiceRolloutRequest.new
            #
            #   # Call the create_service_rollout method.
            #   result = client.create_service_rollout 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 create_service_rollout request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::CreateServiceRolloutRequest

              # 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.create_service_rollout.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

              header_params = {}
              if request.service_name
                header_params["service_name"] = request.service_name
              end

              request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
              metadata[:"x-goog-request-params"] ||= request_params_header

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

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

              @service_manager_stub.call_rpc :create_service_rollout, request, options: options do |response, operation|
                response = ::Gapic::Operation.new response, @operations_client, options: options
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Generates and returns a report (errors, warnings and changes from
            # existing configurations) associated with
            # GenerateConfigReportRequest.new_value
            #
            # If GenerateConfigReportRequest.old_value is specified,
            # GenerateConfigReportRequest will contain a single ChangeReport based on the
            # comparison between GenerateConfigReportRequest.new_value and
            # GenerateConfigReportRequest.old_value.
            # If GenerateConfigReportRequest.old_value is not specified, this method
            # will compare GenerateConfigReportRequest.new_value with the last pushed
            # service configuration.
            #
            # @overload generate_config_report(request, options = nil)
            #   Pass arguments to `generate_config_report` via a request object, either of type
            #   {::Google::Cloud::ServiceManagement::V1::GenerateConfigReportRequest} or an equivalent Hash.
            #
            #   @param request [::Google::Cloud::ServiceManagement::V1::GenerateConfigReportRequest, ::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 generate_config_report(new_config: nil, old_config: nil)
            #   Pass arguments to `generate_config_report` 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 new_config [::Google::Protobuf::Any, ::Hash]
            #     Required. Service configuration for which we want to generate the report.
            #     For this version of API, the supported types are
            #     {::Google::Cloud::ServiceManagement::V1::ConfigRef google.api.servicemanagement.v1.ConfigRef},
            #     {::Google::Cloud::ServiceManagement::V1::ConfigSource google.api.servicemanagement.v1.ConfigSource},
            #     and {::Google::Api::Service google.api.Service}
            #   @param old_config [::Google::Protobuf::Any, ::Hash]
            #     Optional. Service configuration against which the comparison will be done.
            #     For this version of API, the supported types are
            #     {::Google::Cloud::ServiceManagement::V1::ConfigRef google.api.servicemanagement.v1.ConfigRef},
            #     {::Google::Cloud::ServiceManagement::V1::ConfigSource google.api.servicemanagement.v1.ConfigSource},
            #     and {::Google::Api::Service google.api.Service}
            #
            # @yield [response, operation] Access the result along with the RPC operation
            # @yieldparam response [::Google::Cloud::ServiceManagement::V1::GenerateConfigReportResponse]
            # @yieldparam operation [::GRPC::ActiveCall::Operation]
            #
            # @return [::Google::Cloud::ServiceManagement::V1::GenerateConfigReportResponse]
            #
            # @raise [::Google::Cloud::Error] if the RPC is aborted.
            #
            # @example Basic example
            #   require "google/cloud/service_management/v1"
            #
            #   # Create a client object. The client can be reused for multiple calls.
            #   client = Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new
            #
            #   # Create a request. To set request fields, pass in keyword arguments.
            #   request = Google::Cloud::ServiceManagement::V1::GenerateConfigReportRequest.new
            #
            #   # Call the generate_config_report method.
            #   result = client.generate_config_report request
            #
            #   # The returned object is of type Google::Cloud::ServiceManagement::V1::GenerateConfigReportResponse.
            #   p result
            #
            def generate_config_report request, options = nil
              raise ::ArgumentError, "request must be provided" if request.nil?

              request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceManagement::V1::GenerateConfigReportRequest

              # 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.generate_config_report.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::Cloud::ServiceManagement::V1::VERSION
              metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id

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

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

              @service_manager_stub.call_rpc :generate_config_report, request, options: options do |response, operation|
                yield response, operation if block_given?
                return response
              end
            rescue ::GRPC::BadStatus => e
              raise ::Google::Cloud::Error.from_error(e)
            end

            ##
            # Configuration class for the ServiceManager API.
            #
            # This class represents the configuration for ServiceManager,
            # 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::Cloud::ServiceManagement::V1::ServiceManager::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
            #   # list_services to 20 seconds,
            #   # and all remaining timeouts to 10 seconds.
            #   ::Google::Cloud::ServiceManagement::V1::ServiceManager::Client.configure do |config|
            #     config.timeout = 10.0
            #     config.rpcs.list_services.timeout = 20.0
            #   end
            #
            #   # Apply the above configuration only to a new client.
            #   client = ::Google::Cloud::ServiceManagement::V1::ServiceManager::Client.new do |config|
            #     config.timeout = 10.0
            #     config.rpcs.list_services.timeout = 20.0
            #   end
            #
            # @!attribute [rw] endpoint
            #   The hostname or hostname:port of the service endpoint.
            #   Defaults to `"servicemanagement.googleapis.com"`.
            #   @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,      "servicemanagement.googleapis.com", ::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 ServiceManager 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 `list_services`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :list_services
                ##
                # RPC-specific configuration for `get_service`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :get_service
                ##
                # RPC-specific configuration for `create_service`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :create_service
                ##
                # RPC-specific configuration for `delete_service`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :delete_service
                ##
                # RPC-specific configuration for `undelete_service`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :undelete_service
                ##
                # RPC-specific configuration for `list_service_configs`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :list_service_configs
                ##
                # RPC-specific configuration for `get_service_config`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :get_service_config
                ##
                # RPC-specific configuration for `create_service_config`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :create_service_config
                ##
                # RPC-specific configuration for `submit_config_source`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :submit_config_source
                ##
                # RPC-specific configuration for `list_service_rollouts`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :list_service_rollouts
                ##
                # RPC-specific configuration for `get_service_rollout`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :get_service_rollout
                ##
                # RPC-specific configuration for `create_service_rollout`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :create_service_rollout
                ##
                # RPC-specific configuration for `generate_config_report`
                # @return [::Gapic::Config::Method]
                #
                attr_reader :generate_config_report

                # @private
                def initialize parent_rpcs = nil
                  list_services_config = parent_rpcs.list_services if parent_rpcs.respond_to? :list_services
                  @list_services = ::Gapic::Config::Method.new list_services_config
                  get_service_config = parent_rpcs.get_service if parent_rpcs.respond_to? :get_service
                  @get_service = ::Gapic::Config::Method.new get_service_config
                  create_service_config = parent_rpcs.create_service if parent_rpcs.respond_to? :create_service
                  @create_service = ::Gapic::Config::Method.new create_service_config
                  delete_service_config = parent_rpcs.delete_service if parent_rpcs.respond_to? :delete_service
                  @delete_service = ::Gapic::Config::Method.new delete_service_config
                  undelete_service_config = parent_rpcs.undelete_service if parent_rpcs.respond_to? :undelete_service
                  @undelete_service = ::Gapic::Config::Method.new undelete_service_config
                  list_service_configs_config = parent_rpcs.list_service_configs if parent_rpcs.respond_to? :list_service_configs
                  @list_service_configs = ::Gapic::Config::Method.new list_service_configs_config
                  get_service_config_config = parent_rpcs.get_service_config if parent_rpcs.respond_to? :get_service_config
                  @get_service_config = ::Gapic::Config::Method.new get_service_config_config
                  create_service_config_config = parent_rpcs.create_service_config if parent_rpcs.respond_to? :create_service_config
                  @create_service_config = ::Gapic::Config::Method.new create_service_config_config
                  submit_config_source_config = parent_rpcs.submit_config_source if parent_rpcs.respond_to? :submit_config_source
                  @submit_config_source = ::Gapic::Config::Method.new submit_config_source_config
                  list_service_rollouts_config = parent_rpcs.list_service_rollouts if parent_rpcs.respond_to? :list_service_rollouts
                  @list_service_rollouts = ::Gapic::Config::Method.new list_service_rollouts_config
                  get_service_rollout_config = parent_rpcs.get_service_rollout if parent_rpcs.respond_to? :get_service_rollout
                  @get_service_rollout = ::Gapic::Config::Method.new get_service_rollout_config
                  create_service_rollout_config = parent_rpcs.create_service_rollout if parent_rpcs.respond_to? :create_service_rollout
                  @create_service_rollout = ::Gapic::Config::Method.new create_service_rollout_config
                  generate_config_report_config = parent_rpcs.generate_config_report if parent_rpcs.respond_to? :generate_config_report
                  @generate_config_report = ::Gapic::Config::Method.new generate_config_report_config

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