# Generated by Django 5.2.7 on 2025-11-01 01:33

from django.db import migrations


def create_recurring_task(apps, schema_editor):
    CrontabSchedule = apps.get_model("django_celery_beat", "CrontabSchedule")
    PeriodicTask = apps.get_model("django_celery_beat", "PeriodicTask")

    schedule, _ = CrontabSchedule.objects.get_or_create(
        minute="0",
        hour="5",
        day_of_week="*",
        day_of_month="*",
        month_of_year="*",
    )

    PeriodicTask.objects.update_or_create(
        name="core.ensure_recurring_client_reports",
        defaults={
            "task": "core.tasks.ensure_recurring_client_reports",
            "crontab": schedule,
            "enabled": True,
        },
    )


def remove_recurring_task(apps, schema_editor):
    PeriodicTask = apps.get_model("django_celery_beat", "PeriodicTask")
    PeriodicTask.objects.filter(
        name="core.ensure_recurring_client_reports"
    ).delete()


class Migration(migrations.Migration):

    dependencies = [
        ("core", "0079_clientreport_chargers_clientreportschedule_chargers"),
    ]

    operations = [
        migrations.RunPython(create_recurring_task, remove_recurring_task),
    ]
