using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Hotline.Share.Requests;
using SqlSugar;
using XF.Domain.Entities;

namespace Hotline.Repository.SqlSugar.Extensions
{
    public static class SqlSugarRepositoryExtensions
    {
        public static async Task<(int Total, List<TEntity> Items)> ToPagedListAsync<TEntity>(this ISugarQueryable<TEntity> query, int pageIndex, int pageSize, CancellationToken cancellationToken = default)
            where TEntity : class, new()
        {
            RefAsync<int> total = 0;
            var items = await query.ToPageListAsync(pageIndex, pageSize, total, cancellationToken);
            return (total.Value, items);
        }

        public static async Task<(int Total, List<TEntity> Items)> ToPagedListAsync<TEntity>(this ISugarQueryable<TEntity> query, PagedRequest dto, CancellationToken cancellationToken = default)
            where TEntity : class, new()
        {
            RefAsync<int> total = 0;
            var items = await query.ToPageListAsync(dto.PageIndex, dto.PageSize, total, cancellationToken);
            return (total.Value, items);
        }
    }
}
