package com.bio.bio_backend.global.dto;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * 페이지네이션된 결과를 담는 제네릭 클래스
 * @param <T> 페이지네이션할 데이터의 타입
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class PagedResult<T> extends BasePagedResponseDto {
    
    private List<T> content;
    
    public static <T> PagedResult<T> of(Page<?> page, List<T> content) {
        PagedResult<T> result = new PagedResult<>();
        result.setContent(content);
        result.setCurrentPage(page.getNumber());
        result.setTotalPages(page.getTotalPages());
        result.setTotalElements(page.getTotalElements());
        result.setSize(page.getSize());
        result.setHasNext(page.hasNext());
        result.setHasPrevious(page.hasPrevious());
        result.setFirst(page.isFirst());
        result.setLast(page.isLast());
        return result;
    }
}
