# Generated by Django 3.0.8 on 2020-07-08 15:42

import django.db.models.deletion
from django.db import migrations, models

DEFAULT_CATEGORIES = {
    'FASHION': ['Shoes', 'Clothes', 'Bags'],
    'ELECTRONICS': ['Speakers', 'Television', 'Mobiles', 'Headphones', 'Camera'],
    'BEAUTY & HEALTH': ['Medicines', 'Make-up', 'Diet % Nutrition'],
    'Books': ['School books', 'Fiction books', 'Textbooks'],
}


def populate_default_data(apps, schema):
    Category = apps.get_model('products', 'Category')
    SubCategory = apps.get_model('products', 'SubCategory')
    Product = apps.get_model('products', 'Product')
    for category, sub_categories in DEFAULT_CATEGORIES.items():
        category = Category.objects.create(name=category)
        for sub_category in sub_categories:
            sub_category = SubCategory.objects.create(category=category, name=sub_category)
            Product.objects.create(sub_category=sub_category, name=f'Product {sub_category.name}')


class Migration(migrations.Migration):
    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Category',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False,
                                        verbose_name='ID')),
                ('added_on', models.DateTimeField(auto_now_add=True)),
                ('updated_on', models.DateTimeField(auto_now=True)),
                ('name',
                 models.CharField(help_text='Provide category name', max_length=256, unique=True)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='SubCategory',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False,
                                        verbose_name='ID')),
                ('added_on', models.DateTimeField(auto_now_add=True)),
                ('updated_on', models.DateTimeField(auto_now=True)),
                ('name', models.CharField(help_text='Provide sub category name', max_length=256,
                                          unique=True)),
                ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
                                               to='products.Category')),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='Product',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False,
                                        verbose_name='ID')),
                ('added_on', models.DateTimeField(auto_now_add=True)),
                ('updated_on', models.DateTimeField(auto_now=True)),
                ('name',
                 models.CharField(help_text='Provide prodct name', max_length=256, unique=True)),
                ('sub_category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
                                                   to='products.SubCategory')),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.RunPython(populate_default_data)
    ]
