using System;
using System.Linq;
using VCommon.VApplication.Dto;
using VCommon.VEntity;

namespace VCommon.VApplication.Linq.Expressions
{
    public static class QueryableExtensions
    {
        public static IQueryable<T> PageBy<T>(this IQueryable<T> queryable, IPageRequest input)
        {
            return queryable.Skip(input.Skip).Take(input.Take);
        }

        public static IQueryable<T> OrderByCreateTimeDescAndPageBy<T>(this IQueryable<T> queryable, IPageRequest input) where T : IHaveCreationTime
        {
            return queryable
                .OrderByDescending(ExpressionHelper.Property<T, DateTime>(nameof(IHaveCreationTime.CreationTime)))
                .PageBy(input);
        }
    }
}