package com.ruoyi.tjfx.common;

import lombok.Data;

import java.util.List;

/**
 * 分页响应类
 */
@Data
public class PageResponse<T> {

    private List<T> list;
    private Pagination pagination;

    public PageResponse(List<T> list, Pagination pagination) {
        this.list = list;
        this.pagination = pagination;
    }

    @Data
    public static class Pagination {
        private Long total;
        private Integer page;
        private Integer pageSize;
        private Integer totalPages;
        private Boolean hasNext;
        private Boolean hasPrev;

        public Pagination(Long total, Integer page, Integer pageSize) {
            this.total = total;
            this.page = page;
            this.pageSize = pageSize;
            this.totalPages = (int) Math.ceil((double) total / pageSize);
            this.hasNext = page < totalPages;
            this.hasPrev = page > 1;
        }
    }
}
