# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2018-03-05 18:20
from __future__ import unicode_literals

from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django.db.models.manager
import django.utils.timezone
import django_extensions.db.fields

from mtp.apps.common.management import create_ordered_contenttypes
import mtp.apps.ideas.managers
import mtp.apps.trainings.models.sessions

def force_create_content_types(apps, schema_editor):
    """Force the creation of the content types for the ``ideas`` app"""

    app_config = apps.get_app_config('ideas')
    create_ordered_contenttypes(app_config)


def migrate_brainstormers_to_ideas(apps, schema_editor):
    """Migrate the ``Brainstormer`` and the related model to their ideas equivalent"""

    Brainstorming = apps.get_model(
        'ideas',
        'Brainstorming'
    )

    Brainstorming.objects.migrate_brainstormer_templates(
        template_model=apps.get_model(
            'brainstormers',
            'BrainstormerTemplate'
        )
    )
    Brainstorming.objects.migrate_brainstormers()


def noop_backward_func(apps, schema_editor):
    """No turning back"""

    pass


class Migration(migrations.Migration):

    replaces = [('ideas', '0001_initial'), ('ideas', '0002_migrate_brainstormers_to_ideas'), ('ideas', '0003_django_upgrade_add_managers_in_migrations'), ('ideas', '0004_django_upgrade_add_all_managers_in_migrations'), ('ideas', '0005_add_timestamps')]

    initial = True

    dependencies = [
        ('trainings', '0049_add_timestamps'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('brainstormers', '0028_remove_brainstormeractivity'),
        ('likes', '0005_use_django_extension_uuid'),
        ('sync', '0003_add_index_on_update_synchornized'),
    ]

    operations = [
        migrations.CreateModel(
            name='Brainstorming',
            fields=[
                ('trainingactivity_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='trainings.TrainingActivity')),
                ('is_anonymous', models.BooleanField(default=False, verbose_name='Anonymous')),
            ],
            options={
                'abstract': False,
            },
            bases=('trainings.trainingactivity', models.Model),
        ),
        migrations.CreateModel(
            name='BrainstormingIdea',
            fields=[
                ('sort_order', models.IntegerField(blank=True, db_index=True)),
                ('id', django_extensions.db.fields.UUIDField(blank=True, editable=False, primary_key=True, serialize=False)),
                ('is_deleted', models.BooleanField(default=False)),
                ('update_locally', models.BooleanField(default=False)),
                ('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
                ('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
                ('text', models.CharField(max_length=80, verbose_name='Text')),
                ('brainstorming', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ideas', to='ideas.Brainstorming', verbose_name='Brainstorming')),
                ('first_update', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ideas_brainstormingidea_by_first', to='sync.Update')),
                ('last_update', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ideas_brainstormingidea_by_last', to='sync.Update')),
                ('original_version', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='all_duplicates', to='ideas.BrainstormingIdea')),
                ('parent_version', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='direct_duplicates', to='ideas.BrainstormingIdea')),
                ('session', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='brainstormingidea_ideas', to='trainings.TrainingSession', verbose_name='Session')),
            ],
            bases=(mtp.apps.trainings.models.sessions.LiveDependencyMixin, models.Model),
        ),
        migrations.CreateModel(
            name='BrainstormingTag',
            fields=[
                ('sort_order', models.IntegerField(blank=True, db_index=True)),
                ('id', django_extensions.db.fields.UUIDField(blank=True, editable=False, primary_key=True, serialize=False)),
                ('is_deleted', models.BooleanField(default=False)),
                ('update_locally', models.BooleanField(default=False)),
                ('name', models.CharField(max_length=50, verbose_name='Name')),
                ('color', models.CharField(blank=True, max_length=30, null=True, verbose_name='Color')),
                ('brainstorming', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tags', to='ideas.Brainstorming', verbose_name='Brainstorming')),
                ('first_update', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ideas_brainstormingtag_by_first', to='sync.Update')),
                ('last_update', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ideas_brainstormingtag_by_last', to='sync.Update')),
                ('original_version', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='all_duplicates', to='ideas.BrainstormingTag')),
                ('parent_version', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='direct_duplicates', to='ideas.BrainstormingTag')),
                ('session', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='brainstorming_tags', to='trainings.TrainingSession', verbose_name='Session')),
                ('created_at', models.DateTimeField(blank=True, db_index=True, default=django.utils.timezone.now, editable=False, verbose_name='created at')),
                ('updated_at', models.DateTimeField(auto_now=True, db_index=True, verbose_name='last updated at')),
            ],
            bases=(mtp.apps.trainings.models.sessions.LiveDependencyMixin, models.Model),
        ),
        migrations.CreateModel(
            name='QuestionWall',
            fields=[
                ('trainingactivity_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='trainings.TrainingActivity')),
                ('is_anonymous', models.BooleanField(default=False, verbose_name='Anonymous')),
            ],
            options={
                'abstract': False,
            },
            bases=('trainings.trainingactivity', models.Model),
        ),
        migrations.CreateModel(
            name='QuestionWallIdea',
            fields=[
                ('sort_order', models.IntegerField(blank=True, db_index=True)),
                ('id', django_extensions.db.fields.UUIDField(blank=True, editable=False, primary_key=True, serialize=False)),
                ('is_deleted', models.BooleanField(default=False)),
                ('update_locally', models.BooleanField(default=False)),
                ('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
                ('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
                ('text', models.CharField(max_length=140, verbose_name='Text')),
                ('first_update', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ideas_questionwallidea_by_first', to='sync.Update')),
                ('last_update', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ideas_questionwallidea_by_last', to='sync.Update')),
                ('questionwall', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ideas', to='ideas.QuestionWall', verbose_name='Question wall')),
                ('session', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='questionwallidea_ideas', to='trainings.TrainingSession', verbose_name='Session')),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='questionwallidea_ideas', to=settings.AUTH_USER_MODEL, verbose_name='User')),
            ],
        ),
        migrations.CreateModel(
            name='WordCloud',
            fields=[
                ('trainingactivity_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='trainings.TrainingActivity')),
                ('is_anonymous', models.BooleanField(default=False, verbose_name='Anonymous')),
            ],
            options={
                'abstract': False,
            },
            bases=('trainings.trainingactivity', models.Model),
        ),
        migrations.CreateModel(
            name='WordCloudIdea',
            fields=[
                ('sort_order', models.IntegerField(blank=True, db_index=True)),
                ('id', django_extensions.db.fields.UUIDField(blank=True, editable=False, primary_key=True, serialize=False)),
                ('is_deleted', models.BooleanField(default=False)),
                ('update_locally', models.BooleanField(default=False)),
                ('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
                ('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
                ('text', models.CharField(max_length=30, validators=[django.core.validators.RegexValidator(message='No spaces are allowed', regex='^[^\\s]+$')], verbose_name='Text')),
                ('first_update', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ideas_wordcloudidea_by_first', to='sync.Update')),
                ('last_update', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='ideas_wordcloudidea_by_last', to='sync.Update')),
                ('session', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='wordcloudidea_ideas', to='trainings.TrainingSession', verbose_name='Session')),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='wordcloudidea_ideas', to=settings.AUTH_USER_MODEL, verbose_name='User')),
                ('wordcloud', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ideas', to='ideas.WordCloud', verbose_name='Word cloud')),
            ],
        ),
        migrations.AddField(
            model_name='brainstormingidea',
            name='tags',
            field=models.ManyToManyField(related_name='ideas', to='ideas.BrainstormingTag', verbose_name='Tags'),
        ),
        migrations.AddField(
            model_name='brainstormingidea',
            name='user',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='brainstormingidea_ideas', to=settings.AUTH_USER_MODEL, verbose_name='User'),
        ),
        migrations.AlterUniqueTogether(
            name='wordcloudidea',
            unique_together=set([('wordcloud', 'session', 'sort_order')]),
        ),
        migrations.AlterUniqueTogether(
            name='questionwallidea',
            unique_together=set([('questionwall', 'session', 'sort_order')]),
        ),
        migrations.AlterUniqueTogether(
            name='brainstormingtag',
            unique_together=set([('brainstorming', 'session', 'sort_order')]),
        ),
        migrations.AddField(
            model_name='brainstormingidea',
            name='created_at',
            field=models.DateTimeField(blank=True, db_index=True, default=django.utils.timezone.now, editable=False, verbose_name='created at'),
        ),
        migrations.AddField(
            model_name='brainstormingidea',
            name='updated_at',
            field=models.DateTimeField(auto_now=True, db_index=True, verbose_name='last updated at'),
        ),
        migrations.AlterUniqueTogether(
            name='brainstormingidea',
            unique_together=set([('brainstorming', 'session', 'sort_order')]),
        ),
        migrations.AlterModelManagers(
            name='brainstorming',
            managers=[
                ('objects', mtp.apps.ideas.managers.IdeasActivityManager()),
            ],
        ),
        migrations.AlterModelManagers(
            name='questionwall',
            managers=[
                ('objects', django.db.models.manager.Manager()),
                ('dependency_objects', django.db.models.manager.Manager()),
            ],
        ),
        migrations.AlterModelManagers(
            name='wordcloud',
            managers=[
                ('objects', django.db.models.manager.Manager()),
                ('dependency_objects', django.db.models.manager.Manager()),
            ],
        ),
        migrations.RunPython(
            code=force_create_content_types,
            reverse_code=noop_backward_func,
        ),
        migrations.RunPython(
            code=migrate_brainstormers_to_ideas,
            reverse_code=noop_backward_func,
        ),
    ]
