package com.izouma.nineth.dto;

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

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageWrapper<T> {
    private List<T> content;

    private int page;

    private int size;

    private long total;

    public Page<T> toPage() {
        return new PageImpl<>(content, PageRequest.of(page, size), total);
    }

    public static <T> PageWrapper<T> of(Page<T> page) {
        return new PageWrapper<>(page.getContent(), page.getPageable().getPageNumber(),
                page.getPageable().getPageSize(), page.getTotalElements());
    }
}
