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

import java.util.List;

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

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


    private final V compareValue;
    private final String propertyName;

    public GreaterThanOrEqualToPropertySpecification(String propertyName, V compareValue, List<String> joins) {
        super(joins);
        this.compareValue = compareValue;
        this.propertyName = propertyName;
    }


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

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

}
