package com.zanxiang.game.data.serve.utils;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.nutz.dao.pager.Pager;

import java.util.Collections;
import java.util.List;

/**
 * @author shishaosong
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Page<T> {

    /**
     * 查询数据列表
     */
    private List<T> records = Collections.emptyList();

    /**
     * 总数
     */
    private long total = 0;
    /**
     * 每页显示条数，默认 10
     */
    private long size = 10;

    /**
     * 当前页
     */
    private long current = 1;

    /**
     * 总页数
     */
    private long pages;

    public Page(List<T> records, Pager pager) {
        this.records = records;
        this.pages = pager.getPageCount();
        this.current = pager.getPageNumber();
        this.total = pager.getRecordCount();
        this.size = pager.getPageSize();
    }
}
