using Newtonsoft.Json;

namespace Exam.Infrastructure.Data.Entity
{
    public class Pagination
    {
        /// <summary>
        /// 当前页面索引
        /// </summary>
        [JsonProperty(PropertyName = "pageNum")]
        public int PageIndex { get; set; }

        /// <summary>
        /// 页面大小
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 数据总量
        /// </summary>
        [JsonProperty(PropertyName = "total")]
        public int TotalCount { get; set; }

        /// <summary>
        /// 页面首页
        /// </summary>
        public int FirstPageIndex
        {
            get
            {
                return 1;
            }
        }

        /// <summary>
        /// 页面总页数
        /// </summary>
        public int PageCount
        {
            get { return PageSize == 0 ? PageSize : TotalCount / PageSize + (TotalCount % PageSize == 0 ? 0 : 1); }
        }

        /// <summary>
        /// 偏移量
        /// </summary>
        [JsonIgnore]
        public int SkipCount
        {
            get { return PageIndex <= 0 ? PageSize : (PageIndex - 1) * PageSize; }
        }

        public Pagination(int pageIndex, int pageSize, int totalCount = 0)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = totalCount;
        }

    }

    /// <summary>
    /// 默认分页
    /// </summary>
    public class DefaultPagination : Pagination
    {
        public DefaultPagination()
            : base(PaginationValueConstant.PageIndex, PaginationValueConstant.PageSize)
        {

        }

        public DefaultPagination(int pageIndex, int pageSize, int totalCount = 0)
            : base(pageIndex, pageSize, totalCount)
        {
        }
    }

    /// <summary>
    /// 最大分页数
    /// </summary>
    public class DefaultMaxPagination : Pagination
    {
        public DefaultMaxPagination()
            : base(PaginationValueConstant.PageIndex, PaginationValueConstant.PageMaxSize)
        {

        }

        public DefaultMaxPagination(int pageIndex, int pageSize, int totalCount = 0)
            : base(pageIndex, pageSize, totalCount)
        {
        }
    }

    public class PaginationValueConstant
    {
        public const int PageIndex = 1;

        public const int PageSize = 10;

        public const int PageMaxSize = 100;
    }
}
