from django.contrib.auth.hashers import make_password
from django.core.management import BaseCommand
from tqdm import tqdm

from account.models import User

users = [
    {
        "email": "poizonstore@mail.ru",
        "password": "219404Poizon",
        "first_name": "Илья",
        "middle_name": "Сергеевич",
        "last_name": "Савочкин",
        "role": User.ADMIN,
        "is_staff": True
    },
    {
        "email": "poizonmanager1@mail.ru",
        "password": "poizonm1",
        "first_name": "Патрик",
        "middle_name": "Сергеевич",
        "last_name": "Стар",
        "role": User.PRODUCT_MANAGER
    },
    {
        "email": "poizonorder1@mail.ru",
        "password": "2193071Po1",
        "first_name": "Гоша",
        "middle_name": "Альбах",
        "last_name": "Абызов",
        "role": User.ORDER_MANAGER
    }
]


class Command(BaseCommand):
    help = ''' Create test data '''

    def create_test_users(self):
        for user_data in tqdm(users, desc="Creating users"):
            user_data['password'] = make_password(user_data['password'])
            User.objects.get_or_create(email=user_data['email'], defaults=user_data)

    def handle(self, *args, **kwargs):
        self.create_test_users()

