package com.sundot.airport.exam.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;

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

public class PageData<T> {

    /**
     * 当前页
     * 默认第一页
     */
    private int pageNum = 1;

    /**
     * 每页的数量
     * 默认展示10条
     */
    private int pageSize = 10;

    /**
     * 总记录数
     * 默认0条
     */
    private long total = 0;

    /**
     * 总页数
     * 默认0页
     */
    private int pages = 0;

    /**
     * 结果集
     */
    private List<T> list = new ArrayList<>();

    public PageData(PageInfo pageInfo) {
        this.pageNum = pageInfo.getPageNum();
        this.pageSize = pageInfo.getPageSize();
        this.total = pageInfo.getTotal();
        this.pages = pageInfo.getPages();
    }

    public PageData(Page<T> page1) {
        this.pageNum = (int) page1.getCurrent();
        this.pageSize = (int) page1.getSize();
        this.total = page1.getTotal();
        this.list = page1.getRecords();
    }

    public PageData() {
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}

