// Kyoo - A portable and vast media library solution.
// Copyright (c) Kyoo.
//
// See AUTHORS.md and LICENSE file in the project root for full license information.
//
// Kyoo is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Kyoo is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see .
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 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();
}
}
}