package org.xyzh.common.core.page;

import java.io.Serializable;

/**
 * @description    PageParam.java文件描述 分页参数
 * @filename    PageParam.java
 * @author    yslg
 * @copyright xyzh
 * @since 2025-09-07
 */
public class PageParam implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * @description    当前页码
     * @author    yslg
     * @since 2025-09-07
     */
    private int pageNumber;

    /**
     * @description    每页显示数量
     * @author    yslg
     * @since 2025-09-07
     */
    private int pageSize;

    /**
     * @description    总页数
     * @author    yslg
     * @since 2025-09-07
     */
    private int totalPages;

    /**
     * @description    总记录数
     * @author    yslg
     * @since 2025-09-07
     */
    private long totalElements;

    /**
     * @description    偏移量
     * @author    yslg
     * @since 2025-10-20
     */
    private long offset;

    public PageParam() {
        this.pageNumber = 1;
        this.pageSize = 10;
        this.totalPages = 0;
        this.totalElements = 0;
        this.offset = 0;
    }

    public PageParam(int pageNumber, int pageSize) {
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.offset = (pageNumber - 1) * pageSize;
    }

    public PageParam(int pageNumber, int pageSize, int totalPages, long totalElements) {
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.totalPages = totalPages;
        this.totalElements = totalElements;
        this.offset = (pageNumber - 1) * pageSize;
    }
    /**
     * @description    设置当前页码
     * @param    pageNumber 当前页码
     * @return    void
     * @author    yslg
     * @since 2025-09-07
     */
    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    /**
     * @description    获取当前页码
     * @return    当前页码
     * @author    yslg
     * @since 2025-09-07
     */
    public int getPageNumber() {
        return pageNumber;
    }

    /**
     * @description    设置每页显示数量
     * @param    pageSize 每页显示数量
     * @return    void
     * @author    yslg
     * @since 2025-09-07
     */
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * @description    获取每页显示数量
     * @return    每页显示数量
     * @author    yslg
     * @since 2025-09-07
     */
    public int getPageSize() {
        return pageSize;
    }

    /**
     * @description    设置总页数
     * @param    totalPages 总页数
     * @return    void
     * @author    yslg
     * @since 2025-09-07
     */
    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    /**
     * @description    获取总页数
     * @return    总页数
     * @author    yslg
     * @since 2025-09-07
     */
    public int getTotalPages() {
        return totalPages;
    }

    /**
     * @description    设置总记录数
     * @param    totalElements 总记录数
     * @return    void
     * @author    yslg
     * @since 2025-09-07
     */
    public void setTotalElements(long totalElements) {
        this.totalElements = totalElements;
        if (this.pageSize > 0) {
            this.totalPages = (int) ((totalElements + pageSize - 1) / pageSize);
        } else {
            this.totalPages = 0;
        }
    }

    /**
     * @description    获取总记录数
     * @return    总记录数
     * @author    yslg
     * @since 2025-09-07
     */
    public long getTotalElements() {
        return totalElements;
    }

    /**
     * @description    设置偏移量
     * @param    offset 偏移量
     * @return    void
     * @author    yslg
     * @since 2025-10-20
     */
    public void setOffset(long offset) {
        this.offset = offset;
    }

    /**
     * @description    获取偏移量
     * @return    偏移量
     * @author    yslg
     * @since 2025-10-20
     */
    public long getOffset() {
        return offset;
    }
}
