using System; using System.Collections.Generic; using System.Linq; using Kyoo.Utils; namespace Kyoo.Abstractions.Models { /// /// A page of resource that contains information about the pagination of resources. /// /// The type of resource contained in this page. public class Page where T : IResource { /// /// The link of the current page. /// public Uri This { get; } /// /// The link of the first page. /// public Uri First { get; } /// /// The link of the next page. /// public Uri Next { get; } /// /// The number of items in the current page. /// public int Count => Items.Count; /// /// The list of items in the page. /// public ICollection Items { get; } /// /// Create a new . /// /// The list of items in the page. /// The link of the current page. /// The link of the next page. /// The link of the first page. public Page(ICollection items, Uri @this, Uri next, Uri first) { Items = items; This = @this; Next = next; First = first; } /// /// Create a new and compute the urls. /// /// The list of items in the page. /// The base url of the resources available from this page. /// The list of query strings of the current page /// The number of items requested for the current page. public Page(ICollection items, Uri url, Dictionary query, int limit) { Items = items; This = new Uri(url + query.ToQueryString()); if (items.Count == limit && limit > 0) { query["afterID"] = items.Last().ID.ToString(); Next = new Uri(url + query.ToQueryString()); } query.Remove("afterID"); First = new Uri(url + query.ToQueryString()); } } }