package com.chinaweal.aiccs.aiccs.business.entity.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 *
 * 分页请求体
 *
 * @author zhouxy
 * @since 2025-12-29
 */
@Data
@ApiModel("分页请求体")
public class BasePageRequestDto implements Serializable {

    private static final long serialVersionUID = 1L;

    private static final Integer DEFAULT_PAGE = 1;
    private static final Integer DEFAULT_PAGE_SIZE = 10;
    private static final String ORDER_DEFAULT = "update_time";
    private static final String COMMA = ",";

    @ApiModelProperty("当前分页（默认1）")
    private Integer curPage;

    @ApiModelProperty("分页大小（默认10）")
    private Integer pageSize;

    @ApiModelProperty("排序字段（update_time）")
    private String orderField;

    @ApiModelProperty("排序规则（默认desc）")
    private String orderingRule;

    public BasePageRequestDto checkDefault(Integer curPageDefault, Integer pageSizeDefault, String orderFieldDefault) {
        if (curPageDefault == null) {
            curPageDefault = 1;
        }

        if (pageSizeDefault == null) {
            pageSizeDefault = DEFAULT_PAGE_SIZE;
        }

        if (StringUtils.isBlank(orderFieldDefault)) {
            orderFieldDefault = "update_time";
        }

        this.curPage = this.curPage == null ? curPageDefault : this.curPage;
        this.pageSize = this.pageSize == null ? pageSizeDefault : this.pageSize;
        this.orderField = StringUtils.isBlank(this.orderField) ? orderFieldDefault : this.orderField;
        return this;
    }
}
