# Path: graphscale/grapple/enum.py
# class GraphQLPythonEnumType(GraphQLEnumType):
#     def __init__(self, python_enum_type: Any, description: str=None) -> None:
#         self.python_enum_type = python_enum_type
#         name = python_enum_type.__name__
#         values = OrderedDict()  # type: OrderedDict[Any, GraphQLEnumValue]
#         for enum_value in python_enum_type.__members__.keys():
#             values[enum_value] = GraphQLEnumValue(value=enum_value)
#         super().__init__(name, values, description=description)
# 
#     def serialize(self, value: Enum) -> str:
#         return value.name
# 
#     def parse_value(self, value: str) -> Enum:
#         return self.python_enum_type(value)  # type: ignore
# 
#     def parse_literal(self, value_ast: Value) -> Enum:
#         if not isinstance(value_ast, EnumValue):
#             return None
#         return self.python_enum_type(value_ast.value)  # type: ignore


from enum import Enum
from typing import Callable, Any
from graphql import GraphQLObjectType, GraphQLField, graphql, GraphQLSchema, GraphQLArgument
from graphscale.grapple.enum import GraphQLPythonEnumType
import pytest

pytestmark = pytest.mark.asyncio


class EnumTest(Enum):
    VALUE_ONE = 'VALUE_ONE'
    VALUE_TWO = 'VALUE_TWO'


def define_schema(resolver: Callable, enumType: GraphQLObjectType) -> GraphQLSchema:
    def resolve_input(_obj: Any, args: dict, *_: Any) -> Any:
        assert isinstance(args['testEnumArg'], EnumTest)
        return args['testEnumArg']

    query_type = GraphQLObjectType(
        name='Query',
        fields={
            'testEnum':
            GraphQLField(type=enumType, resolver=resolver),
            'testEnumArg':
            GraphQLField(
                type=enumType,
                args={'testEnumArg': GraphQLArgument(type=enumType)},
                resolver=resolve_input
            )
        }
    )
    return GraphQLSchema(query=query_type)



# Path: graphscale/grapple/enum.py
# class GraphQLPythonEnumType(GraphQLEnumType):
#     def __init__(self, python_enum_type: Any, description: str=None) -> None:
#         self.python_enum_type = python_enum_type
#         name = python_enum_type.__name__
#         values = OrderedDict()  # type: OrderedDict[Any, GraphQLEnumValue]
#         for enum_value in python_enum_type.__members__.keys():
#             values[enum_value] = GraphQLEnumValue(value=enum_value)
#         super().__init__(name, values, description=description)
# 
#     def serialize(self, value: Enum) -> str:
#         return value.name
# 
#     def parse_value(self, value: str) -> Enum:
#         return self.python_enum_type(value)  # type: ignore
# 
#     def parse_literal(self, value_ast: Value) -> Enum:
#         if not isinstance(value_ast, EnumValue):
#             return None
#         return self.python_enum_type(value_ast.value)  # type: ignore


# Path: tests/test_enum.py
from enum import Enum
from typing import Callable, Any
from graphql import GraphQLObjectType, GraphQLField, graphql, GraphQLSchema, GraphQLArgument
from graphscale.grapple.enum import GraphQLPythonEnumType
import pytest


pytestmark = pytest.mark.asyncio


class EnumTest(Enum):
    VALUE_ONE = 'VALUE_ONE'
    VALUE_TWO = 'VALUE_TWO'


def define_schema(resolver: Callable, enumType: GraphQLObjectType) -> GraphQLSchema:
    def resolve_input(_obj: Any, args: dict, *_: Any) -> Any:
        assert isinstance(args['testEnumArg'], EnumTest)
        return args['testEnumArg']

    query_type = GraphQLObjectType(
        name='Query',
        fields={
            'testEnum':
            GraphQLField(type=enumType, resolver=resolver),
            'testEnumArg':
            GraphQLField(
                type=enumType,
                args={'testEnumArg': GraphQLArgument(type=enumType)},
                resolver=resolve_input
            )
        }
    )
    return GraphQLSchema(query=query_type)



GraphQLEnumTest = GraphQLPythonEnumType(EnumTest)