# Generated by Django 4.2.2 on 2023-06-16 20:06

from django.db import migrations, models
import django.utils.timezone


def set_pumping_start_end_values(apps, schema_editor):
    # The model must be imported to ensure its overridden `save` method is run.
    Pumping = apps.get_model("core", "Pumping")

    for pumping in Pumping.objects.all():
        pumping.start = pumping.time
        pumping.end = pumping.start
        pumping.save()


class Migration(migrations.Migration):
    dependencies = [
        ("core", "0028_alter_sleep_options_remove_sleep_napping_sleep_nap"),
    ]

    operations = [
        migrations.AlterModelOptions(
            name="pumping",
            options={
                "default_permissions": ("view", "add", "change", "delete"),
                "ordering": ["-start"],
                "verbose_name": "Pumping",
                "verbose_name_plural": "Pumping",
            },
        ),
        migrations.AddField(
            model_name="pumping",
            name="start",
            field=models.DateTimeField(
                default=django.utils.timezone.localtime, verbose_name="Start time"
            ),
        ),
        migrations.AddField(
            model_name="pumping",
            name="end",
            field=models.DateTimeField(
                default=django.utils.timezone.localtime, verbose_name="End time"
            ),
        ),
        migrations.AddField(
            model_name="pumping",
            name="duration",
            field=models.DurationField(
                editable=False, null=True, verbose_name="Duration"
            ),
        ),
        migrations.RunPython(
            set_pumping_start_end_values, reverse_code=migrations.RunPython.noop
        ),
        migrations.RemoveField(
            model_name="pumping",
            name="time",
        ),
    ]
