package org.nl.common.enums;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.nl.common.domain.query.LConsumer;

import java.util.Collection;

/*
 * @author ZZQ
 * @Date 2022/12/14 8:26 下午
 */
@Getter
public enum QueryTEnum {
    //
    EQ((q, k, v) -> { q.eq(k[0],v); }),
    IN((q, key, o) -> { if (o instanceof Collection){ q.in(key[0],(Collection) o); } }),
    LK((q, keys, o) -> { for (String key : keys) { q.like(key,o); } }),
    LE((q, k, v) -> { q.le(k[0],v); }),
    BY((q, k, v) -> { q.orderByDesc(k[0],v); }),
    NO((q, k, v) -> { q.isNull(k[0]); }),
    LT((q, k, v) -> { q.lt(k[0],v); }),
    OREQ((q, k, v) -> { if (StringUtils.isBlank((String)v)){ q.isNull(k[0]); }else { q.eq(k[0],v); } });

    private LConsumer<QueryWrapper,String[], Object> doP;

    QueryTEnum(LConsumer<QueryWrapper,String[], Object> doP) {
        this.doP = doP;
    }

    public static void build(QueryTEnum type, QueryWrapper q, String[] k , Object v){
        type.getDoP().accept(q,k,v);
    }
}
