using System.Collections.Generic;
using System.Linq;
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 string This { get; }
///
/// The link of the first page.
///
public string First { get; }
///
/// The link of the next page.
///
public string 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, string @this, string next, string 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,
string url,
Dictionary query,
int limit)
{
Items = items;
This = url + query.ToQueryString();
if (items.Count == limit && limit > 0)
{
query["afterID"] = items.Last().ID.ToString();
Next = url + query.ToQueryString();
}
query.Remove("afterID");
First = url + query.ToQueryString();
}
}
}