package com.qmth.exam.reserve.util;

import java.util.ArrayList;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qmth.boot.core.collection.PageResult;

public class PageUtil {

    public static <T> PageResult<T> of(IPage<T> iPage) {
        PageResult<T> result = new PageResult<>();
        result.setResult(iPage.getRecords());
        result.setPageNumber(iPage.getCurrent());
        result.setPageSize(iPage.getSize());
        result.setTotalCount(iPage.getTotal());
        result.setPageCount(iPage.getPages());
        return result;
    }

    public static <T> PageResult<T> emptyPage() {
        PageResult<T> page = new PageResult<>();
        page.setPageCount(0);
        page.setPageNumber(1);
        page.setPageSize(10);
        page.setTotalCount(0);
        page.setResult(new ArrayList<>());
        return page;
    }
}
