# Generated by Django 5.1.4 on 2025-01-15 15:11

import django.core.validators
import django.db.models.deletion
import shared_models.constants
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='SystemSetting',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('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)),
                ('name', models.CharField(max_length=255)),
                ('description', models.TextField(blank=True, null=True)),
                ('setting_type', models.CharField(choices=[('email', 'email'), ('security', 'security'), ('kyc', 'kyc'), ('commission', 'commission')], max_length=50)),
                ('status', models.CharField(choices=[('active', 'active'), ('inactive', 'inactive'), ('pending', 'pending')], default=shared_models.constants.SettingStatus['INACTIVE'], max_length=20)),
                ('is_enabled', models.BooleanField(default=False)),
                ('metadata', models.JSONField(blank=True, default=dict)),
            ],
            options={
                'verbose_name': 'System Setting',
                'verbose_name_plural': 'System Settings',
                'db_table': 'system_settings',
                'ordering': ['-created_at'],
                'permissions': [('add_system_setting', 'Can add system setting'), ('change_system_setting', 'Can change system setting'), ('delete_system_setting', 'Can delete system setting'), ('view_system_setting', 'Can view system setting')],
            },
        ),
        migrations.CreateModel(
            name='EmailConfiguration',
            fields=[
                ('systemsetting_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='system_settings.systemsetting')),
                ('provider', models.CharField(choices=[('smtp', 'smtp'), ('sendgrid', 'sendgrid')], default=shared_models.constants.EmailProvider['SMTP'], max_length=50)),
                ('from_email', models.EmailField(max_length=254, validators=[django.core.validators.EmailValidator()])),
                ('reply_to', models.EmailField(blank=True, max_length=254, null=True, validators=[django.core.validators.EmailValidator()])),
                ('use_tls', models.BooleanField(default=True, help_text='Use TLS encryption for SMTP')),
                ('use_ssl', models.BooleanField(default=False, help_text="Use SSL encryption for SMTP. Don't enable both TLS and SSL.")),
                ('timeout', models.IntegerField(default=30, help_text='Connection timeout in seconds')),
                ('debug_level', models.IntegerField(default=0, help_text='SMTP debug level (0-2). Higher values for more verbose logging.')),
            ],
            options={
                'verbose_name': 'Email Configuration',
                'verbose_name_plural': 'Email Configurations',
                'db_table': 'system_email_configuration',
                'permissions': [('add_email_configuration', 'Can add email configuration'), ('change_email_configuration', 'Can change email configuration'), ('delete_email_configuration', 'Can delete email configuration'), ('view_email_configuration', 'Can view email configuration')],
            },
            bases=('system_settings.systemsetting',),
        ),
        migrations.CreateModel(
            name='EmailTemplate',
            fields=[
                ('systemsetting_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='system_settings.systemsetting')),
                ('html_template', models.TextField(default='<!DOCTYPE html>\n<html>\n<head>\n    <meta charset="utf-8">\n    <meta name="viewport" content="width=device-width, initial-scale=1.0">\n</head>\n<body>\n    <div>___header___</div>\n    <div>___main_content___</div>\n    <div>___footer___</div>\n</body>\n</html>', help_text='HTML template with placeholders like ___content1___, ___button1Title___')),
                ('content_placeholders', models.JSONField(default=list, help_text="List of content placeholders in the template (e.g., ['content1', 'button1Title'])")),
            ],
            options={
                'verbose_name': 'Email Template',
                'verbose_name_plural': 'Email Templates',
                'db_table': 'system_email_template',
                'permissions': [('add_email_template', 'Can add email template'), ('change_email_template', 'Can change email template'), ('delete_email_template', 'Can delete email template'), ('view_email_template', 'Can view email template')],
            },
            bases=('system_settings.systemsetting',),
        ),
        migrations.CreateModel(
            name='SystemEmail',
            fields=[
                ('systemsetting_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='system_settings.systemsetting')),
                ('available_variables', models.JSONField(default=list, help_text="Additional variables specific to this type of system email (e.g., ['order_number', 'amount']). Base variables are automatically included.")),
                ('cc', models.JSONField(default=list)),
                ('bcc', models.JSONField(default=list)),
                ('trigger_event', models.CharField(help_text='Event that triggers this email. Must be one of the predefined trigger events.', max_length=255)),
                ('template', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='system_settings.emailtemplate')),
            ],
            options={
                'verbose_name': 'System Email',
                'verbose_name_plural': 'System Emails',
                'db_table': 'system_email',
                'permissions': [('add_system_email', 'Can add system email'), ('change_system_email', 'Can change system email'), ('delete_system_email', 'Can delete system email'), ('view_system_email', 'Can view system email')],
            },
            bases=('system_settings.systemsetting',),
        ),
        migrations.CreateModel(
            name='EmailContent',
            fields=[
                ('systemsetting_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='system_settings.systemsetting')),
                ('language_code', models.CharField(max_length=10)),
                ('subject', models.CharField(max_length=255)),
                ('content_sections', models.JSONField(default=dict, help_text='Dict mapping template placeholders to content. Content can include any variables in {{ variable }} format.')),
                ('content_type', models.CharField(choices=[('text', 'text'), ('html', 'html')], default=shared_models.constants.ContentType['HTML'], max_length=20)),
                ('system_email', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contents', to='system_settings.systememail')),
            ],
            options={
                'verbose_name': 'Email Content',
                'verbose_name_plural': 'Email Contents',
                'db_table': 'system_email_content',
                'permissions': [('add_email_content', 'Can add email content'), ('change_email_content', 'Can change email content'), ('delete_email_content', 'Can delete email content'), ('view_email_content', 'Can view email content')],
                'unique_together': {('system_email', 'language_code', 'content_type')},
            },
            bases=('system_settings.systemsetting',),
        ),
    ]
