# Path: graphscale/check.py
# def isinst(obj: Any, ttype: Type, _msg: str=None) -> None:
# def invariant(condition: Any, msg: str) -> None:
# def failed(msg: str) -> NoReturn:
# 
# Path: graphscale/utils.py
# def is_camel_case(string: str) -> bool:
#     """Is the string potentially camel case? Only checks for capital letters currently"""
#     return bool(re.search('[A-Z]', string))
# 
# def to_snake_case(camel_case: str) -> str:
#     """Convert a camel case string to snake case. e.g. fooBar ==> foo_bar"""
#     with_underscores = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', camel_case)
#     return re.sub('([a-z0-9])([A-Z])', r'\1_\2', with_underscores).lower()


from datetime import datetime
from enum import Enum, auto
from typing import NamedTuple, List, Any, Union
from uuid import UUID
from graphql.language.ast import (
    EnumTypeDefinition, InputObjectTypeDefinition, ListType, NamedType, NonNullType,
    ObjectTypeDefinition, IntValue, StringValue, BooleanValue, Node, TypeDefinition, Value,
    InputValueDefinition, Directive, FieldDefinition, Type
)
from graphql.language.parser import parse
from graphql.language.source import Source
from graphscale import check
from graphscale.utils import is_camel_case, to_snake_case


FIELD_VARIETAL_MAPPING = {
    'custom': FieldVarietal.CUSTOM,
    'customGen': FieldVarietal.CUSTOM_GEN,
    'customMutation': FieldVarietal.CUSTOM_MUTATION,
    'readPent': FieldVarietal.READ_PENT,
    'createPent': FieldVarietal.CREATE_PENT,
    'deletePent': FieldVarietal.DELETE_PENT,
    'updatePent': FieldVarietal.UPDATE_PENT,
    'browsePents': FieldVarietal.BROWSE_PENTS,
    'genFromStoredId': FieldVarietal.GEN_FROM_STORED_ID,
    'edgeToStoredId': FieldVarietal.EDGE_TO_STORED_ID,
}


def get_field_varietal(graphql_field: FieldDefinition) -> FieldVarietal:
    check.isinst(graphql_field, FieldDefinition)
    for directive_name, varietal_enum in FIELD_VARIETAL_MAPPING.items():
        if has_directive(graphql_field, directive_name):
            return varietal_enum

    return FieldVarietal.VANILLA


def get_field_varietal_data(
    graphql_field: FieldDefinition, field_varietal: FieldVarietal
) -> FieldVarietalsUnion:
    check.isinst(graphql_field, FieldDefinition)
    if field_varietal == FieldVarietal.EDGE_TO_STORED_ID:

# Path: graphscale/check.py
# def isinst(obj: Any, ttype: Type, _msg: str=None) -> None:
# def invariant(condition: Any, msg: str) -> None:
# def failed(msg: str) -> NoReturn:
# 
# Path: graphscale/utils.py
# def is_camel_case(string: str) -> bool:
#     """Is the string potentially camel case? Only checks for capital letters currently"""
#     return bool(re.search('[A-Z]', string))
# 
# def to_snake_case(camel_case: str) -> str:
#     """Convert a camel case string to snake case. e.g. fooBar ==> foo_bar"""
#     with_underscores = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', camel_case)
#     return re.sub('([a-z0-9])([A-Z])', r'\1_\2', with_underscores).lower()


# Path: graphscale/grapple/parser.py
from datetime import datetime
from enum import Enum, auto
from typing import NamedTuple, List, Any, Union
from uuid import UUID
from graphql.language.ast import (
    EnumTypeDefinition, InputObjectTypeDefinition, ListType, NamedType, NonNullType,
    ObjectTypeDefinition, IntValue, StringValue, BooleanValue, Node, TypeDefinition, Value,
    InputValueDefinition, Directive, FieldDefinition, Type
)
from graphql.language.parser import parse
from graphql.language.source import Source
from graphscale import check
from graphscale.utils import is_camel_case, to_snake_case



FIELD_VARIETAL_MAPPING = {
    'custom': FieldVarietal.CUSTOM,
    'customGen': FieldVarietal.CUSTOM_GEN,
    'customMutation': FieldVarietal.CUSTOM_MUTATION,
    'readPent': FieldVarietal.READ_PENT,
    'createPent': FieldVarietal.CREATE_PENT,
    'deletePent': FieldVarietal.DELETE_PENT,
    'updatePent': FieldVarietal.UPDATE_PENT,
    'browsePents': FieldVarietal.BROWSE_PENTS,
    'genFromStoredId': FieldVarietal.GEN_FROM_STORED_ID,
    'edgeToStoredId': FieldVarietal.EDGE_TO_STORED_ID,
}


def get_field_varietal(graphql_field: FieldDefinition) -> FieldVarietal:
    check.isinst(graphql_field, FieldDefinition)
    for directive_name, varietal_enum in FIELD_VARIETAL_MAPPING.items():
        if has_directive(graphql_field, directive_name):
            return varietal_enum

    return FieldVarietal.VANILLA


def get_field_varietal_data(
    graphql_field: FieldDefinition, field_varietal: FieldVarietal
) -> FieldVarietalsUnion:
    check.isinst(graphql_field, FieldDefinition)
    if field_varietal == FieldVarietal.EDGE_TO_STORED_ID:

        dir_ast = get_directive(graphql_field, 'edgeToStoredId')