package org.minager.core.security;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import org.springframework.http.HttpMethod;

/**
 * Route for filter matching.
 * 
 * @author Takiguchi
 *
 */
public class Route {
	/** The regex to match urls. */
	private String url;
	/** The http method to match. Use a {@link Optional#empty()} to match all methods. */
	private Optional<List<HttpMethod>> method;

	/**
	 * Instanciate a vierge route.
	 */
	public Route() {
		super();
		url = "";
		method = Optional.empty();
	}
	
	/**
	 * Instanciate a route for all http methods.
	 * 
	 * @param pUrl
	 *            The regex to match urls.
	 */
	public Route(final String pUrl) {
		this();
		this.url = pUrl;
	}

	/**
	 * Instanciate a route for methods given in parameters
	 * 
	 * @param pUrl
	 *            The regex to match urls.
	 * @param pMethod
	 *            The http method to match. Use a {@link Optional#empty()} to match
	 *            all methods.
	 */
	public Route(final String pUrl, final HttpMethod... pMethods) {
		this(pUrl);
		this.method = Optional.of(Arrays.asList(pMethods));
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Optional<List<HttpMethod>> getMethod() {
		return method;
	}

	public void setMethod(HttpMethod pMethods) {
		this.method = Optional.of(Arrays.asList(pMethods));
	}
	
}
