from pprint import pprint

from django.db.models import Q

from transfer.models import Accounts, Identities
from transfer.serializers.account import UserSerializer
from transfer.serializers.user_social_auth import UserSocialAuthSerializer

STOP_LIST = (
    # 'cyril@tomatic.net',
    # 'cyril2@tomatic.net',
    # 'd.sadykova@id-east.ru',
    # 'd.sadykova@octopod.ru',
    # 'n.yurchenko@id-east.ru',
)


def transfer_user():
    # queryset = Profiles.objects.all()
    # queryset = queryset.annotate(nickname=F('account__nickname'))
    # queryset = queryset.annotate(email=F('account__email'))

    queryset = Accounts.objects.exclude(email__in=STOP_LIST)

    serialized_data = UserSerializer(data=list(queryset.values()), many=True)

    if serialized_data.is_valid():
        serialized_data.save()
    else:
        pprint(f'News serializer errors: {serialized_data.errors}')


def transfer_identities():
    queryset = Identities.objects.exclude(
        Q(account_id__isnull=True) |
        # Q(account__confirmed_at__isnull=True) |
        Q(account__email__in=STOP_LIST)
    ).values_list(
        'account_id',
        'provider',
        'uid',
    )

    serialized_data = UserSocialAuthSerializer(data=list(queryset.values()), many=True)

    if serialized_data.is_valid():
        serialized_data.save()
    else:
        pprint(f'UserSocialAuth serializer errors: {serialized_data.errors}')


data_types = {
    'account': [transfer_user],
    'identities': [transfer_identities],
}
