# Generated by Django 5.0.8 on 2024-12-23 15:24

import c3nav.routing.schemas
import django.core.serializers.json
import django.db.models.deletion
import django_pydantic_field.compat.django
import django_pydantic_field.fields
import types
import typing
from django.db import migrations, models


def forwards_func(apps, schema_editor):
    BeaconMeasurement = apps.get_model('mapdata', 'BeaconMeasurement')
    for measurement in BeaconMeasurement.objects.all():
        if isinstance(measurement.data, list):
            measurement.data = {"wifi": measurement.data}
        measurement.data["wifi"] = [
            [{**{k: v for k, v in peer.items() if k != "level"}, "rssi": peer.get("level", peer.get("rssi"))}
             for peer in scan]
            for scan in measurement.data["wifi"]
        ]
        measurement.save()



class Migration(migrations.Migration):

    dependencies = [
        ('mapdata', '0123_door_name_door_todo'),
    ]

    operations = [
        migrations.RunPython(forwards_func, migrations.RunPython.noop),
        migrations.AlterField(
            model_name='beaconmeasurement',
            name='data',
            field=django_pydantic_field.fields.PydanticSchemaField(config=None, encoder=django.core.serializers.json.DjangoJSONEncoder, schema=c3nav.routing.schemas.BeaconMeasurementDataSchema, verbose_name='Measurement list'),
        ),
    ]
