package com.app.framework.core.api.paging;

import com.app.framework.core.support.view.grid.Paging;

import java.util.List;

/**
 * Api分页返回数据
 * @param <T>
 */
public class ApiPagingData<T> {

    /**
     * 分页信息
     */
    private PagingResult paging;

    /**
     * 分页数据
     */
    private List<T> data;

    public PagingResult getPaging() {
        return paging;
    }

    public void setPaging(PagingResult paging) {
        this.paging = paging;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public ApiPagingData(Paging paging, List<T> data){
        PagingResult pagingResult = new PagingResult();
        if(paging != null) {
            pagingResult.setPageNo(paging.getPageNo());
            pagingResult.setLimit(paging.getLimit());
            pagingResult.setTotalCount(paging.getTotalCount());
            pagingResult.setTotalPage(paging.getTotalPage());
        }
        this.setPaging(pagingResult);
        this.setData(data);
    }

    public class PagingResult {
        /**当前页码*/
        private Integer pageNo;
        /**每页显示记录数*/
        private Integer limit;
        /**总记录*/
        private Long totalCount;
        /**总页数*/
        private Long totalPage;

        public Integer getPageNo() {
            return pageNo;
        }

        public void setPageNo(Integer pageNo) {
            this.pageNo = pageNo;
        }

        public Integer getLimit() {
            return limit;
        }

        public void setLimit(Integer limit) {
            this.limit = limit;
        }

        public Long getTotalCount() {
            if(totalCount == null){
                totalCount = 0L;
            }
            return totalCount;
        }

        public void setTotalCount(Long totalCount) {
            this.totalCount = totalCount;
        }

        public Long getTotalPage() {
            if(totalPage == null){
                totalPage = 0L;
            }
            return totalPage;
        }

        public void setTotalPage(Long totalPage) {
            this.totalPage = totalPage;
        }
    }
}
