package com.eactive.eai.rms.common.vo;

import java.util.List;

import org.springframework.data.domain.Page;

public class GridResponse<T> {

	private Integer total;
	private Integer page;
	private Long records;
	private List<T> rows;
	
	public GridResponse() {
	}
	
	public GridResponse(Page<T> page) {
		setPage(page);
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Long getRecords() {
		return records;
	}

	public void setRecords(Long records) {
		this.records = records;
	}
	
	public void setRecords(Integer records) {
		this.records = records.longValue();
	}

	public List<T> getRows() {
		return rows;
	}

	public void setRows(List<T> rows) {
		this.rows = rows;
	}
	
	public GridResponse(List<T> rows) {
        this.rows = rows;
        this.total = 1;
        this.page = 1;
        this.records = (long) rows.size();
    }

	public GridResponse<T> setPage(Page<T> page) {
		setTotal(page.getTotalPages()); // 전체 페이지수
		setPage(page.getNumber() + 1); // 현재 페이지수
		setRecords(page.getTotalElements()); // 전체 레코드건수
		setRows(page.getContent());
		return this;
	}
}
