package com.sunyard.chsm.model;

import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @author liulu
 * @since 2024/10/16
 */
@Getter
@NoArgsConstructor
public class PageQuery {

    public static final int MAX_PAGE_SIZE = 200;

    /**
     * 当前页
     */
    private int pageNumber = 1;
    /**
     * 每页大小
     */
    private int pageSize = 10;


    public PageQuery(int pageNum, int pageSize) {
        this.pageNumber = pageNum;
        this.pageSize = pageSize;
    }

    public void setPageNumber(int pageNum) {
        this.pageNumber = Math.max(1, pageNum);
    }

    public void setPageSize(int pageSize) {
        this.pageSize = Math.min(MAX_PAGE_SIZE, Math.max(1, pageSize));
    }

    public int getOffset() {
        return pageSize * (pageNumber - 1);
    }

}
