package gaf3.core.web.condition;

import org.springframework.util.MultiValueMap;

/**
 * Parses and matches a single param expression to a request.
 */
public class ParamExpression extends AbstractNameValueExpression<String> {

    public ParamExpression(String expression) {
        super(expression);
    }

    @Override
    protected boolean isCaseSensitiveName() {
        return true;
    }

    @Override
    protected String parseValue(String valueExpression) {
        return valueExpression;
    }

    @Override
    protected boolean matchName(MultiValueMap<String, String> queryParams) {
        return queryParams.containsKey(this.name);
    }

    @Override
    protected boolean matchValue(MultiValueMap<String, String> queryParams) {
        return (this.value != null &&
                this.value.equals(queryParams.getFirst(this.name)));
    }
}
