namespace LyricsFinder.NET.Utility
{
    public class PaginatedList<T> : List<T>
    {
        public PaginatedList(List<T> items, int count, int pageIndex, int pageSize)
        {
            PageIndex = pageIndex;
            TotalPages = (int)Math.Ceiling(count / (double)pageSize);

            this.AddRange(items);
        }

        public bool HasNextPage
        {
            get { return (PageIndex < TotalPages); }
        }

        public bool HasPreviousPage
        {
            get { return (PageIndex > 1); }
        }

        public int PageIndex { get; private set; }
        public int TotalPages { get; private set; }

        public static PaginatedList<T> Create(IEnumerable<T> source, int pageIndex, int pageSize)
        {
            var count = source.Count();
            var items = source.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            return new PaginatedList<T>(items, count, pageIndex, pageSize);
        }
    }
}