/// <summary>
        ///   Creates the track one Event Hub client instance for inner use, handling any necessary translation between track two
        ///   and track one concepts/types.
        /// </summary>
        ///
        /// <param name="host">The fully qualified host name for the Event Hubs namespace.  This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param>
        /// <param name="eventHubPath">The path of the specific Event Hub to connect the client to.</param>
        /// <param name="credential">The Azure managed identity credential to use for authorization.  Access controls may be specified by the Event Hubs namespace or the requeseted Event Hub, depending on Azure configuration.</param>
        /// <param name="clientOptions">A set of options to apply when configuring the client.</param>
        ///
        /// <returns>The <see cref="TrackOne.EventHubClient" /> to use.</returns>
        ///
        internal static TrackOne.EventHubClient CreateClient(string host,
                                                             string eventHubPath,
                                                             TokenCredential credential,
                                                             EventHubClientOptions clientOptions)
        {
            // Translate the connection type into the corresponding Track One transport type.

            TrackOne.TransportType transportType;

            switch (clientOptions.TransportType)
            {
            case TransportType.AmqpTcp:
                transportType = TrackOne.TransportType.Amqp;
                break;

            case TransportType.AmqpWebSockets:
                transportType = TrackOne.TransportType.AmqpWebSockets;
                break;

            default:
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidTransportType, clientOptions.TransportType.ToString(), nameof(clientOptions.TransportType)));
            }

            // Translate the provided credential into a Track One token provider.

            TokenProvider tokenProvider;

            switch (credential)
            {
            case SharedAccessSignatureCredential sasCredential:
                tokenProvider = new TrackOneSharedAccessTokenProvider(sasCredential.SharedAccessSignature);
                break;

            case EventHubTokenCredential eventHubCredential:
                tokenProvider = new TrackOneGenericTokenProvider(eventHubCredential);
                break;

            default:
                throw new ArgumentException(Resources.UnsupportedCredential, nameof(credential));
            }

            // Create the endpoint for the client.

            var endpointBuilder = new UriBuilder
            {
                Scheme = clientOptions.TransportType.GetUriScheme(),
                Host   = host,
                Path   = eventHubPath,
                Port   = -1,
            };

            // Build and configure the client.

            var client = TrackOne.EventHubClient.Create(endpointBuilder.Uri, eventHubPath, tokenProvider, clientOptions.DefaultTimeout, transportType);

            client.WebProxy = clientOptions.Proxy;

            return(client);
        }
        /// <summary>
        ///   Creates the track one Event Hub client instance for inner use, handling any necessary translation between track two
        ///   and track one concepts/types.
        /// </summary>
        ///
        /// <param name="host">The fully qualified host name for the Event Hubs namespace.  This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param>
        /// <param name="eventHubName">The name of the specific Event Hub to connect the client to.</param>
        /// <param name="credential">The Azure managed identity credential to use for authorization.  Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration.</param>
        /// <param name="clientOptions">A set of options to apply when configuring the client.</param>
        /// <param name="defaultRetryPolicyFactory">A function that retrieves a default retry policy to use if no retry options were specified in the <paramref name="clientOptions" />.</param>
        ///
        /// <returns>The <see cref="TrackOne.EventHubClient" /> to use.</returns>
        ///
        public static TrackOne.EventHubClient CreateClient(string host,
                                                           string eventHubName,
                                                           TokenCredential credential,
                                                           EventHubClientOptions clientOptions,
                                                           Func <EventHubRetryPolicy> defaultRetryPolicyFactory)
        {
            // Translate the connection type into the corresponding Track One transport type.

            TrackOne.TransportType transportType;

            switch (clientOptions.TransportType)
            {
            case TransportType.AmqpTcp:
                transportType = TrackOne.TransportType.Amqp;
                break;

            case TransportType.AmqpWebSockets:
                transportType = TrackOne.TransportType.AmqpWebSockets;
                break;

            default:
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidTransportType, clientOptions.TransportType.ToString(), nameof(clientOptions.TransportType)));
            }

            // Translate the provided credential into a Track One token provider.

            TokenProvider tokenProvider;

            switch (credential)
            {
            case SharedAccessSignatureCredential sasCredential:
                tokenProvider = new TrackOneSharedAccessTokenProvider(sasCredential.SharedAccessSignature);
                break;

            case EventHubTokenCredential eventHubCredential:
                tokenProvider = new TrackOneGenericTokenProvider(eventHubCredential);
                break;

            default:
                throw new ArgumentException(Resources.UnsupportedCredential, nameof(credential));
            }

            // Create the endpoint for the client.

            var endpointBuilder = new UriBuilder
            {
                Scheme = clientOptions.TransportType.GetUriScheme(),
                Host   = host,
                Path   = eventHubName,
                Port   = -1,
            };

            // Build and configure the client.

            var retryPolicy = (clientOptions.RetryOptions != null)
                ? new BasicRetryPolicy(clientOptions.RetryOptions)
                : defaultRetryPolicyFactory();

            var operationTimeout = retryPolicy.CalculateTryTimeout(0);
            var client           = TrackOne.EventHubClient.Create(endpointBuilder.Uri, eventHubName, tokenProvider, operationTimeout, transportType);

            client.WebProxy    = clientOptions.Proxy;
            client.RetryPolicy = new TrackOneRetryPolicy(retryPolicy);
            client.ConnectionStringBuilder.OperationTimeout = operationTimeout;

            return(client);
        }