# Generated by Django 5.2.9 on 2026-01-05 02:52

from django.db import migrations, models
from django.db.models import Q
from django.utils.text import slugify


def populate_public_view_slug(apps, schema_editor):
    ClockDevice = apps.get_model("clocks", "ClockDevice")
    devices = ClockDevice.objects.filter(
        Q(public_view_slug__isnull=True) | Q(public_view_slug="")
    )
    for device in devices:
        device.public_view_slug = slugify(f"clock-device-{device.pk}")
        device.save(update_fields=["public_view_slug"])


class Migration(migrations.Migration):

    dependencies = [
        ("clocks", "0001_initial"),
    ]

    operations = [
        migrations.AddField(
            model_name="clockdevice",
            name="enable_public_view",
            field=models.BooleanField(default=False),
        ),
        migrations.AddField(
            model_name="clockdevice",
            name="public_view_slug",
            field=models.SlugField(blank=True, null=True, unique=True),
        ),
        migrations.RunPython(populate_public_view_slug, migrations.RunPython.noop),
    ]
