import datetime

from src.internals.serializers import unsafe_dumper, unsafe_loader


def serialize_account(account, dumper=unsafe_dumper):
    return dumper(account)


def deserialize_account(account, loader=unsafe_loader):
    return rebuild_account_fields(loader(account))


def prepare_account_fields(account):
    account["created_at"] = account["created_at"].isoformat()
    return account


def rebuild_account_fields(account):
    if not account:
        return None
    account["created_at"] = datetime.datetime.fromisoformat(account["created_at"])
    return account
