package com.qunzhixinxi.hnqz.admin.entity.base;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * {@code HnqzPage}
 * <p>
 * 分页结果
 *
 * @author Hengchen.Sun
 * @version 1.0.0
 * @date 2021/11/11 16:46
 */
@Data
public final class HnqzPage<T> implements Serializable {

    private static final long serialVersionUID = 4263748953110453274L;

    public HnqzPage(Page<T> page) {
        this.records = page.getRecords();
        this.total = page.getTotal();
        this.current = page.getCurrent();
        this.size = page.getSize();
        this.pages = page.getPages();
        this.hasNext = page.hasNext();
        this.hasPrevious = page.hasPrevious();
    }

    /**
     * 记录
     */
    private final List<T> records;

    /**
     * 记录总数
     */
    private final Long total;

    /**
     * 分页记录数
     */
    private final Long size;

    /**
     * 是否是最后一页
     */
    private final Boolean hasNext;

    /**
     * 是否是第一页
     */
    private final Boolean hasPrevious;

    /**
     * 当前页
     */
    private final Long current;

    /**
     * 总共多少页
     */
    private final Long pages;

    /**
     * 静态方法 封装page
     *
     * @param page 分页结果
     * @param <T>  记录类型
     * @return gulop page
     */
    public static <T> HnqzPage<T> of(Page<T> page) {
        return new HnqzPage<>(page);
    }
}
