# Generated by Django 6.0.1 on 2026-03-21 15:44

import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('master_admin', '0003_remove_schoollevel_master_admi_code_a4093c_idx_and_more'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='EmailTemplate',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('name', models.CharField(max_length=255, unique=True)),
                ('subject', models.CharField(max_length=500)),
                ('body', models.TextField(help_text='Use {{school_name}}, {{email}}, or any {{variable}} placeholders')),
                ('description', models.TextField(blank=True, null=True)),
                ('status', models.CharField(choices=[('active', 'Active'), ('inactive', 'Inactive'), ('draft', 'Draft')], default='active', max_length=20)),
                ('tags', models.JSONField(blank=True, default=list)),
                ('variables_used', models.JSONField(blank=True, default=list, help_text='Auto-detected list of {{variable}} placeholders in this template')),
                ('created_at', models.DateTimeField(blank=True, null=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_email_templates', to=settings.AUTH_USER_MODEL)),
                ('updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_email_templates', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='BulkEmailLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('template_name_snapshot', models.CharField(blank=True, help_text='Snapshot of template name at send time', max_length=255, null=True)),
                ('to_emails', models.TextField(help_text='Comma-separated list of To addresses')),
                ('cc_emails', models.TextField(blank=True, help_text='Comma-separated list of CC addresses', null=True)),
                ('rendered_subject', models.CharField(max_length=500)),
                ('rendered_body', models.TextField()),
                ('context_data', models.JSONField(blank=True, default=dict, help_text='Variables passed to render the template')),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('sent', 'Sent'), ('failed', 'Failed'), ('bounced', 'Bounced')], default='pending', max_length=20)),
                ('error_message', models.TextField(blank=True, null=True)),
                ('sent_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(blank=True, null=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('sent_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sent_bulk_emails', to=settings.AUTH_USER_MODEL)),
                ('template', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='email_logs', to='master_admin.emailtemplate')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddIndex(
            model_name='emailtemplate',
            index=models.Index(fields=['status'], name='master_admi_status_5770dc_idx'),
        ),
        migrations.AddIndex(
            model_name='emailtemplate',
            index=models.Index(fields=['name'], name='master_admi_name_bb0983_idx'),
        ),
        migrations.AddIndex(
            model_name='emailtemplate',
            index=models.Index(fields=['created_at'], name='master_admi_created_db11db_idx'),
        ),
        migrations.AddIndex(
            model_name='bulkemaillog',
            index=models.Index(fields=['status'], name='master_admi_status_6d3b12_idx'),
        ),
        migrations.AddIndex(
            model_name='bulkemaillog',
            index=models.Index(fields=['template'], name='master_admi_templat_5bcdd1_idx'),
        ),
        migrations.AddIndex(
            model_name='bulkemaillog',
            index=models.Index(fields=['sent_at'], name='master_admi_sent_at_70c8f4_idx'),
        ),
        migrations.AddIndex(
            model_name='bulkemaillog',
            index=models.Index(fields=['sent_by'], name='master_admi_sent_by_9c7c59_idx'),
        ),
        migrations.AddIndex(
            model_name='bulkemaillog',
            index=models.Index(fields=['created_at'], name='master_admi_created_744474_idx'),
        ),
    ]
