using kehati.Models.Common;
using Microsoft.EntityFrameworkCore;

public static class Pagination
{
    public static async Task<PagedResult<T>> PaginateAsync<T>(
        IQueryable<T> query,
        int page = 1,
        int pageSize = 10)
    {
        var totalItems = await query.CountAsync();

        var items = await query
            .Skip((page - 1) * pageSize)
            .Take(pageSize)
            .ToListAsync();

        return new PagedResult<T>
        {
            Items = items,
            CurrentPage = page,
            PageSize = pageSize,
            TotalItems = totalItems
        };
    }
}