using System;

namespace CncModels.Dto
{
    /// <summary>
    /// 分页查询参数基类
    /// 默认值：page=1, pageSize=20
    /// 约束：pageSize最大100，page最小1
    /// </summary>
    public class PagedQuery
    {
        private int _page = 1;
        private int _pageSize = 20;

        /// <summary>页码（从1开始），小于1自动修正为1</summary>
        public int Page
        {
            get => _page;
            set => _page = value < 1 ? 1 : value;
        }

        /// <summary>每页条数，范围1-100，超出自动修正</summary>
        public int PageSize
        {
            get => _pageSize;
            set => _pageSize = value < 1 ? 20 : (value > 100 ? 100 : value);
        }

        /// <summary>
        /// 计算SQL偏移量（OFFSET）
        /// </summary>
        public int Offset => (Page - 1) * PageSize;
    }
}
