import uuid

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('notifications', '0004_alter_notification_id_alter_notificationtemplate_id'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.AddField(
            model_name='notification',
            name='is_read',
            field=models.BooleanField(db_index=True, default=False),
        ),
        migrations.AddField(
            model_name='notification',
            name='payload',
            field=models.JSONField(blank=True, default=dict),
        ),
        migrations.AddField(
            model_name='notification',
            name='read_at',
            field=models.DateTimeField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name='notification',
            name='channel',
            field=models.CharField(choices=[('in_app', 'In App'), ('email', 'Email'), ('sms', 'SMS'), ('push', 'Push'), ('whatsapp', 'WhatsApp')], max_length=20),
        ),
        migrations.CreateModel(
            name='NotificationCampaign',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('title', models.CharField(max_length=255)),
                ('message', models.TextField()),
                ('audience', models.CharField(choices=[('all', 'All Users'), ('active', 'Active Users'), ('role', 'Role Based')], default='all', max_length=20)),
                ('role', models.CharField(blank=True, max_length=50)),
                ('delivery_channel', models.CharField(choices=[('in_app', 'In App'), ('push', 'Push'), ('both', 'In App + Push')], default='both', max_length=20)),
                ('mode', models.CharField(choices=[('instant', 'Instant'), ('scheduled', 'Scheduled')], default='instant', max_length=20)),
                ('scheduled_at', models.DateTimeField(blank=True, db_index=True, null=True)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('scheduled', 'Scheduled'), ('sent', 'Sent'), ('failed', 'Failed')], db_index=True, default='draft', max_length=20)),
                ('sent_at', models.DateTimeField(blank=True, null=True)),
                ('total_recipients', models.PositiveIntegerField(default=0)),
                ('total_sent', models.PositiveIntegerField(default=0)),
                ('total_failed', models.PositiveIntegerField(default=0)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_notification_campaigns', to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='UserDeviceToken',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('platform', models.CharField(choices=[('android', 'Android'), ('ios', 'iOS'), ('web', 'Web')], default='android', max_length=20)),
                ('device_token', models.CharField(db_index=True, max_length=512, unique=True)),
                ('last_seen_at', models.DateTimeField(auto_now=True)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='device_tokens', to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.AddIndex(
            model_name='notificationcampaign',
            index=models.Index(fields=['status', 'scheduled_at'], name='notificatio_status_8150c2_idx'),
        ),
        migrations.AddIndex(
            model_name='notificationcampaign',
            index=models.Index(fields=['created_at'], name='notificatio_created_00d10b_idx'),
        ),
        migrations.AddIndex(
            model_name='userdevicetoken',
            index=models.Index(fields=['user', 'platform'], name='notificatio_user_id_49fa46_idx'),
        ),
        migrations.AddIndex(
            model_name='userdevicetoken',
            index=models.Index(fields=['is_active'], name='notificatio_is_acti_3e2fa2_idx'),
        ),
    ]
