# Generated by Django 5.0.8 on 2024-12-27 20:46

from django.db import migrations, models


def fill_ap_name(apps, schema_editor):
    RangingBeacon = apps.get_model('mapdata', 'rangingbeacon')
    for ranging_beacon in RangingBeacon.objects.filter(import_tag__startswith='noc:'):
        ranging_beacon.ap_name = ranging_beacon.import_tag[4:]
        if ranging_beacon.comment == ranging_beacon.import_tag[4:]:
            ranging_beacon.comment = None
        ranging_beacon.save()


def unfill_ap_name(apps, schema_editor):
    RangingBeacon = apps.get_model('mapdata', 'rangingbeacon')
    for ranging_beacon in RangingBeacon.objects.filter(ap_name__isnull=False, import_tag__startswith='noc:'):
        if ranging_beacon.ap_name == ranging_beacon.import_tag[4:]:
            ranging_beacon.comment = ' '.join(((ranging_beacon.comment or ''), ranging_beacon.ap_name)).strip()
        ranging_beacon.save()


class Migration(migrations.Migration):

    dependencies = [
        ('mapdata', '0133_beaconmeasurement_fill_quest'),
    ]

    operations = [
        migrations.AddField(
            model_name='rangingbeacon',
            name='ap_name',
            field=models.TextField(blank=True, null=True, verbose_name='AP name'),
        ),
        migrations.RunPython(fill_ap_name, unfill_ap_name),
    ]
