package com.bcxin.Infrastructures;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;

import java.io.Serializable;
import java.util.Collection;

@Getter
public class Pageable<T> implements Serializable {
    private final int pageIndex;
    private final int pageSize;
    @JsonIgnore
    private final int totalCount;
    private final Collection<T> data;

    public Pageable(int pageIndex, int pageSize, int totalCount, Collection<T> data) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.data = data;
        this.totalCount = totalCount;
    }

    public static <T> Pageable create(int pageIndex, int pageSize, int totalCount, Collection<T> data) {
        return new Pageable(pageIndex, pageSize, totalCount, data);
    }

    public int getTotal() {
        return this.getTotalCount();
    }
}
