using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Threading.Tasks; using JpnCardsPokemonSdk.Client.Endpoints; namespace JpnCardsPokemonSdk.Client.Responses; public class PageableApiResponse : EnumerableApiResponse, IPageableApiResponse, IEnumerable> where T : EndpointObject { private string? RequestUri { get; set; } public int TotalPages => (int)Math.Ceiling((decimal)( (IPageableApiResponse, IEnumerable>)this).TotalCount / ( (IPageableApiResponse, IEnumerable>)this).PageSize); ApiClient? IPageableApiResponse, IEnumerable>.CurrentApiClient { get; set; } int IPageableApiResponse, IEnumerable>.Page { get; set; } int IPageableApiResponse, IEnumerable>.PageSize { get; set; } int IPageableApiResponse, IEnumerable>.Count { get; set; } int IPageableApiResponse, IEnumerable>.TotalCount { get; set; } #if !(NETCOREAPP3_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER) bool IPageableApiResponse, IEnumerable>.HasNextPage() { return ((IPageableApiResponse, IEnumerable>)this).Page < ((IPageableApiResponse, IEnumerable>)this).TotalCount; } #endif async Task> IPageableApiResponse, IEnumerable>. FetchNextPageAsync() { return await ((IPageableApiResponse, IEnumerable>)this).FetchPageAsync(( (IPageableApiResponse, IEnumerable>)this).Page + 1); } async Task?> IPageableApiResponse, IEnumerable>. FetchPageAsync(int page) { var requestUri = RequestUri + "&page=" + page; return await ((IPageableApiResponse, IEnumerable>)this).CurrentApiClient ?.FetchDataAsync, IEnumerable>(requestUri)!; } void IPageableApiResponse, IEnumerable>.RememberRequestUri(string requestUri) { // Remember full Uri without page RequestUri = Regex.Replace(requestUri, @"page=\d*&?", ""); } }