package com.dbnt.sims.config;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Transient;
import java.util.List;

@Getter
@Setter
@NoArgsConstructor
public class BaseModel {
  @Transient
  private List<String> upOrganCdList;
  @Transient
  private List<String> downOrganCdList;
  @Transient
  private Integer pageIndex=1; //요청페이지
  @Transient
  private Integer firstIndex=0;	// 쿼리의 시작 row
  @Transient
  private Integer rowCnt=10;	//한 페이지에 표현되는 row 수
  @Transient
  private Integer startNum=1; // pagination 시작값
  @Transient
  private Integer endNum=5; // pagination 마지막값
  @Transient
  private Integer maxNum; // pagination 최대값
  @Transient
  private Integer contentCnt=0;
  @Transient
  private String dateSelector;
  @Transient
  private String startDate;
  @Transient
  private String endDate;
  @Transient
  private Boolean dashboardFlag = false;

  public void setQueryInfo(){
    setFirstIndex((getPageIndex()-1)*getRowCnt());
  }

  public void setPaginationInfo(){
    int contentCnt = getContentCnt();
    int rowCnt = getRowCnt();
    int maxNum = (int)Math.ceil(((double)contentCnt)/rowCnt);
    if (maxNum==0){
      maxNum = 1;
    }
    setMaxNum(maxNum);

    int pageIndex = getPageIndex();
    int startNum = pageIndex - 2;
    if(startNum <= 0){
      startNum = 1;
    }
    setStartNum(startNum);

    int endNum = startNum + 4;
    if(endNum>maxNum){
      endNum = maxNum;
    }
    setEndNum(endNum);
  }
}
