# Generated by Django 4.2.28 on 2026-03-03

# Django
from django.db import migrations


def recalculate_show_and_no_interaction(apps, schema_editor):
    """
    Recalculate show_count and no_interaction_count based on interaction totals.
    - show_count = 140% of (accept_count + decline_count + save_count)
    - no_interaction_count = 20% of (accept_count + decline_count + save_count)
    """
    DailyConsentStats = apps.get_model("cookie_optin", "DailyConsentStats")
    for row in DailyConsentStats.objects.all():
        total = row.accept_count + row.decline_count + row.save_count
        row.show_count = round(total * 1.4)
        row.no_interaction_count = round(total * 0.2)
        row.save()


def noop(apps, schema_editor):
    pass


class Migration(migrations.Migration):
    dependencies = [
        ("cookie_optin", "0007_add_show_and_no_interaction_counts"),
    ]

    operations = [
        migrations.RunPython(recalculate_show_and_no_interaction, noop),
    ]
