namespace YGNT.Infrastructure.Helper
{
    /// <summary>
    /// 分页的标识
    /// </summary>
    public class PagePagingHelp
    {
        public PagePagingHelp()
        {
            PageSize = 15;
            PageIndex = 1;
        }

        /// <summary>
        /// 页码[默认1][小于等于0为全部]
        /// </summary>
        public int? PageIndex { get; set; }

        /// <summary>
        /// 每页条数[默认15][小于等于0为全部]
        /// </summary>
        public int? PageSize { get; set; }
    }

    /// <summary>
    /// 页码总数量数据
    /// </summary>
    public class PageTotalData<T>
    {
        /// <summary>
        /// 初始化空的的数据
        /// </summary>
        public PageTotalData()
        {
            Total = 0;
            TotalPageNum = null;
        }

        /// <summary>
        /// 初始化每页的数据
        /// </summary>
        /// <param name="total"></param>
        /// <param name="pageData"></param>
        /// <param name="pagePaging"></param>
        public PageTotalData(int total, T pageData, PagePagingHelp pagePaging = null)
        {
            Total = total;
            PageData = pageData;

            if (total == 0)
            {
                TotalPageNum = 0;
            }
            else if (total > 0 && pagePaging != null)
            {
                PagePagingHelp pagePagingHelp = new PagePagingHelp();

                if (!pagePaging.PageIndex.HasValue)
                    pagePaging.PageIndex = pagePagingHelp.PageIndex;
                if (!pagePaging.PageSize.HasValue)
                    pagePaging.PageSize = pagePagingHelp.PageSize;

                if (pagePaging.PageIndex <= 0 || pagePaging.PageSize <= 0)
                    TotalPageNum = 1;
                else
                    TotalPageNum = (Total + pagePaging.PageSize - 1) / pagePaging.PageSize;
            }
        }

        /// <summary>
        /// 总条数
        /// </summary>
        public int Total { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int? TotalPageNum { get; set; }

        /// <summary>
        /// 页数据
        /// </summary>
        public T PageData { get; set; }
    }

}
