package com.hdkj.lt.bf.entity.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * 通用分页查询结果
 *
 * @author lsl
 * @since 2026-07-23
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel(description = "分页查询结果")
public class PageResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "数据列表")
    private List<T> records;

    @ApiModelProperty(value = "总记录数")
    private long total;

    @ApiModelProperty(value = "总页数")
    private long pages;

    @ApiModelProperty(value = "当前页码")
    private long current;

    @ApiModelProperty(value = "每页大小")
    private long pageSize;

    public static <T> PageResult<T> of(IPage<?> mpPage, List<T> records) {
        PageResult<T> r = new PageResult<>();
        r.setRecords(records);
        r.setTotal(mpPage.getTotal());
        r.setPages(mpPage.getPages());
        r.setCurrent(mpPage.getCurrent());
        r.setPageSize(mpPage.getSize());
        return r;
    }
}
