/// <summary>
        /// Deletes Time Series instances from the environment by Time Series Ids synchronously.
        /// </summary>
        /// <param name="timeSeriesHierarchyIds">List of Ids of the Time Series instances to delete.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// List of error objects corresponding by position to the input array in the request. null when the operation is successful.
        /// </returns>
        /// <seealso cref="DeleteByIdAsync(IEnumerable{string}, CancellationToken)">
        /// See the asynchronous version of this method for examples.
        /// </seealso>
        /// <exception cref="ArgumentNullException">
        /// The exception is thrown when <paramref name="timeSeriesHierarchyIds"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The exception is thrown when <paramref name="timeSeriesHierarchyIds"/> is empty.
        /// </exception>
        public virtual Response <TimeSeriesOperationError[]> DeleteById(
            IEnumerable <string> timeSeriesHierarchyIds,
            CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(DeleteById)}");
            scope.Start();
            try
            {
                Argument.AssertNotNullOrEmpty(timeSeriesHierarchyIds, nameof(timeSeriesHierarchyIds));

                var batchRequest = new HierarchiesBatchRequest
                {
                    Delete = new HierarchiesRequestBatchGetDelete()
                };

                foreach (string hierarchyId in timeSeriesHierarchyIds ?? Enumerable.Empty <string>())
                {
                    batchRequest.Delete.HierarchyIds.Add(hierarchyId);
                }
                Response <HierarchiesBatchResponse> executeBatchResponse = _hierarchiesRestClient
                                                                           .ExecuteBatch(batchRequest, null, cancellationToken);
                return(Response.FromValue(executeBatchResponse.Value.Delete.ToArray(), executeBatchResponse.GetRawResponse()));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }
        /// <summary>
        /// Creates Time Series Insights hierarchies synchronously. If a provided hierarchy is already in use, then this will attempt to replace the existing hierarchy with the provided Time Series hierarchy.
        /// </summary>
        /// <param name="timeSeriesHierarchies">The Time Series Insights hierarchies to be created or replaced.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// List of hierarchies or error objects corresponding by position to the <paramref name="timeSeriesHierarchies"/> array in the request.
        /// Hierarchy object is set when operation is successful and error object is set when operation is unsuccessful.
        /// </returns>
        /// <seealso cref="CreateOrReplaceAsync(IEnumerable{TimeSeriesHierarchy}, CancellationToken)">
        /// See the asynchronous version of this method for examples.
        /// </seealso>
        /// <exception cref="ArgumentNullException">
        /// The exception is thrown when <paramref name="timeSeriesHierarchies"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The exception is thrown when <paramref name="timeSeriesHierarchies"/> is empty.
        /// </exception>
        public virtual Response <TimeSeriesHierarchyOperationResult[]> CreateOrReplace(
            IEnumerable <TimeSeriesHierarchy> timeSeriesHierarchies,
            CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(CreateOrReplace)}");
            scope.Start();

            try
            {
                Argument.AssertNotNullOrEmpty(timeSeriesHierarchies, nameof(timeSeriesHierarchies));

                var batchRequest = new HierarchiesBatchRequest();

                foreach (TimeSeriesHierarchy hierarchy in timeSeriesHierarchies)
                {
                    batchRequest.Put.Add(hierarchy);
                }

                Response <HierarchiesBatchResponse> executeBatchResponse = _hierarchiesRestClient
                                                                           .ExecuteBatch(batchRequest, null, cancellationToken);

                IEnumerable <TimeSeriesOperationError> errorResults = executeBatchResponse.Value.Put.Select((result) => result.Error);

                return(Response.FromValue(executeBatchResponse.Value.Put.ToArray(), executeBatchResponse.GetRawResponse()));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }
        /// <summary>
        /// Deletes Time Series Insights hierarchies by hierarchy names asynchronously.
        /// </summary>
        /// <param name="timeSeriesHierarchyNames">List of names of the Time Series hierarchies to delete.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// List of error objects corresponding by position to the input array in the request. null when the operation is successful.
        /// </returns>
        /// <remarks>
        /// For more samples, see <see href="https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/timeseriesinsights/Azure.IoT.TimeSeriesInsights/samples">our repo samples</see>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// The exception is thrown when <paramref name="timeSeriesHierarchyNames"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The exception is thrown when <paramref name="timeSeriesHierarchyNames"/> is empty.
        /// </exception>
        public virtual async Task <Response <TimeSeriesOperationError[]> > DeleteByNameAsync(
            IEnumerable <string> timeSeriesHierarchyNames,
            CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(DeleteByName)}");
            scope.Start();

            try
            {
                Argument.AssertNotNullOrEmpty(timeSeriesHierarchyNames, nameof(timeSeriesHierarchyNames));

                var batchRequest = new HierarchiesBatchRequest
                {
                    Delete = new HierarchiesRequestBatchGetDelete()
                };

                foreach (string timeSeriesName in timeSeriesHierarchyNames)
                {
                    batchRequest.Delete.Names.Add(timeSeriesName);
                }

                Response <HierarchiesBatchResponse> executeBatchResponse = await _hierarchiesRestClient
                                                                           .ExecuteBatchAsync(batchRequest, null, cancellationToken)
                                                                           .ConfigureAwait(false);

                return(Response.FromValue(executeBatchResponse.Value.Delete.ToArray(), executeBatchResponse.GetRawResponse()));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }
        /// <summary>
        /// Gets Time Series Insights hierarchies by hierarchy names synchronously.
        /// </summary>
        /// <param name="timeSeriesHierarchyNames">List of names of the Time Series hierarchies to return.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// List of hierarchy or error objects corresponding by position to the array in the request.
        /// Hierarchy object is set when operation is successful and error object is set when operation is unsuccessful.
        /// </returns>
        /// <seealso cref="GetByNameAsync(IEnumerable{string}, CancellationToken)">
        /// See the asynchronous version of this method for examples.
        /// </seealso>
        /// <exception cref="ArgumentNullException">
        /// The exception is thrown when <paramref name="timeSeriesHierarchyNames"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The exception is thrown when <paramref name="timeSeriesHierarchyNames"/> is empty.
        /// </exception>
        public virtual Response <TimeSeriesHierarchyOperationResult[]> GetByName(
            IEnumerable <string> timeSeriesHierarchyNames,
            CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TimeSeriesInsightsClient)}.{nameof(GetByName)}");
            scope.Start();

            try
            {
                Argument.AssertNotNullOrEmpty(timeSeriesHierarchyNames, nameof(timeSeriesHierarchyNames));

                var batchRequest = new HierarchiesBatchRequest()
                {
                    Get = new HierarchiesRequestBatchGetDelete()
                };

                foreach (string timeSeriesName in timeSeriesHierarchyNames)
                {
                    batchRequest.Get.Names.Add(timeSeriesName);
                }

                Response <HierarchiesBatchResponse> executeBatchResponse = _hierarchiesRestClient
                                                                           .ExecuteBatch(batchRequest, null, cancellationToken);

                return(Response.FromValue(executeBatchResponse.Value.Get.ToArray(), executeBatchResponse.GetRawResponse()));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }