from datetime import datetime


def normalize_entity(in_dict):
    """Converts BlitzDB Document to standard dictionary

    Parameters
    ----------
    in_dict : dict
        BlitzDB Document-compatible dictionary of values

    Returns
    -------
    dict
        normal dictionary of values, output of to_dictionary function
    """
    out_dict = in_dict.copy()
    if 'pk' in list(in_dict):
        out_dict['id'] = in_dict['pk']
        del out_dict['pk']
    if 'start_time' in list(in_dict):
        out_dict['start_time'] = \
            datetime.strptime(in_dict['start_time'], '%Y-%m-%dT%H:%M:%S.%fZ') \
                if out_dict['start_time'] else None
    if 'end_time' in list(in_dict):
        out_dict['end_time'] = \
            datetime.strptime(in_dict['end_time'], '%Y-%m-%dT%H:%M:%S.%fZ') \
                if out_dict['end_time'] else None
    if 'created_at' in list(in_dict):
        out_dict['created_at'] = datetime.strptime(in_dict['created_at'],
                                                   '%Y-%m-%dT%H:%M:%S.%fZ')
    if 'updated_at' in list(in_dict):
        out_dict['updated_at'] = datetime.strptime(in_dict['updated_at'],
                                                   '%Y-%m-%dT%H:%M:%S.%fZ')
    return out_dict