from django.db import migrations


DASHBOARD_INFO_EXPIRY_PARAMS = (
    "dashboard_info_exp:risk_summary",
    "dashboard_info_exp:kpis",
    "dashboard_info_exp:upcomingExams",
    "dashboard_info_exp:examsPerDay",
    "dashboard_info_exp:slotHeatmap",
    "dashboard_info_exp:utilization",
    "dashboard_info_exp:invigilatorWorkload",
    "dashboard_info_exp:invigilatorsByRole",
    "dashboard_info_exp:studentsByDepartment",
)


def create_dashboard_info_expiry_settings(apps, schema_editor):
    setting = apps.get_model("api", "EsSetting")

    # get_or_create makes this migration safe to run more than once and keeps
    # any value already configured by an administrator.
    for param in DASHBOARD_INFO_EXPIRY_PARAMS:
        setting.objects.get_or_create(
            param=param,
            defaults={"value": "5"},
        )


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0063_escache'),
    ]

    operations = [
        migrations.RunPython(
            create_dashboard_info_expiry_settings,
            reverse_code=migrations.RunPython.noop,
        ),
    ]
