package com.zanxiang.game.gs.data.serve.pojo.vo;

import com.mybatisflex.core.paginate.Page;
import com.zanxiang.game.gs.data.serve.pojo.dto.BaseListDTO;
import lombok.Data;

import java.util.Collections;
import java.util.List;

@Data
public class PageVO<T, S> {

    private long current;
    private long size;
    private long total;
    private long pages;
    private List<T> records;
    private S sumRecord;

    public PageVO(long current, long size) {
        this(current, size, 0, Collections.emptyList());
    }

    public PageVO(long current, long size, long total, List<T> records) {
        this.current = 0;
        this.size = size;
        this.total = total;
        this.pages = this.total % this.size > 0 ? this.total / this.size + 1 : this.total / this.size;
        this.records = records;
    }

    public PageVO(Page<T> page) {
        this.current = page.getPageNumber();
        this.size = page.getPageSize();
        this.total = page.getTotalRow();
        this.pages = page.getTotalPage();
        this.records = page.getRecords();
    }

    public static <T, S> PageVO<T, S> empty(BaseListDTO dto) {
        return new PageVO<>(dto.getPageNum(), dto.getPageSize(), 0, Collections.emptyList());
    }
}
