package com.malk.server.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * 分页集合数据结构
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class McPage {

    private int page = 1;

    private int size;

    private long total = 0;

    private List list;

    public static McPage page(Page page) {
        return page(page, page.getContent());
    }

    public static McPage page(Page page, List dataList) {
        return McPage.builder()
                .total(page.getTotalElements())
                .page(page.getNumber())
                .size(page.getSize())
                .list(dataList)
                .build();
    }
}