import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('gears', '0011_rig_ballistic_fields'),
        ('calibers', '0001_initial'),
    ]

    operations = [
        # ── Firearm.caliber ──────────────────────────────────────────────────
        migrations.RemoveField(
            model_name='firearm',
            name='caliber',
        ),
        migrations.AddField(
            model_name='firearm',
            name='caliber',
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name='+',
                to='calibers.caliber',
                verbose_name='caliber',
            ),
        ),

        # ── Suppressor.max_caliber ───────────────────────────────────────────
        migrations.RemoveField(
            model_name='suppressor',
            name='max_caliber',
        ),
        migrations.AddField(
            model_name='suppressor',
            name='max_caliber',
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name='+',
                to='calibers.caliber',
                verbose_name='max caliber',
            ),
        ),

        # ── Magazine.caliber ─────────────────────────────────────────────────
        migrations.RemoveField(
            model_name='magazine',
            name='caliber',
        ),
        migrations.AddField(
            model_name='magazine',
            name='caliber',
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name='+',
                to='calibers.caliber',
                verbose_name='caliber',
            ),
        ),

        # ── Ammo.caliber — remove constraint first ───────────────────────────
        migrations.RemoveConstraint(
            model_name='ammo',
            name='unique_ammo_brand_name_caliber',
        ),
        migrations.RemoveField(
            model_name='ammo',
            name='caliber',
        ),
        migrations.AddField(
            model_name='ammo',
            name='caliber',
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name='+',
                to='calibers.caliber',
                verbose_name='caliber',
            ),
        ),
        migrations.AddConstraint(
            model_name='ammo',
            constraint=models.UniqueConstraint(
                fields=['brand', 'name', 'caliber'],
                name='unique_ammo_brand_name_caliber',
            ),
        ),

        # ── Brass.caliber — remove constraint first ───────────────────────────
        migrations.RemoveConstraint(
            model_name='brass',
            name='unique_brass_brand_caliber',
        ),
        migrations.RemoveField(
            model_name='brass',
            name='caliber',
        ),
        migrations.AddField(
            model_name='brass',
            name='caliber',
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name='+',
                to='calibers.caliber',
                verbose_name='caliber',
            ),
        ),
        migrations.AddConstraint(
            model_name='brass',
            constraint=models.UniqueConstraint(
                fields=['brand', 'caliber'],
                name='unique_brass_brand_caliber',
            ),
        ),

        # ── ReloadRecipe.caliber ─────────────────────────────────────────────
        migrations.RemoveField(
            model_name='reloadrecipe',
            name='caliber',
        ),
        migrations.AddField(
            model_name='reloadrecipe',
            name='caliber',
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name='+',
                to='calibers.caliber',
                verbose_name='caliber',
            ),
        ),
    ]
