package com.xy.xyaicpzs.common.response;

import lombok.Data;

import java.util.List;

/**
 * 分页响应对象
 * @param <T> 数据类型
 */
@Data
public class PageResponse<T> {
    
    /**
     * 数据列表
     */
    private List<T> records;
    
    /**
     * 总记录数
     */
    private Long total;
    
    /**
     * 当前页码
     */
    private Integer page;
    
    /**
     * 每页大小
     */
    private Integer size;
    
    /**
     * 总页数
     */
    private Integer totalPages;
    
    /**
     * 是否有下一页
     */
    private Boolean hasNext;
    
    /**
     * 是否有上一页
     */
    private Boolean hasPrevious;
    
    public PageResponse() {}
    
    public PageResponse(List<T> records, Long total, Integer page, Integer size) {
        this.records = records;
        this.total = total;
        this.page = page;
        this.size = size;
        this.totalPages = (int) Math.ceil((double) total / size);
        this.hasNext = page < totalPages;
        this.hasPrevious = page > 1;
    }
    
    /**
     * 创建分页响应对象
     */
    public static <T> PageResponse<T> of(List<T> records, Long total, Integer page, Integer size) {
        return new PageResponse<>(records, total, page, size);
    }
} 