package io.delphiplatform.api.v3.rdb.service.specification;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;

public class LessThanPropertySpecification<T, V extends Comparable<V>> extends OperationOnPropertySpecification<T> {

    private final String propertyName;
    private final V compareValue;

    public LessThanPropertySpecification(String propertyName, V compareValue) {
        super(null);
        this.propertyName = propertyName;
        this.compareValue = compareValue;
    }

    @Override
    protected boolean canProducePredicate() {
        return compareValue != null;
    }

    @Override
    protected Predicate doOperation(CriteriaBuilder cb, Path<T> path) {
        return cb.lessThan(path.get(propertyName), compareValue);
    }

}
