package egovframework.util;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@ToString
@Getter
@Setter
public class PageMaker {

    private int totalCount;
    private int startPage;
    private int endPage;
    private boolean prev;
    private boolean next;
    private int totalPage;
    private int currentPage;
    private static final int DISPLAY_PAGE_NUM = 5;
    private static final int PAGE_PER_COUNT = 10;

    public PageMaker(int currentPage, int totalCount) {
        if (totalCount <= PAGE_PER_COUNT) {
            this.startPage = 1;
            this.endPage   = 1;
            this.prev      = false;
            this.next      = false;
            this.totalPage  = 1;
            this.currentPage = 1;
        }
        else {
            this.currentPage = currentPage;
            this.totalCount  = totalCount;
            this.totalPage   = ((this.totalCount - 1) / PAGE_PER_COUNT ) + 1;
            this.endPage     = (((currentPage - 1) / DISPLAY_PAGE_NUM) + 1 ) * DISPLAY_PAGE_NUM;
            if (this.totalPage < this.endPage) {
                this.endPage = this.totalPage;
            }
            this.startPage   = ((currentPage - 1) / DISPLAY_PAGE_NUM) * DISPLAY_PAGE_NUM + 1;
            this.prev        = !(this.startPage == 1);
            this.next        = !(this.endPage == this.totalPage);
        }
    }

}
