from decimal import Decimal

from django.db import migrations, models


def clear_legacy_percent_seeds(apps, schema_editor):
    """
    0041 seeded percentage-looking values (5, 15, …).
    Those are not valid fixed amounts — reset to 0 so staff set real fees.
    """
    CountryVatRate = apps.get_model('core', 'CountryVatRate')
    CountryVatRate.objects.all().update(vat_amount=Decimal('0.00'))


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0041_country_vat_rate'),
    ]

    operations = [
        migrations.RenameField(
            model_name='countryvatrate',
            old_name='vat_rate_percent',
            new_name='vat_amount',
        ),
        migrations.AlterField(
            model_name='countryvatrate',
            name='vat_amount',
            field=models.DecimalField(
                decimal_places=2,
                help_text='Fixed VAT amount (not a percentage), e.g. 300.00.',
                max_digits=14,
            ),
        ),
        migrations.RunPython(clear_legacy_percent_seeds, migrations.RunPython.noop),
    ]
