from datetime import (
    date,
    datetime,
)
from inspect import Signature
from typing import (
    Any,
    Type,
)

import iso8601


def to_camel_case(snake_str):
    components = snake_str.split('_')
    return components[0] + ''.join(x.title() for x in components[1:])


def to_snake_case(camel_str: str):
    ret = camel_str[0].lower()
    for c in camel_str[1:]:
        if c.isupper():
            ret += '_' + c.lower()
        else:
            ret += c

    return ret


primitive_types = {
        bool: bool,
        int: int,
        str: str,
        float: float,
        Signature.empty: str,
        datetime: iso8601.parse_date,
        date: lambda x: iso8601.parse_date(x).date(),
    }


def is_primitive(t: Type) -> bool:
    return t in primitive_types


def transform_primitive(t: Type, value: Any) -> Any:
    return primitive_types[t](value)
