package cn.axzo.workflow.core.repository.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import org.springframework.util.StringUtils;

import java.util.Collection;

public class BpmnLambdaQueryWrapperX<T> extends LambdaQueryWrapper<T> {
    public BpmnLambdaQueryWrapperX() {
    }

    public BpmnLambdaQueryWrapperX<T> likeIfPresent(SFunction<T, ?> column, String val) {
        return StringUtils.hasText(val) ? (BpmnLambdaQueryWrapperX) super.like(column, val) : this;
    }

    public BpmnLambdaQueryWrapperX<T> inIfPresent(SFunction<T, ?> column, Collection<?> values) {
        return !CollectionUtils.isEmpty(values) ? (BpmnLambdaQueryWrapperX) super.in(column, values) : this;
    }

    public BpmnLambdaQueryWrapperX<T> inIfPresent(SFunction<T, ?> column, Object... values) {
        return !ArrayUtils.isEmpty(values) ? (BpmnLambdaQueryWrapperX) super.in(column, values) : this;
    }

    public BpmnLambdaQueryWrapperX<T> eqIfPresent(SFunction<T, ?> column, Object val) {
        return val != null ? (BpmnLambdaQueryWrapperX) super.eq(column, val) : this;
    }

    public BpmnLambdaQueryWrapperX<T> neIfPresent(SFunction<T, ?> column, Object val) {
        return val != null ? (BpmnLambdaQueryWrapperX) super.ne(column, val) : this;
    }

    public BpmnLambdaQueryWrapperX<T> gtIfPresent(SFunction<T, ?> column, Object val) {
        return val != null ? (BpmnLambdaQueryWrapperX) super.gt(column, val) : this;
    }

    public BpmnLambdaQueryWrapperX<T> geIfPresent(SFunction<T, ?> column, Object val) {
        return val != null ? (BpmnLambdaQueryWrapperX) super.ge(column, val) : this;
    }

    public BpmnLambdaQueryWrapperX<T> ltIfPresent(SFunction<T, ?> column, Object val) {
        return val != null ? (BpmnLambdaQueryWrapperX) super.lt(column, val) : this;
    }

    public BpmnLambdaQueryWrapperX<T> leIfPresent(SFunction<T, ?> column, Object val) {
        return val != null ? (BpmnLambdaQueryWrapperX) super.le(column, val) : this;
    }

    public BpmnLambdaQueryWrapperX<T> betweenIfPresent(SFunction<T, ?> column, Object val1, Object val2) {
        if (val1 != null && val2 != null) {
            return (BpmnLambdaQueryWrapperX) super.between(column, val1, val2);
        } else if (val1 != null) {
            return (BpmnLambdaQueryWrapperX) this.ge(column, val1);
        } else {
            return val2 != null ? (BpmnLambdaQueryWrapperX) this.le(column, val2) : this;
        }
    }

    public BpmnLambdaQueryWrapperX<T> eq(boolean condition, SFunction<T, ?> column, Object val) {
        super.eq(condition, column, val);
        return this;
    }

    public BpmnLambdaQueryWrapperX<T> eq(SFunction<T, ?> column, Object val) {
        super.eq(column, val);
        return this;
    }

    public BpmnLambdaQueryWrapperX<T> orderByDesc(SFunction<T, ?> column) {
        super.orderByDesc(true, column);
        return this;
    }

    public BpmnLambdaQueryWrapperX<T> last(String lastSql) {
        super.last(lastSql);
        return this;
    }

    public BpmnLambdaQueryWrapperX<T> in(SFunction<T, ?> column, Collection<?> coll) {
        super.in(column, coll);
        return this;
    }
}
