"""Rename TaskImages, add Content model, and keyword links"""
from django.core.validators import MinValueValidator
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('planner', '0004_add_keyword_objects_to_contentideas'),
        ('writer', '0001_initial'),
    ]

    operations = [
        migrations.RenameModel(
            old_name='TaskImages',
            new_name='Images',
        ),
        migrations.AlterModelTable(
            name='images',
            table='igny8_images',
        ),
        migrations.AlterModelOptions(
            name='images',
            options={'ordering': ['task', 'position', '-created_at']},
        ),
        migrations.AddField(
            model_name='tasks',
            name='keyword_objects',
            field=models.ManyToManyField(blank=True, help_text='Individual keywords linked to this task', related_name='tasks', to='planner.keywords'),
        ),
        migrations.CreateModel(
            name='Content',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('html_content', models.TextField(help_text='Final AI-generated HTML content')),
                ('word_count', models.IntegerField(default=0, help_text='Word count of generated content', validators=[MinValueValidator(0)])),
                ('metadata', models.JSONField(default=dict, help_text='Additional metadata (SEO, structure, etc.)')),
                ('generated_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('sector', models.ForeignKey(on_delete=models.CASCADE, related_name='content_set', to='igny8_core_auth.sector')),
                ('site', models.ForeignKey(on_delete=models.CASCADE, related_name='content_set', to='igny8_core_auth.site')),
                ('task', models.OneToOneField(help_text='The task this content belongs to', on_delete=models.CASCADE, related_name='content_record', to='writer.tasks')),
                ('tenant', models.ForeignKey(on_delete=models.CASCADE, related_name='content_set', to='igny8_core_auth.tenant')),
            ],
            options={
                'db_table': 'igny8_content',
                'ordering': ['-generated_at'],
            },
        ),
        migrations.AddIndex(
            model_name='images',
            index=models.Index(fields=['task', 'position'], name='igny8_images_task_id_pos_idx'),
        ),
        migrations.AddIndex(
            model_name='content',
            index=models.Index(fields=['task'], name='igny8_content_task_id_idx'),
        ),
        migrations.AddIndex(
            model_name='content',
            index=models.Index(fields=['generated_at'], name='igny8_content_generated_idx'),
        ),
    ]

