# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2021-10-18 17:47
from __future__ import unicode_literals

from django.db import migrations, models


def migrate_carousel_mode(apps, schema_editor):
    Carousel = apps.get_model("carousel", "Carousel")
    for carousel in Carousel.objects.all():
        if carousel.mode == "off":
            carousel.enabled = False
        elif carousel.mode == "latest":
            carousel.latest_articles = True
        elif carousel.mode == "news":
            carousel.latest_news = True
        elif carousel.mode == "mixed":
            carousel.latest_articles = True
            carousel.latest_news = True
        carousel.save()


class Migration(migrations.Migration):
    dependencies = [
        ("journal", "0046_auto_20210922_1436"),
        ("carousel", "0003_auto_20200121_1020"),
    ]

    operations = [
        migrations.AddField(
            model_name="carousel",
            name="current_issue",
            field=models.BooleanField(
                default=False, help_text="Always include the current issue"
            ),
        ),
        migrations.AddField(
            model_name="carousel",
            name="issues",
            field=models.ManyToManyField(
                blank=True, to="journal.Issue", verbose_name="Issues and Collections"
            ),
        ),
        migrations.AddField(
            model_name="carousel",
            name="latest_articles",
            field=models.BooleanField(
                default=False,
                help_text="The carousel will display the latest published articles",
            ),
        ),
        migrations.AddField(
            model_name="carousel",
            name="latest_news",
            field=models.BooleanField(
                default=False,
                help_text="The carousel will display the latest published news items",
            ),
        ),
        migrations.AlterField(
            model_name="carousel",
            name="exclude",
            field=models.BooleanField(
                default=False,
                help_text="If enabled, the selectors below will behave as an exclusion list",
            ),
        ),
        migrations.RunPython(migrate_carousel_mode, migrations.RunPython.noop),
    ]
