# Generated by Django 3.2.4 on 2021-07-22 17:05

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import packman.mail.models
import uuid


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('committees', '0017_auto_20210720_1640'),
        ('dens', '0008_auto_20210720_1640'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='DistributionList',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date_added', models.DateTimeField(auto_now_add=True, help_text='Date and time this entry was first added to the database.', verbose_name='created')),
                ('last_updated', models.DateTimeField(auto_now=True, help_text='Date and time this entry was last changed in the database.', verbose_name='modified')),
                ('name', models.CharField(max_length=150, unique=True, verbose_name='name')),
                ('is_all', models.BooleanField(default=False, help_text='Messages sent to this distribution list should be delivered to all active members of the Pack.', verbose_name='all members')),
                ('committees', models.ManyToManyField(blank=True, related_name='distribution_list', related_query_name='distribution_list', to='committees.Committee')),
                ('dens', models.ManyToManyField(blank=True, related_name='distribution_list', related_query_name='distribution_list', to='dens.Den')),
            ],
            options={
                'verbose_name': 'Distribution List',
                'verbose_name_plural': 'Distribution Lists',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Message',
            fields=[
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, verbose_name='UUID')),
                ('date_added', models.DateTimeField(auto_now_add=True, help_text='Date and time this entry was first added to the database.', verbose_name='created')),
                ('last_updated', models.DateTimeField(auto_now=True, help_text='Date and time this entry was last changed in the database.', verbose_name='modified')),
                ('subject', models.CharField(max_length=150, verbose_name='subject')),
                ('body', models.TextField(verbose_name='body')),
                ('date_sent', models.DateTimeField(blank=True, null=True, verbose_name='sent')),
                ('author', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, related_name='sent_messages', related_query_name='sent_message', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Message',
                'verbose_name_plural': 'Messages',
                'ordering': ['-last_updated'],
                'get_latest_by': 'last_updated',
            },
        ),
        migrations.CreateModel(
            name='Settings',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date_added', models.DateTimeField(auto_now_add=True, help_text='Date and time this entry was first added to the database.', verbose_name='created')),
                ('last_updated', models.DateTimeField(auto_now=True, help_text='Date and time this entry was last changed in the database.', verbose_name='modified')),
                ('list_name', models.CharField(blank=True, max_length=100, verbose_name='list name')),
                ('list_description', models.CharField(blank=True, max_length=150, verbose_name='list description')),
                ('list_subject', models.CharField(blank=True, max_length=20, verbose_name='subject line prefix')),
                ('list_id', models.CharField(blank=True, max_length=100, verbose_name='list ID')),
                ('list_help', models.CharField(blank=True, max_length=100, verbose_name='help ')),
                ('list_from', models.EmailField(blank=True, max_length=100, verbose_name='from')),
            ],
            options={
                'verbose_name': 'Settings',
                'verbose_name_plural': 'Settings',
            },
        ),
        migrations.CreateModel(
            name='Thread',
            fields=[
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, verbose_name='UUID')),
                ('date_added', models.DateTimeField(auto_now_add=True, help_text='Date and time this entry was first added to the database.', verbose_name='created')),
                ('last_updated', models.DateTimeField(auto_now=True, help_text='Date and time this entry was last changed in the database.', verbose_name='modified')),
            ],
            options={
                'verbose_name': 'Thread',
                'verbose_name_plural': 'Threads',
            },
        ),
        migrations.CreateModel(
            name='MessageRecipient',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('delivery', models.CharField(choices=[('to', 'To'), ('cc', 'Cc'), ('bcc', 'Bcc')], default='to', max_length=3, verbose_name='')),
                ('from_distro', models.BooleanField(default=False, help_text='Specify whether this recipient was included in the message directly or as part of a larger distribution list.', verbose_name='distribution list')),
                ('date_received', models.DateTimeField(auto_now_add=True, verbose_name='received')),
                ('date_read', models.DateTimeField(blank=True, null=True, verbose_name='read')),
                ('date_archived', models.DateTimeField(blank=True, null=True, verbose_name='archived')),
                ('date_deleted', models.DateTimeField(blank=True, null=True, verbose_name='deleted')),
                ('message', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_query_name='message_recipient', to='mail.message')),
                ('recipient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_query_name='message_recipient', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Message Recipient',
                'verbose_name_plural': 'Message Recipients',
            },
        ),
        migrations.CreateModel(
            name='MessageDistribution',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('delivery', models.CharField(choices=[('to', 'To'), ('cc', 'Cc'), ('bcc', 'Bcc')], default='to', max_length=3, verbose_name='')),
                ('distribution_list', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_query_name='message_distribution_list', to='mail.distributionlist')),
                ('message', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_query_name='message_distribution_list', to='mail.message')),
            ],
            options={
                'verbose_name': 'Message Distribution List',
                'verbose_name_plural': 'Message Distribution Lists',
            },
        ),
        migrations.AddField(
            model_name='message',
            name='distribution_lists',
            field=models.ManyToManyField(blank=True, related_name='messages', through='mail.MessageDistribution', to='mail.DistributionList'),
        ),
        migrations.AddField(
            model_name='message',
            name='parent',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='replies', to='mail.message', verbose_name='replying to'),
        ),
        migrations.AddField(
            model_name='message',
            name='recipients',
            field=models.ManyToManyField(blank=True, related_name='messages', through='mail.MessageRecipient', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='message',
            name='thread',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='mail.thread'),
        ),
        migrations.CreateModel(
            name='EmailAddress',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date_added', models.DateTimeField(auto_now_add=True, help_text='Date and time this entry was first added to the database.', verbose_name='created')),
                ('last_updated', models.DateTimeField(auto_now=True, help_text='Date and time this entry was last changed in the database.', verbose_name='modified')),
                ('address', models.EmailField(error_messages={'unique': 'A distribution list with this email address already exists.'}, max_length=254, unique=True, verbose_name='email address')),
                ('is_default', models.BooleanField(default=False, help_text='Indicates whether this address should be used as the default from address.', verbose_name='default')),
                ('distribution_list', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='addresses', to='mail.distributionlist')),
            ],
            options={
                'verbose_name': 'Email Address',
                'verbose_name_plural': 'Email Addresses',
                'ordering': ('-is_default', 'address'),
            },
        ),
        migrations.CreateModel(
            name='Attachment',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('filename', models.FileField(help_text='attachments should be under 5mb.', upload_to=packman.mail.models.get_upload_to, verbose_name='file')),
                ('message', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='mail.message')),
            ],
            options={
                'verbose_name': 'Attachment',
                'verbose_name_plural': 'Attachments',
            },
        ),
        migrations.AddConstraint(
            model_name='messagerecipient',
            constraint=models.UniqueConstraint(fields=('message', 'recipient'), name='unique_message_per_recipient'),
        ),
        migrations.AddConstraint(
            model_name='messagedistribution',
            constraint=models.UniqueConstraint(fields=('message', 'distribution_list'), name='unique_message_per_distribution_list'),
        ),
    ]
