package com.jy.framework.model.base;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.framework.model.validation.BatchDeleteGroup;
import com.jy.framework.model.validation.DeleteGroup;
import com.jy.framework.model.validation.DetailGroup;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

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

@Getter
@Setter
@SuppressWarnings("unused")
public class BaseSelectDto implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 通用id
     */
    @NotNull(groups = {DetailGroup.class, DeleteGroup.class})
    private Long id;

    /**
     * 通用id集合
     */
    @NotEmpty(groups = BatchDeleteGroup.class)
    private List<Long> idList;

    /**
     * 页数
     */
    private Integer pageNum;

    /**
     * 每页条数
     */
    private Integer pageSize;

    /**
     * 是否查询全部数据
     */
    private Boolean searchAll;

    /**
     * 返回分页实体
     */
    public <T> Page<T> getPage() {
        if (Boolean.TRUE.equals(searchAll)) {
            return new Page<>(1, Long.MAX_VALUE, false);
        } else {
            return new Page<>(getPageNum(), getPageSize());
        }
    }

    public Integer getPageNum() {
        return ObjectUtil.defaultIfNull(pageNum, 1);
    }

    public Integer getPageSize() {
        return ObjectUtil.defaultIfNull(pageSize, 10);
    }

}
