# Generated by Django 5.0.8 on 2024-12-26 21:03

import django.core.serializers.json
import django_pydantic_field.compat.django
import django_pydantic_field.fields
import pydantic_extra_types.mac_address
from django.db import migrations


def bssids_into_list(apps, schema_editor):
    RangingBeacon = apps.get_model('mapdata', 'rangingbeacon')
    for ranging_beacon in RangingBeacon.objects.all():
        ranging_beacon.wifi_bssids = [ranging_beacon.wifi_bssid] if ranging_beacon.wifi_bssid else []
        ranging_beacon.save()


def bssid_from_list(apps, schema_editor):
    RangingBeacon = apps.get_model('mapdata', 'rangingbeacon')
    for ranging_beacon in RangingBeacon.objects.all():
        ranging_beacon.wifi_bssid = ranging_beacon.wifi_bssids[0] if ranging_beacon.wifi_bssids else None
        ranging_beacon.save()


class Migration(migrations.Migration):

    dependencies = [
        ('mapdata', '0129_dataoverlay_cluster_points'),
    ]

    operations = [
        migrations.AddField(
            model_name='rangingbeacon',
            name='wifi_bssids',
            field=django_pydantic_field.fields.PydanticSchemaField(config=None, default=list, encoder=django.core.serializers.json.DjangoJSONEncoder, help_text="uses node's value if not set", schema=django_pydantic_field.compat.django.GenericContainer(list, (pydantic_extra_types.mac_address.MacAddress,)), verbose_name='WiFi BSSIDs'),
        ),
        migrations.RunPython(bssids_into_list, bssid_from_list),
        migrations.RemoveField(
            model_name='rangingbeacon',
            name='wifi_bssid',
        ),
    ]
