public <S extends Enum<S>> S asEnum(Map<String, ValueReference> parameters, Class<S> type) {
        final String value;
        switch (valueType()) {
            case STRING:
                value = String.class.cast(value());
                break;
            case PARAMETER:
                value = asType(parameters, String.class);
                break;
            default:
                throw new IllegalStateException("Expected value reference of type STRING or PARAMETER but got " + valueType());
        }

        return Enum.valueOf(type, value);
    }
@Test
    public void asEnum() {
        assertThat(ValueReference.of(TestEnum.A).asEnum(Collections.emptyMap(), TestEnum.class)).isEqualTo(TestEnum.A);
        assertThatThrownBy(() -> ValueReference.of("Test").asEnum(Collections.emptyMap(), TestEnum.class))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessage("No enum constant org.graylog2.contentpacks.model.entities.references.ValueReferenceTest.TestEnum.Test");
        assertThatThrownBy(() -> ValueReference.of(0).asEnum(Collections.emptyMap(), TestEnum.class))
                .isInstanceOf(IllegalStateException.class)
                .hasMessage("Expected value reference of type STRING or PARAMETER but got INTEGER");
    }