package com.ruoyi.common.core.domain;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

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

/**
 * 响应信息主体
 *
 * @author Lion Li
 */
@Data
@NoArgsConstructor
public class PageModel<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @Schema(description = "分页数据")
    private List<T> rows;
    @Schema(description = "总数量")
    private long total;

    public PageModel(List<T> list, long total) {
        this.rows = list;
        this.total = total;
    }

    public static <T> PageModel<T> build(IPage<T> page) {
        PageModel<T> rspData = new PageModel<>();
        rspData.setRows(page.getRecords());
        rspData.setTotal(page.getTotal());
        return rspData;
    }
}
