package top.baogutang.common.domain;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: nikooh
 * @date: 2024/02/22 : 11:22
 */
@Data
public class PageParam implements Serializable {

    private static final long serialVersionUID = 5353838683455028860L;

    private Integer pageNum;

    private Integer pageSize;

    @ApiModelProperty("排序条件")
    private List<OrderBy> orders = new ArrayList<>();

    @ApiModel
    @Data
    public static class OrderBy implements Serializable {

        private static final long serialVersionUID = -2936335557980068706L;

        @ApiModelProperty("排序列名")
        private String columnName;

        @ApiModelProperty("是否降序")
        private boolean desc;

    }

    public Integer getPageNum() {
        pageNum = pageNum == null ? 1 : pageNum;
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        if (pageSize == null || pageSize > 100) {
            pageSize = 10;
        }
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

}
