# Generated by Django 3.1.12 on 2021-06-29 12:45

from django.db import migrations, models


def professional_type_to_subtype(apps, schema_editor):
    SupportGroupSubtype = apps.get_model("groups", "SupportGroupSubtype")
    SupportGroup = apps.get_model("groups", "SupportGroup")
    subtype, created = SupportGroupSubtype.objects.update_or_create(
        label="groupe d'action professionnel",
        defaults={
            "description": "Groupe d'action professionnel",
            "visibility": "A",
            "color": "#f4981e",
            "icon_name": "industry",
            "type": "L",
        },
    )
    subtype.supportgroups.add(*SupportGroup.objects.filter(type="P"))
    SupportGroup.objects.filter(type__in=["P", "2"]).update(type="L")
    SupportGroupSubtype.objects.filter(type__in=["P", "2"]).update(type="L")


class Migration(migrations.Migration):
    dependencies = [
        ("groups", "0002_creer_sous_types"),
    ]

    operations = [
        migrations.RunPython(
            code=professional_type_to_subtype, reverse_code=migrations.RunPython.noop
        ),
        migrations.AlterField(
            model_name="supportgroup",
            name="type",
            field=models.CharField(
                choices=[
                    ("L", "Groupe local"),
                    ("B", "Groupe thématique"),
                    ("F", "Groupe fonctionnel"),
                ],
                default="L",
                max_length=1,
                verbose_name="type de groupe",
            ),
        ),
        migrations.AlterField(
            model_name="supportgroupsubtype",
            name="type",
            field=models.CharField(
                choices=[
                    ("L", "Groupe local"),
                    ("B", "Groupe thématique"),
                    ("F", "Groupe fonctionnel"),
                ],
                max_length=1,
                verbose_name="type de groupe",
            ),
        ),
    ]
