package com.njzscloud.common.mp.support;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
 * 分页结果类
 */
@Getter
@Setter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class PageResult<T> {

    private final List<T> records;

    /**
     * 总数
     */
    private final Integer total;

    /**
     * 总页数
     */
    private final Integer pages;

    /**
     * 每页显示条数，默认 10
     */
    private final Integer size;

    /**
     * 当前页
     */
    private final Integer current;


    public static <E> PageResult<E> of(IPage<E> page) {
        return new PageResult<>(page.getRecords(), (int) page.getTotal(), (int) page.getPages(), (int) page.getSize(), (int) page.getCurrent());
    }

}
