package com.ywt.mg.core;

import java.util.ArrayList;
import java.util.List;

public class PagedList<T> {

    /**
     * 页码
     */
    private int pageIndex = 1;

    /**
     * 页大小
     */
    private int pageSize = 10;

    /**
     * 总记录数
     */
    private int total = 0;

    /**
     * 总页数
     */
    private int totalPage = 0;

    /**
     * 记录
     */
    private List<T> items = new ArrayList<>();


    /**
     * 是否有上一页
     */
    public boolean hasPrev;

    /**
     * 是否有下一页
     */
    public boolean hasNext;

    public PagedList(int pageIndex, int pageSize, int total, List<T> items) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.total = total;
        this.items = items;
        this.totalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
        this.hasPrev = pageIndex > 1;
        this.hasNext = pageIndex < this.totalPage;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public int getTotal() {
        return total;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public List<T> getItems() {
        return items;
    }

    public boolean isHasPrev() {
        return hasPrev;
    }

    public boolean isHasNext() {
        return hasNext;
    }
}
