

package org.sfs.validate;

import io.vertx.core.MultiMap;
import io.vertx.core.json.JsonObject;
import org.sfs.SfsRequest;
import org.sfs.util.HttpRequestValidationException;
import rx.functions.Func1;

import static java.lang.String.format;
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;

public class ValidateParamNotExists implements Func1<SfsRequest, SfsRequest> {


    private final String paramName;

    public ValidateParamNotExists(String paramName) {
        this.paramName = paramName;
    }

    @Override
    public SfsRequest call(SfsRequest httpServerRequest) {
        MultiMap params = httpServerRequest.params();

        String value = params.get(paramName);
        if (value != null) {
            JsonObject jsonObject = new JsonObject()
                    .put("message", format("%s is not supported", paramName));

            throw new HttpRequestValidationException(HTTP_BAD_REQUEST, jsonObject);
        }
        return httpServerRequest;
    }
}