"""Stop auto-filling starlink_ip with a private default.

The field defaulted to 192.168.100.1, so every connection silently gained a
Starlink target nobody entered — which then pinged DOWN forever, because the
CRM cannot reach a private address from cPanel.

The data step only clears rows still holding that exact default. A different
value was typed deliberately and is left alone.
"""
from django.db import migrations, models


def clear_default_starlink(apps, schema_editor):
    ClientNetwork = apps.get_model('clients', 'ClientNetwork')
    ClientNetwork.objects.filter(starlink_ip='192.168.100.1').update(starlink_ip='')


class Migration(migrations.Migration):

    dependencies = [
        ('clients', '0018_clientnetwork_is_active'),
    ]

    operations = [
        migrations.AlterField(
            model_name='clientnetwork',
            name='starlink_ip',
            field=models.CharField(blank=True, default='', max_length=50),
        ),
        # Not reversible on purpose: restoring a phantom default would
        # reintroduce the false DOWN this migration exists to remove.
        migrations.RunPython(clear_default_starlink, migrations.RunPython.noop),
    ]
