# Generated by Django 6.0 on 2026-02-03 21:15

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


class Migration(migrations.Migration):

    dependencies = [
        ('collections_management', '0001_initial'),
        ('tenancy', '0003_tenant_address_line1_tenant_address_line2_and_more'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='CollectionEmail',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('direction', models.CharField(choices=[('outbound', 'Outbound'), ('inbound', 'Inbound')], db_index=True, default='outbound', max_length=12)),
                ('source', models.CharField(choices=[('outlook', 'Outlook'), ('acx', 'ACX'), ('other', 'Other')], db_index=True, default='outlook', max_length=20)),
                ('from_address', models.CharField(blank=True, default='', max_length=255)),
                ('to', models.JSONField(blank=True, null=True)),
                ('cc', models.JSONField(blank=True, null=True)),
                ('bcc', models.JSONField(blank=True, null=True)),
                ('subject', models.CharField(blank=True, default='', max_length=255)),
                ('sent_at', models.DateTimeField(blank=True, db_index=True, null=True)),
                ('message_id', models.CharField(blank=True, default='', max_length=255)),
                ('raw_eml', models.FileField(blank=True, null=True, upload_to='collections/emails/raw/')),
                ('body_text', models.TextField(blank=True, default='')),
                ('body_html', models.TextField(blank=True, default='')),
                ('notes', models.TextField(blank=True, default='')),
                ('action', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='email_evidences', to='collections_management.collectionaction')),
                ('case', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='emails', to='collections_management.collectioncase')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_collection_emails', to=settings.AUTH_USER_MODEL)),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='collection_emails', to='tenancy.tenant')),
            ],
            options={
                'ordering': ['-sent_at', '-id'],
            },
        ),
        migrations.CreateModel(
            name='CollectionEmailAttachment',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('file', models.FileField(upload_to='collections/emails/attachments/')),
                ('filename', models.CharField(blank=True, default='', max_length=255)),
                ('content_type', models.CharField(blank=True, default='', max_length=120)),
                ('size', models.PositiveIntegerField(default=0)),
                ('email', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='collections_management.collectionemail')),
            ],
            options={
                'ordering': ['-id'],
            },
        ),
        migrations.AddIndex(
            model_name='collectionemail',
            index=models.Index(fields=['tenant', 'case', '-sent_at'], name='collections_tenant__66080c_idx'),
        ),
        migrations.AddIndex(
            model_name='collectionemail',
            index=models.Index(fields=['tenant', 'source'], name='collections_tenant__fff099_idx'),
        ),
        migrations.AddIndex(
            model_name='collectionemail',
            index=models.Index(fields=['tenant', 'direction'], name='collections_tenant__325567_idx'),
        ),
    ]
