package cn.axzo.msg.center.common.utils;

import cn.azxo.framework.common.model.Page;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Collections;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author cold_blade
 * @date 2023/10/16
 * @version 1.0
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class PageHelperUtil {

    public static <T> Page<T> emptyPage(Long pageNum, Long pageSize) {
        return Page.toPage(pageNum, pageSize, 0L, Collections.emptyList());
    }

    public static <T, S> Page<T> convert(Page<S> page, Function<S, T> convertFunc) {
        Page<T> tgtPage = new Page<>();
        tgtPage.setPageNum(page.getPageNum());
        tgtPage.setPageSize(page.getPageSize());
        tgtPage.setTotalElements(page.getTotalElements());
        tgtPage.setList(page.getList().stream().map(convertFunc).collect(Collectors.toList()));
        return tgtPage;
    }
}
