package com.dbnt.kcscbackend.config.common;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.Transient;
import java.io.Serializable;

@Getter
@Setter
public class BoardParams implements Serializable {
  @Transient
  private String searchCondition;
  @Transient
  private String searchKeyword;
  @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
  @Schema(description = "검색시작일")
  private String searchBgnDe = "";
  @Transient
  @Schema(description = "검색종료일")
  private String searchEndDe = "";
  @Transient
  @Schema(description = "정렬순서(DESC,ASC)")
  private long sortOrdr = 0L;

  @JsonIgnore
  public void setQueryInfo(){
    setFirstIndex((getPageIndex()-1)*getRowCnt());
  }
  @JsonIgnore
  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 - 4;
    if(startNum <= 0){
      startNum = 1;
    }
    setStartNum(startNum);

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