# Generated by Django 5.2.8 on 2025-12-08 07:05

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


class Migration(migrations.Migration):

    dependencies = [
        ('messaging', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='BroadcastMessage',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('subject', models.CharField(help_text='Message subject (for email) or title (for in-app)', max_length=255)),
                ('body', models.TextField(help_text='Message body content')),
                ('target_owners', models.BooleanField(default=False, help_text='Send to all owners')),
                ('target_managers', models.BooleanField(default=False, help_text='Send to all managers')),
                ('target_staff', models.BooleanField(default=False, help_text='Send to all staff')),
                ('target_customers', models.BooleanField(default=False, help_text='Send to all customers')),
                ('delivery_method', models.CharField(choices=[('in_app', 'In-App Notification'), ('email', 'Email'), ('sms', 'SMS'), ('all', 'All Channels')], default='in_app', help_text='How to deliver the message', max_length=20)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('scheduled', 'Scheduled'), ('sending', 'Sending'), ('sent', 'Sent'), ('failed', 'Failed')], db_index=True, default='draft', max_length=20)),
                ('scheduled_at', models.DateTimeField(blank=True, help_text='When to send the message (null = send immediately)', null=True)),
                ('total_recipients', models.PositiveIntegerField(default=0, help_text='Total number of recipients')),
                ('delivered_count', models.PositiveIntegerField(default=0, help_text='Number of successful deliveries')),
                ('failed_count', models.PositiveIntegerField(default=0, help_text='Number of failed deliveries')),
                ('read_count', models.PositiveIntegerField(default=0, help_text='Number of recipients who read the message')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('sent_at', models.DateTimeField(blank=True, help_text='When the message was actually sent', null=True)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='MessageRecipient',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('delivery_status', models.CharField(choices=[('pending', 'Pending'), ('delivered', 'Delivered'), ('failed', 'Failed'), ('bounced', 'Bounced')], default='pending', max_length=20)),
                ('delivered_at', models.DateTimeField(blank=True, null=True)),
                ('is_read', models.BooleanField(default=False)),
                ('read_at', models.DateTimeField(blank=True, null=True)),
                ('error_message', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
        ),
        migrations.RenameIndex(
            model_name='communicationsession',
            new_name='messaging_c_is_acti_26c502_idx',
            old_name='communicati_is_acti_ebcdc9_idx',
        ),
        migrations.AddField(
            model_name='broadcastmessage',
            name='individual_recipients',
            field=models.ManyToManyField(blank=True, help_text='Specific users to receive the message', related_name='received_broadcast_messages', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='broadcastmessage',
            name='sender',
            field=models.ForeignKey(help_text='User who sent the message', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sent_broadcast_messages', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='messagerecipient',
            name='message',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='recipients', to='messaging.broadcastmessage'),
        ),
        migrations.AddField(
            model_name='messagerecipient',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='message_deliveries', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddIndex(
            model_name='broadcastmessage',
            index=models.Index(fields=['status', 'scheduled_at'], name='messaging_b_status_16f15e_idx'),
        ),
        migrations.AddIndex(
            model_name='broadcastmessage',
            index=models.Index(fields=['sender', 'created_at'], name='messaging_b_sender__65f622_idx'),
        ),
        migrations.AddIndex(
            model_name='messagerecipient',
            index=models.Index(fields=['message', 'delivery_status'], name='messaging_m_message_59ed8d_idx'),
        ),
        migrations.AddIndex(
            model_name='messagerecipient',
            index=models.Index(fields=['user', 'is_read'], name='messaging_m_user_id_c6b099_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='messagerecipient',
            unique_together={('message', 'user')},
        ),
    ]
