class ColorFunctions {

    @ScalarFunction
    @LiteralParameters("x")
    @SqlType(ColorType.NAME)
    public static long color(@SqlType("varchar(x)") Slice color)
    {
        int rgb = parseRgb(color);

        if (rgb != -1) {
            return rgb;
        }

        // encode system colors (0-15) as negative values, offset by one
        try {
            SystemColor systemColor = SystemColor.valueOf(upper(color).toStringUtf8());
            int index = systemColor.getIndex();
            return -(index + 1);
        }
        catch (IllegalArgumentException e) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid color: '%s'", color.toStringUtf8()), e);
        }
    }

    private  ColorFunctions();

}