package com.mcwl.common.core.page;

import com.mcwl.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotNull;

/**
 * 分页数据
 * 
 * @author mcwl
 */
@ApiModel("分页数据")
public class PageDomain
{
    /** 当前记录起始索引 */
    @NotNull(message = "当前记录起始索引不能为空")
    @ApiModelProperty(value = "当前记录起始索引",required = true)
    private Integer pageNum;

    /** 每页显示记录数 */
    @NotNull(message = "每页显示记录数不能为空")
    @ApiModelProperty(value = "每页显示记录数",required = true)
    private Integer pageSize;

    /** 排序列 */
    @ApiModelProperty(value = "排序列")
    private String orderByColumn;

    /** 排序的方向desc或者asc */
    @ApiModelProperty(hidden = true)
    private String isAsc = "asc";

    /** 分页参数合理化 */
    @ApiModelProperty(hidden = true)
    private Boolean reasonable = true;

    public String getOrderBy()
    {
        if (StringUtils.isEmpty(orderByColumn))
        {
            return "";
        }
        return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc;
    }

    public Integer getPageNum()
    {
        return pageNum;
    }

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

    public Integer getPageSize()
    {
        return pageSize;
    }

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

    public String getOrderByColumn()
    {
        return orderByColumn;
    }

    public void setOrderByColumn(String orderByColumn)
    {
        this.orderByColumn = orderByColumn;
    }

    public String getIsAsc()
    {
        return isAsc;
    }

    public void setIsAsc(String isAsc)
    {
        if (StringUtils.isNotEmpty(isAsc))
        {
            // 兼容前端排序类型
            if ("ascending".equals(isAsc))
            {
                isAsc = "asc";
            }
            else if ("descending".equals(isAsc))
            {
                isAsc = "desc";
            }
            this.isAsc = isAsc;
        }
    }

    public Boolean getReasonable()
    {
        if (StringUtils.isNull(reasonable))
        {
            return Boolean.TRUE;
        }
        return reasonable;
    }

    public void setReasonable(Boolean reasonable)
    {
        this.reasonable = reasonable;
    }
}
