# Generated by Django 3.2.22 on 2023-12-15 14:42
import datetime
import re

import django.core.validators
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models

import NEMO.mixins
from NEMO.apps.nemo_ce.migration_utils import NEMOMigration


class Migration(NEMOMigration):

    dependencies = [
        ("NEMO", "0055_reservationconfigurationoption"),
        ("nemo_ce", "0014_ce_remove_default_value_tool_shadowing"),
    ]

    operations = [
        migrations.CreateModel(
            name="ConfigurationPrecursor",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                (
                    "name",
                    models.CharField(
                        help_text="The name of this overall configuration. This text is displayed as a label on the tool control page.",
                        max_length=255,
                    ),
                ),
                (
                    "configurable_item_name",
                    models.CharField(
                        blank=True,
                        help_text="The name of the tool part being configured. This text is displayed as a label on the tool control page. Leave this field blank if there is only one configuration slot.",
                        max_length=255,
                        null=True,
                    ),
                ),
                (
                    "advance_notice_limit",
                    models.PositiveIntegerField(
                        help_text="Configuration changes must be made this many hours in advance."
                    ),
                ),
                (
                    "display_order",
                    models.PositiveIntegerField(
                        help_text="The order in which this configuration will be displayed beside others when making a reservation and controlling a tool. Can be any positive integer including 0. Lower values are displayed first."
                    ),
                ),
                (
                    "prompt",
                    models.TextField(
                        blank=True,
                        help_text="The textual description the user will see when making a configuration choice.",
                        null=True,
                    ),
                ),
                (
                    "available_settings",
                    models.TextField(
                        blank=True,
                        help_text="The available choices to select for this configuration option. Multiple values are separated by commas.",
                        null=True,
                    ),
                ),
                (
                    "calendar_colors",
                    models.TextField(
                        blank=True,
                        help_text="Comma separated list of html colors for each available setting. E.g. #ffffff, #eeeeee",
                        null=True,
                        validators=[
                            django.core.validators.RegexValidator(
                                re.compile(
                                    "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})(?:,\\s*#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}))*$"
                                ),
                                code="invalid",
                                message="Enter a valid hex color list, eg. #000000,#111111",
                            )
                        ],
                    ),
                ),
                (
                    "absence_string",
                    models.CharField(
                        blank=True,
                        help_text="The text that appears to indicate absence of a choice.",
                        max_length=100,
                        null=True,
                    ),
                ),
                (
                    "qualified_users_are_maintainers",
                    models.BooleanField(
                        default=False,
                        help_text="Any user that is qualified to use the tool that this configuration applies to may also change this configuration. Checking this box implicitly adds qualified users to the maintainers list.",
                    ),
                ),
                (
                    "exclude_from_configuration_agenda",
                    models.BooleanField(
                        default=False,
                        help_text="Reservations containing this configuration will be excluded from the Configuration Agenda page.",
                    ),
                ),
                (
                    "enabled",
                    models.BooleanField(
                        default=True, help_text="Only active configurations will show up for the selected tool"
                    ),
                ),
                (
                    "maintainers",
                    models.ManyToManyField(
                        blank=True,
                        help_text="Select the users that are allowed to change this configuration.",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "tool",
                    models.ForeignKey(
                        help_text="The tool that this configuration option applies to.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="NEMO.tool",
                    ),
                ),
            ],
            options={
                "ordering": ["tool", "name"],
            },
            bases=(models.Model, NEMO.mixins.ConfigurationMixin),
        ),
        migrations.CreateModel(
            name="ConfigurationPrecursorSchedule",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("reset_time", models.TimeField(default=datetime.time(0, 0))),
                (
                    "monday",
                    models.BooleanField(
                        default=True, help_text="Check this box if the configuration resets on Mondays."
                    ),
                ),
                (
                    "tuesday",
                    models.BooleanField(
                        default=True, help_text="Check this box if the configuration resets on Tuesdays."
                    ),
                ),
                (
                    "wednesday",
                    models.BooleanField(
                        default=True, help_text="Check this box if the configuration resets on Wednesdays."
                    ),
                ),
                (
                    "thursday",
                    models.BooleanField(
                        default=True, help_text="Check this box if the configuration resets on Thursdays."
                    ),
                ),
                (
                    "friday",
                    models.BooleanField(
                        default=True, help_text="Check this box if the configuration resets on Fridays."
                    ),
                ),
                (
                    "saturday",
                    models.BooleanField(
                        default=False, help_text="Check this box if the configuration resets on Saturdays."
                    ),
                ),
                (
                    "sunday",
                    models.BooleanField(
                        default=False, help_text="Check this box if the configuration resets on Sundays."
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.RenameField(
            model_name="configurationhistory",
            old_name="slot",
            new_name="position",
        ),
        migrations.AddField(
            model_name="configurationoption",
            name="current_position",
            field=models.PositiveIntegerField(
                blank=True, help_text="The current position for this configuration option", null=True
            ),
        ),
        migrations.AddField(
            model_name="configurationoption",
            name="locked",
            field=models.BooleanField(default=False, help_text="Whether this setting is locked"),
        ),
        migrations.AddField(
            model_name="configurationoption",
            name="precursor_configuration",
            field=models.ForeignKey(
                blank=True,
                help_text="The configuration precursor this option applies to",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                to="NEMO.configurationprecursor",
            ),
        ),
        migrations.CreateModel(
            name="ConfigurationPrecursorSlot",
            fields=[
                ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("setting", models.CharField(blank=True, max_length=255, null=True)),
                ("position", models.PositiveIntegerField()),
                ("permanent_position", models.BooleanField(default=False)),
                ("permanent_setting", models.BooleanField(default=False)),
                (
                    "precursor_configuration",
                    models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="NEMO.configurationprecursor"),
                ),
                (
                    "schedule",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="NEMO.configurationprecursorschedule",
                    ),
                ),
            ],
            options={
                "ordering": ["precursor_configuration", "position"],
            },
        ),
        migrations.AddField(
            model_name="configurationhistory",
            name="precursor_configuration",
            field=models.ForeignKey(
                blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="NEMO.configurationprecursor"
            ),
        ),
        migrations.AlterField(
            model_name="configurationhistory",
            name="configuration",
            field=models.ForeignKey(
                blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="NEMO.configuration"
            ),
        ),
        migrations.AddField(
            model_name="closure",
            name="configuration_precursor_schedule",
            field=models.ManyToManyField(
                blank=True,
                help_text="Select precursor configuration schedules to unlock during this closure (for the whole week)",
                to="NEMO.ConfigurationPrecursorSchedule",
            ),
        ),
    ]
