# Generated by Django 3.2.7 on 2021-09-04 19:36

from django.db import migrations, models, transaction
import django.db.models.deletion
from django.contrib.auth.models import User
import random

def create_users(apps, schema_editor):
    with transaction.atomic():
        users = [
            {
                'first_name': 'Sebastián',
                'last_name': 'Castañeda',
                'email': 'sebastian@mail.com',
                'username': 'sebastianc',
                'position': 'Software Developer'
            },
            {
                'first_name': 'Valentina',
                'last_name': 'Ibarra',
                'email': 'valentina@mail.com',
                'username': 'valentinai',
                'position': 'Recruiter'
            },
            {
                'first_name': 'Sara',
                'last_name': 'Hincapié',
                'email': 'sara@mail.com',
                'username': 'sarah',
                'position': 'Product Owner'
            },
            {
                'first_name': 'Juan',
                'last_name': 'Ciro',
                'email': 'juan@mail.com',
                'username': 'juanc',
                'position': 'CTO'
            },
            {
                'first_name': 'David',
                'last_name': 'Leal',
                'email': 'david@mail.com',
                'username': 'david',
                'position': 'Tech Lead'
            }
        ]
        Information = apps.get_model('profiles', 'Information')
        Skills = apps.get_model('profiles', 'Skills')
        for user in users:
            new_user = User()
            new_user.first_name = user['first_name']
            new_user.last_name = user['last_name']
            new_user.email = user['email']
            new_user.username = user['username']
            new_user.set_password('factored2021')
            new_user.save()
            new_information = Information()
            new_information.user_id = User.objects.get(username = user['username']).id
            new_information.position = user['position']
            new_information.avatar = 'https://avatars.dicebear.com/api/avataaars/' + user['username'] + '.svg'
            new_information.save()
            new_skills = Skills()
            new_skills.user_id = User.objects.get(username = user['username']).id
            new_skills.python_xp = random.randint(1,99)
            new_skills.javascript_xp = random.randint(1,99)
            new_skills.sql_xp = random.randint(1,99)
            new_skills.java_xp = random.randint(1,99)
            new_skills.spark_xp = random.randint(1,99)
            new_skills.html_xp = random.randint(1,99)
            new_skills.others_xp = random.randint(1,99)
            new_skills.save()

class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('auth', '0012_alter_user_first_name_max_length'),
    ]

    operations = [
        migrations.CreateModel(
            name='Information',
            fields=[
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, serialize=False, to='auth.user')),
                ('position', models.CharField(max_length=100)),
                ('avatar', models.CharField(max_length=100)),
            ],
        ),
        migrations.CreateModel(
            name='Skills',
            fields=[
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, serialize=False, to='auth.user')),
                ('python_xp', models.IntegerField()),
                ('javascript_xp', models.IntegerField()),
                ('sql_xp', models.IntegerField()),
                ('java_xp', models.IntegerField()),
                ('spark_xp', models.IntegerField()),
                ('html_xp', models.IntegerField()),
                ('others_xp', models.IntegerField()),
            ],
        ),
        migrations.RunPython(create_users)
    ]
