# Generated by Django 3.2.9 on 2021-11-06 16:58
from django.db import migrations
from faker import Faker
from faker.generator import random


def create_demo_data(apps, schema_editor):
    fake = Faker(locale="ru-RU")

    Page = apps.get_model("decision", "Page")
    Content = apps.get_model("content", "Content")

    Audio = apps.get_model("content", "Audio")
    Text = apps.get_model("content", "Text")
    Video = apps.get_model("content", "Video")

    contents = [Audio, Text, Video]

    for i in range(50):
        page = Page.objects.create(title=fake.sentence())

        for j in range(random.randint(1, 10)):
            content_model = random.choice(contents)
            if content_model == Audio:
                content = content_model.objects.create(title=fake.sentence(),
                                                       bitrate=random.randint(10000, 100000),
                                                       bit_in_second=random.randint(1000, 1000000),
                                                       link=fake.url())
                Content.objects.create(page=page,
                                       content_audio=content)
            elif content_model == Text:
                content = content_model.objects.create(title=fake.sentence(),
                                                       text=fake.text())
                Content.objects.create(page=page,
                                       content_text=content)
            elif content_model == Video:
                content = content_model.objects.create(title=fake.sentence(),
                                                       link=fake.url(),
                                                       link_subtitles=fake.url())
                Content.objects.create(page=page,
                                       content_video=content)


class Migration(migrations.Migration):
    dependencies = [
        ('decision', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(create_demo_data)
    ]
