# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-11-13 22:26
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid


def create_measurement_data(apps, schema_editor):
    app = apps.get_model('supplements', 'Measurement')

    # pycharm is amazing.
    dict_list = [
        {
            'name': 'milligram',
            'short_name': 'mg',
            'is_liquid': False,
        },
        {
            'name': 'gram',
            'short_name': 'g',
            'is_liquid': False,
        },
        {
            'name': 'milliliter',
            'short_name': 'ml',
            'is_liquid': True,
        },
        {
            'name': 'liter',
            'short_name': 'l',
            'is_liquid': True,
        },
        {
            'name': 'pill',
            'short_name': 'pill',
            'is_liquid': False,
        },
    ]

    for measurement in dict_list:
        app.objects.create(**measurement)


class Migration(migrations.Migration):

    replaces = [('supplements', '0001_initial'), ('supplements', '0002_auto_20170605_1603'), ('supplements', '0003_data_migrations_for_measurements'), ('supplements', '0004_auto_20171019_0120'), ('supplements', '0005_adjust_supplement_stack_to_include_quantity'), ('supplements', '0006_auto_20171022_0700'), ('supplements', '0007_auto_20171023_0402')]

    initial = True

    dependencies = [
        ('vendors', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Ingredient',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('name', models.CharField(max_length=300)),
                ('half_life_minutes', models.PositiveIntegerField(blank=True, null=True)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='IngredientComposition',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('quantity', models.FloatField(default=1)),
                ('ingredient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='supplements.Ingredient')),
            ],
            options={
                'verbose_name': 'Ingredient Composition',
                'ordering': ['user', 'ingredient__name'],
                'verbose_name_plural': 'Ingredient Compositions',
            },
        ),
        migrations.CreateModel(
            name='Measurement',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('name', models.CharField(max_length=100)),
                ('short_name', models.CharField(blank=True, max_length=100, null=True)),
                ('is_liquid', models.BooleanField(default=False)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='Supplement',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('name', models.CharField(max_length=300)),
                ('ingredient_compositions', models.ManyToManyField(blank=True, to='supplements.IngredientComposition')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Supplement',
                'ordering': ['user', 'name'],
                'verbose_name_plural': 'Supplements',
            },
        ),
        migrations.AddField(
            model_name='ingredientcomposition',
            name='measurement',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='supplements.Measurement'),
        ),
        migrations.AddField(
            model_name='ingredientcomposition',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
        ),
        migrations.AlterUniqueTogether(
            name='supplement',
            unique_together=set([('user', 'name')]),
        ),
        migrations.AlterField(
            model_name='ingredientcomposition',
            name='created',
            field=models.DateTimeField(auto_now_add=True),
        ),
        migrations.AlterUniqueTogether(
            name='ingredientcomposition',
            unique_together=set([('user', 'ingredient', 'measurement', 'quantity')]),
        ),
        migrations.AlterField(
            model_name='ingredient',
            name='created',
            field=models.DateTimeField(auto_now_add=True),
        ),
        migrations.AlterUniqueTogether(
            name='ingredient',
            unique_together=set([('name', 'user')]),
        ),
        migrations.RunPython(
            code=create_measurement_data,
        ),
        migrations.CreateModel(
            name='UserSupplementStack',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('name', models.CharField(max_length=300)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Supplements Stack',
                'ordering': ['user', 'name'],
                'verbose_name_plural': 'Supplements Stacks',
            },
        ),
        migrations.AlterUniqueTogether(
            name='usersupplementstack',
            unique_together=set([('user', 'name')]),
        ),
        migrations.CreateModel(
            name='UserSupplementStackComposition',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('quantity', models.FloatField(default=1)),
                ('stack', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='supplements.UserSupplementStack')),
                ('supplement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='supplements.Supplement')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.AlterUniqueTogether(
            name='usersupplementstackcomposition',
            unique_together=set([('supplement', 'stack')]),
        ),
        migrations.AlterField(
            model_name='usersupplementstackcomposition',
            name='stack',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='compositions', to='supplements.UserSupplementStack'),
        ),
        migrations.AlterUniqueTogether(
            name='usersupplementstackcomposition',
            unique_together=set([('user', 'supplement', 'stack')]),
        ),
    ]
