# Generated by Django 4.1.10 on 2023-07-11 19:01

import aleksis.core.managers
import aleksis.core.mixins
from django.db import migrations, models
import django.db.models.deletion
import recurrence.fields
import timezone_field.fields


class Migration(migrations.Migration):

    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
        ("core", "0050_managed_by_app_label"),
    ]

    operations = [
        migrations.CreateModel(
            name="CalendarEvent",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "managed_by_app_label",
                    models.CharField(
                        blank=True,
                        editable=False,
                        max_length=255,
                        verbose_name="App label of app responsible for managing this instance",
                    ),
                ),
                ("extended_data", models.JSONField(default=dict, editable=False)),
                (
                    "datetime_start",
                    models.DateTimeField(blank=True, null=True, verbose_name="Start date and time"),
                ),
                (
                    "datetime_end",
                    models.DateTimeField(blank=True, null=True, verbose_name="End date and time"),
                ),
                (
                    "timezone",
                    timezone_field.fields.TimeZoneField(
                        blank=True, null=True, verbose_name="Timezone"
                    ),
                ),
                ("date_start", models.DateField(blank=True, null=True, verbose_name="Start date")),
                ("date_end", models.DateField(blank=True, null=True, verbose_name="End date")),
                (
                    "recurrences",
                    recurrence.fields.RecurrenceField(
                        blank=True, null=True, verbose_name="Recurrences"
                    ),
                ),
                (
                    "amends",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="amended_by",
                        to="core.calendarevent",
                        verbose_name="Amended base event",
                    ),
                ),
                (
                    "polymorphic_ctype",
                    models.ForeignKey(
                        editable=False,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="polymorphic_%(app_label)s.%(class)s_set+",
                        to="contenttypes.contenttype",
                    ),
                ),
            ],
            options={
                "verbose_name": "Calendar Event",
                "verbose_name_plural": "Calendar Events",
                "ordering": ["datetime_start", "date_start", "datetime_end", "date_end"],
            },
            bases=(aleksis.core.mixins.CalendarEventMixin, models.Model),
            managers=[
            ],
        ),
        migrations.CreateModel(
            name="Holiday",
            fields=[
                (
                    "calendarevent_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="core.calendarevent",
                    ),
                ),
                ("holiday_name", models.CharField(max_length=255, verbose_name="Name")),
            ],
            options={
                "verbose_name": "Holiday",
                "verbose_name_plural": "Holidays",
            },
            bases=("core.calendarevent",),
            managers=[
            ],
        ),
        migrations.AddConstraint(
            model_name="calendarevent",
            constraint=models.CheckConstraint(
                check=models.Q(
                    ("date_start__isnull", True), ("datetime_start__isnull", True), _negated=True
                ),
                name="datetime_start_or_date_start",
            ),
        ),
        migrations.AddConstraint(
            model_name="calendarevent",
            constraint=models.CheckConstraint(
                check=models.Q(
                    ("date_end__isnull", True), ("datetime_end__isnull", True), _negated=True
                ),
                name="datetime_end_or_date_end",
            ),
        ),
        migrations.AddConstraint(
            model_name="calendarevent",
            constraint=models.CheckConstraint(
                check=models.Q(
                    ("datetime_start__isnull", False), ("timezone__isnull", True), _negated=True
                ),
                name="timezone_if_datetime_start",
            ),
        ),
        migrations.AddConstraint(
            model_name="calendarevent",
            constraint=models.CheckConstraint(
                check=models.Q(
                    ("datetime_end__isnull", False), ("timezone__isnull", True), _negated=True
                ),
                name="timezone_if_datetime_end",
            ),
        ),
    ]
