package cz.senslog.analytics.server.ws;

public enum ContentType {
    JSON    ("application/json"),
    GEOJSON ("application/geo+json")
    ;

    private final String contentType;

    ContentType(String contentType) {
        this.contentType = contentType;
    }

    public static ContentType of(String format) {
        return valueOf(format.toUpperCase());
    }

    public static ContentType ofType(String contentType) {
        for (ContentType value : values()) {
            if (value.contentType.equalsIgnoreCase(contentType)) {
                return value;
            }
        }
        throw new IllegalArgumentException(String.format("No enum constant %s for the type '%s'.", ContentType.class.getName(), contentType));
    }

    public String contentType() {
        return contentType;
    }

    public static String[] contentTypes() {
        return contentTypes(values());
    }

    public static String[] contentTypes(ContentType... types) {
        String[] values = new String[types.length];
        for (ContentType value : types) {
            values[value.ordinal()] = value.contentType;
        }
        return values;
    }
}