package com.usky.common.core.bean;

import lombok.Data;

import java.util.List;

/**
 * 分页类. 用于分页接口响应
 * 结构从IPage复制而来.
 *
 * @param <T>
 */
@Data
public class CommonPage<T> {
    private static final long serialVersionUID = 8545996863226528798L;
    protected List<T> records;
    protected long total;
    protected long size;
    protected long current;

    public CommonPage() {

    }

    public CommonPage(List<T> records, long total, long size, long current) {
        this.records = records;
        this.total = total;
        this.size = size;
        this.current = current;
    }

    /**
     * 计算虚假total.
     * 该total不是真实的数量, 只能给出是否还有下一页.
     *
     * @param current
     * @param size
     * @param currentSize
     * @return
     */
    public static int fakeTotal(long current, long size, long currentSize) {
        int total = 0;
        if (currentSize >= size) {
            total += current * size + 1;
        } else {
            total += (current - 1) * size + currentSize;
        }
        return total;
    }

}
