function SearchParameterDto() {
  this.page = 1
  this.itemCountPerPage = 20
  this.totalItemCount = 0
  this.pageList = [1]
  this.parameters = {}
}

SearchParameterDto.prototype.calculatePageList = function (currentPage, currentItemCountPerPage = 20, currentTotalItemCount) {
  this.itemCountPerPage = currentItemCountPerPage
  this.totalItemCount = currentTotalItemCount
  if (this.totalItemCount > 0) {
    let pageSize = Math.ceil(this.totalItemCount / this.itemCountPerPage) + 1
    pageSize = pageSize < 1 ? 1 : pageSize
    this.page = currentPage >= 1 && currentPage <= pageSize ? currentPage : 1
    let startPage = Math.floor((this.page - 1) / 10) * 10 + 1
    let lastPage = Math.min(startPage + 9, pageSize)
    let pageArray = []
    for (let i = startPage; i <= lastPage; i++) {
      pageArray.push(i)
    }
    this.pageList = pageArray
  } else {
    this.pageList = [1]
    this.page = 1
  }
}

SearchParameterDto.prototype.setParameter = function (key, value) {
  this.parameters[key] = value
}

SearchParameterDto.prototype.getParameter = function (key) {
  return this.parameters[key]
}

SearchParameterDto.prototype.clearParameter = function () {
  this.parameters = {}
}

export default SearchParameterDto
