namespace QYZH.InteractiveMagazine.Models.Dto;

/// <summary>
/// 通用分页信息类
/// </summary>
public class PageListModel<T>
{
    /// <summary>
    /// 每页行数
    /// </summary>
    public int PageSize { get; set; } = 10;
    /// <summary>
    /// 当前页
    /// </summary>
    public int PageIndex { get; set; } = 1;
    /// <summary>
    /// 总记录数
    /// </summary>
    public int TotalNum { get; set; }
    /// <summary>
    /// 总页数
    /// </summary>
    public int TotalPage
    {
        get
        {
            if (TotalNum > 0)
                return TotalNum % PageSize == 0 ? TotalNum / PageSize : TotalNum / PageSize + 1;
            else
                return 0;
        }
    }

    public List<T> Result { get; set; }

    /// <summary>
    /// 额外数据
    /// </summary>
    public Dictionary<string, object> Extra { get; set; } = new Dictionary<string, object>();
    /// <summary>
    /// 是否有上一页
    /// </summary>
    public bool HasPrev
    {
        get
        {
            return PageIndex > 1;
        }
    }

    /// <summary>
    /// 下一页是否可用
    /// </summary>
    public bool HasNext
    {
        get
        {
            return TotalPage > PageIndex;
        }
    }

    public PageListModel()
    {
    }

    public PageListModel(List<T> result, int pageIndex, int pageSize, int totalNum)
    {
        PageIndex = pageIndex;
        PageSize = pageSize;
        TotalNum = totalNum;
        Result = result;
    }
}
