# Generated by Django 4.2.2 on 2023-06-17 17:38

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
    dependencies = [
        ("diop", "0019_user_disconnected_max_alter_user_accessgroup_member_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="Reservation",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("t_start", models.DateTimeField(verbose_name="Reservation Start")),
                ("t_end", models.DateTimeField(verbose_name="Reservation End")),
                (
                    "deliverygroup",
                    models.ForeignKey(
                        help_text="Delivery Group the reservation is for.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="diop.deliverygroup",
                        verbose_name="Delivery Group",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, to="diop.user"
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="PpmsBooking",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "username",
                    models.CharField(max_length=32, verbose_name="PPMS Username"),
                ),
                ("system_id", models.IntegerField(verbose_name="PPMS System ID")),
                ("t_start", models.DateTimeField(verbose_name="Booking Start")),
                ("t_end", models.DateTimeField(verbose_name="Booking End")),
                (
                    "ppms_session",
                    models.CharField(
                        blank=True,
                        max_length=8,
                        null=True,
                        verbose_name="PPMS Session ID",
                    ),
                ),
                (
                    "sync_state",
                    models.CharField(
                        choices=[("D", "Deleted"), ("N", "New"), ("K", "Known")],
                        default="N",
                        max_length=1,
                    ),
                ),
                (
                    "reservation",
                    models.ForeignKey(
                        blank=True,
                        help_text="Reservation to which this booking belongs.",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="diop.reservation",
                    ),
                ),
            ],
            options={
                "verbose_name": "PPMS Booking",
            },
        ),
        migrations.AddConstraint(
            model_name="reservation",
            constraint=models.UniqueConstraint(
                fields=("user", "deliverygroup", "t_start", "t_end"),
                name="unique_reservation",
            ),
        ),
        migrations.AddConstraint(
            model_name="ppmsbooking",
            constraint=models.UniqueConstraint(
                fields=("username", "system_id", "t_start", "t_end"),
                name="unique_booking",
            ),
        ),
    ]
