# Generated manually for adding seed_keyword relationship to Keywords

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


class Migration(migrations.Migration):

    dependencies = [
        ('igny8_core_auth', '0010_add_seed_keyword'),
        ('planner', '0005_alter_clusters_options_alter_contentideas_options_and_more'),
    ]

    operations = [
        # Remove old fields (keyword, volume, difficulty, intent)
        migrations.RemoveField(
            model_name='keywords',
            name='keyword',
        ),
        migrations.RemoveField(
            model_name='keywords',
            name='volume',
        ),
        migrations.RemoveField(
            model_name='keywords',
            name='difficulty',
        ),
        migrations.RemoveField(
            model_name='keywords',
            name='intent',
        ),
        # Add seed_keyword FK
        migrations.AddField(
            model_name='keywords',
            name='seed_keyword',
            field=models.ForeignKey(
                help_text='Reference to the global seed keyword',
                on_delete=django.db.models.deletion.PROTECT,
                related_name='site_keywords',
                to='igny8_core_auth.seedkeyword',
                null=True  # Temporarily nullable for migration
            ),
        ),
        # Add override fields
        migrations.AddField(
            model_name='keywords',
            name='volume_override',
            field=models.IntegerField(blank=True, help_text='Site-specific volume override (uses seed_keyword.volume if not set)', null=True),
        ),
        migrations.AddField(
            model_name='keywords',
            name='difficulty_override',
            field=models.IntegerField(blank=True, help_text='Site-specific difficulty override (uses seed_keyword.difficulty if not set)', null=True),
        ),
        # Make seed_keyword required (after data migration if needed)
        migrations.AlterField(
            model_name='keywords',
            name='seed_keyword',
            field=models.ForeignKey(
                help_text='Reference to the global seed keyword',
                on_delete=django.db.models.deletion.PROTECT,
                related_name='site_keywords',
                to='igny8_core_auth.seedkeyword'
            ),
        ),
        # Add unique constraint
        migrations.AlterUniqueTogether(
            name='keywords',
            unique_together={('seed_keyword', 'site', 'sector')},
        ),
        # Update indexes
        migrations.AlterIndexTogether(
            name='keywords',
            index_together=set(),
        ),
        # Add new indexes
        migrations.AddIndex(
            model_name='keywords',
            index=models.Index(fields=['seed_keyword'], name='igny8_keyw_seed_k_12345_idx'),
        ),
        migrations.AddIndex(
            model_name='keywords',
            index=models.Index(fields=['seed_keyword', 'site', 'sector'], name='igny8_keyw_seed_si_67890_idx'),
        ),
    ]

