/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 * 
 *  http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file 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.
 */

/*
 * Do not modify this file. This file is generated from the ec2-2016-11-15.normal.json service model.
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Threading;
using System.Threading.Tasks;
using Amazon.Runtime;
 
namespace Amazon.EC2.Model
{
    /// <summary>
    /// Base class for GetAssociatedIpv6PoolCidrs paginators.
    /// </summary>
    internal sealed partial class GetAssociatedIpv6PoolCidrsPaginator : IPaginator<GetAssociatedIpv6PoolCidrsResponse>, IGetAssociatedIpv6PoolCidrsPaginator
    {
        private readonly IAmazonEC2 _client;
        private readonly GetAssociatedIpv6PoolCidrsRequest _request;
        private int _isPaginatorInUse = 0;
        
        /// <summary>
        /// Enumerable containing all full responses for the operation
        /// </summary>
        public IPaginatedEnumerable<GetAssociatedIpv6PoolCidrsResponse> Responses => new PaginatedResponse<GetAssociatedIpv6PoolCidrsResponse>(this);

        /// <summary>
        /// Enumerable containing all of the Ipv6CidrAssociations
        /// </summary>
        public IPaginatedEnumerable<Ipv6CidrAssociation> Ipv6CidrAssociations => 
            new PaginatedResultKeyResponse<GetAssociatedIpv6PoolCidrsResponse, Ipv6CidrAssociation>(this, (i) => i.Ipv6CidrAssociations);

        internal GetAssociatedIpv6PoolCidrsPaginator(IAmazonEC2 client, GetAssociatedIpv6PoolCidrsRequest request)
        {
            this._client = client;
            this._request = request;
        }
#if BCL
        IEnumerable<GetAssociatedIpv6PoolCidrsResponse> IPaginator<GetAssociatedIpv6PoolCidrsResponse>.Paginate()
        {
            if (Interlocked.Exchange(ref _isPaginatorInUse, 1) != 0)
            {
                throw new System.InvalidOperationException("Paginator has already been consumed and cannot be reused. Please create a new instance.");
            }
            PaginatorUtils.SetUserAgentAdditionOnRequest(_request);
            var nextToken = _request.NextToken;
            GetAssociatedIpv6PoolCidrsResponse response;
            do
            {
                _request.NextToken = nextToken;
                response = _client.GetAssociatedIpv6PoolCidrs(_request);
                nextToken = response.NextToken;
                yield return response;
            }
            while (!string.IsNullOrEmpty(nextToken));
        }
#endif
#if AWS_ASYNC_ENUMERABLES_API
        async IAsyncEnumerable<GetAssociatedIpv6PoolCidrsResponse> IPaginator<GetAssociatedIpv6PoolCidrsResponse>.PaginateAsync(CancellationToken cancellationToken = default)
        {
            if (Interlocked.Exchange(ref _isPaginatorInUse, 1) != 0)
            {
                throw new System.InvalidOperationException("Paginator has already been consumed and cannot be reused. Please create a new instance.");
            }
            PaginatorUtils.SetUserAgentAdditionOnRequest(_request);
            var nextToken = _request.NextToken;
            GetAssociatedIpv6PoolCidrsResponse response;
            do
            {
                _request.NextToken = nextToken;
                response = await _client.GetAssociatedIpv6PoolCidrsAsync(_request, cancellationToken).ConfigureAwait(false);
                nextToken = response.NextToken;
                cancellationToken.ThrowIfCancellationRequested();
                yield return response;
            }
            while (!string.IsNullOrEmpty(nextToken));
        }
#endif
    }
}