# Generated by Django 4.2.20 on 2025-04-22 15:49

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('system_settings', '0014_alter_paymentgatewayconfig_payment_method_and_more'),
    ]

    operations = [
        migrations.CreateModel(
            name='EmailCampaign',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.CharField(blank=True, max_length=255, null=True)),
                ('updated_by', models.CharField(blank=True, max_length=255, null=True)),
                ('id', models.AutoField(editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=255, verbose_name='Campaign Name')),
                ('schedule_type', models.CharField(max_length=100, verbose_name='Schedule Type')),
                ('schedule_time', models.DateTimeField(verbose_name='Schedule Time')),
                ('status', models.CharField(choices=[('DRAFT', 'Draft'), ('SCHEDULED', 'Scheduled'), ('IN_PROGRESS', 'In Progress'), ('COMPLETED', 'Completed'), ('FAILED', 'Failed'), ('CANCELLED', 'Cancelled')], default='DRAFT', max_length=20, verbose_name='Status')),
                ('available_variables', models.JSONField(default=list, help_text='Variables that can be used in email content (e.g., ["customer_name", "account_number"])', verbose_name='Available Variables')),
                ('filters', models.JSONField(blank=True, default=dict, help_text='Flexible filtering criteria for targeting email recipients. Can include country, kycStatus, leadStatus, callStatus, isFunded, customerType, source, agentId, ibId, createdAtFrom, createdAtTo, and any other future filter criteria.', verbose_name='Filters')),
                ('template', models.ForeignKey(help_text='Email template with placeholders for content sections', on_delete=django.db.models.deletion.PROTECT, to='system_settings.emailtemplate')),
            ],
            options={
                'verbose_name': 'Email Campaign',
                'verbose_name_plural': 'Email Campaigns',
                'db_table': 'shared_email_campaign',
                'ordering': ['-created_at'],
                'permissions': [('view_email_campaign', 'Can view email campaign'), ('delete_email_campaign', 'Can delete email campaign'), ('change_email_campaign', 'Can change email campaign'), ('add_email_campaign', 'Can add email campaign')],
            },
        ),
        migrations.CreateModel(
            name='EmailCampaignEvent',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.CharField(blank=True, max_length=255, null=True)),
                ('updated_by', models.CharField(blank=True, max_length=255, null=True)),
                ('id', models.AutoField(editable=False, primary_key=True, serialize=False)),
                ('event_type', models.CharField(choices=[('SCHEDULED', 'Scheduled'), ('EDITED', 'Edited'), ('STARTING', 'Starting'), ('WARNING', 'Warning'), ('FAILED', 'Failed'), ('COMPLETED', 'Completed')], max_length=20, verbose_name='Event Type')),
                ('details', models.JSONField(blank=True, default=dict, help_text='Additional details about the event, such as error messages, success counts, etc.', verbose_name='Event Details')),
                ('description', models.TextField(blank=True, null=True, verbose_name='Description')),
                ('campaign', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='events', to='shared_email_campaign.emailcampaign')),
            ],
            options={
                'verbose_name': 'Email Campaign Event',
                'verbose_name_plural': 'Email Campaign Events',
                'db_table': 'shared_email_campaign_event',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['campaign'], name='shared_emai_campaig_6ca583_idx'), models.Index(fields=['event_type'], name='shared_emai_event_t_358605_idx'), models.Index(fields=['created_at'], name='shared_emai_created_6ec312_idx')],
            },
        ),
        migrations.CreateModel(
            name='EmailCampaignContent',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.CharField(blank=True, max_length=255, null=True)),
                ('updated_by', models.CharField(blank=True, max_length=255, null=True)),
                ('id', models.AutoField(editable=False, primary_key=True, serialize=False)),
                ('language_code', models.CharField(help_text='e.g., "en", "es", "fr"', max_length=10, verbose_name='Language Code')),
                ('subject', models.CharField(max_length=255, verbose_name='Email Subject')),
                ('content_sections', models.JSONField(default=dict, help_text='Dict mapping template placeholders to content structures. Each structure has "default" content and optional "condition_sets". Content can include {{ variables }}', verbose_name='Content Sections')),
                ('content_type', models.CharField(choices=[('HTML', 'HTML'), ('TEXT', 'TEXT')], default='HTML', max_length=20, verbose_name='Content Type')),
                ('campaign', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contents', to='shared_email_campaign.emailcampaign')),
            ],
            options={
                'verbose_name': 'Email Campaign Content',
                'verbose_name_plural': 'Email Campaign Contents',
                'db_table': 'shared_email_campaign_content',
                'ordering': ['-created_at'],
                'permissions': [('view_email_campaign_content', 'Can view email campaign content'), ('delete_email_campaign_content', 'Can delete email campaign content'), ('change_email_campaign_content', 'Can change email campaign content'), ('add_email_campaign_content', 'Can add email campaign content')],
                'indexes': [models.Index(fields=['campaign'], name='shared_emai_campaig_442532_idx'), models.Index(fields=['language_code'], name='shared_emai_languag_5d3689_idx')],
                'unique_together': {('campaign', 'language_code', 'content_type')},
            },
        ),
        migrations.AddIndex(
            model_name='emailcampaign',
            index=models.Index(fields=['name'], name='shared_emai_name_95ed16_idx'),
        ),
        migrations.AddIndex(
            model_name='emailcampaign',
            index=models.Index(fields=['schedule_type'], name='shared_emai_schedul_88b233_idx'),
        ),
        migrations.AddIndex(
            model_name='emailcampaign',
            index=models.Index(fields=['schedule_time'], name='shared_emai_schedul_571a3c_idx'),
        ),
        migrations.AddIndex(
            model_name='emailcampaign',
            index=models.Index(fields=['status'], name='shared_emai_status_bfa128_idx'),
        ),
    ]
