package com.qqchen.deploy.backend.framework.query;

import com.qqchen.deploy.backend.framework.annotation.QueryField;
import com.qqchen.deploy.backend.framework.enums.QueryType;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
public abstract class BaseQuery implements Serializable {

    private Integer pageNum = 1;

    private Integer pageSize = 10;

    private String sortField = "createTime";

    private String sortOrder = "desc";

    // 通用状态查询
    @QueryField(field = "enabled")
    private Boolean enabled;

    @QueryField(field = "deleted", type = QueryType.EQUAL)
    private Boolean deleted;

    // 创建时间范围查询
    @QueryField(field = "createTime", type = QueryType.BETWEEN)
    private DateRange createTimeRange;

    // 更新时间范围查询
    @QueryField(field = "updateTime", type = QueryType.BETWEEN)
    private DateRange updateTimeRange;

    // 创建人查询
    @QueryField(field = "createBy", type = QueryType.EQUAL)
    private String createBy;

    // 更新人查询
    @QueryField(field = "updateBy", type = QueryType.EQUAL)
    private String updateBy;

    // 版本号查询
    @QueryField(field = "version", type = QueryType.EQUAL)
    private Integer version;

    // 便捷方法
    public void setCreateTimeRange(LocalDateTime start, LocalDateTime end) {
        if (start != null || end != null) {
            this.createTimeRange = new DateRange(start, end);
        }
    }

    public void setUpdateTimeRange(LocalDateTime start, LocalDateTime end) {
        if (start != null || end != null) {
            this.updateTimeRange = new DateRange(start, end);
        }
    }
} 