package com.zsc.edu.gateway.modules.iot.product.query;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author zhuang
 */
@Data
public class ProductQuery {
    /**
     * 设备名称
     */
    public String name;

    /**
     * 产品分类
     */
    public String type;

    /**
     * 接入方式
     */
    public List<Product.LinkType> links;

    public LambdaQueryWrapper<Product> wrapper() {
        LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(this.name), Product::getName, this.name);
        queryWrapper.eq(StringUtils.hasText(this.type), Product::getProductType, this.type);
        if (Objects.nonNull(this.links) && !this.links.isEmpty()) {
            queryWrapper.in(Product::getLink, this.links);
        }
        return queryWrapper;
    }

    public LambdaQueryWrapper<Product> fuzzyWrapper() {
        LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(this.name), Product::getName, this.name);
        return queryWrapper;
    }
}
