package com.agileboot.reader.dto;

import com.agileboot.common.mybatis.core.page.PageQuery;
import com.agileboot.reader.entity.TextFile;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

/**
 * 文本文件查询DTO
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class TextFileQueryDTO extends PageQuery<TextFile> {

    /**
     * 文件名（模糊查询）
     */
    private String fileName;

    /**
     * 状态
     */
    private Integer status;

    @Override
    public LambdaQueryWrapper<TextFile> toQueryWrapper() {
        return Wrappers.lambdaQuery(TextFile.class)
                .like(StringUtils.isNotEmpty(fileName), TextFile::getOriginalFileName, fileName)
                .or()
                .like(StringUtils.isNotEmpty(fileName), TextFile::getDescription, fileName)
                .eq(status != null, TextFile::getStatus, status)
                .orderByDesc(TextFile::getCreateTime);
    }
}

