# Generated by Django 5.0.7 on 2024-07-17 16:49

import django.core.files.storage
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="EmailMessage",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="Created At"),
                ),
                (
                    "modified_at",
                    models.DateTimeField(auto_now=True, verbose_name="Modified At"),
                ),
                (
                    "uid",
                    models.IntegerField(
                        blank=True,
                        db_comment="IMAP Server Unique Identifier.",
                        help_text="IMAP Server Unique Identifier.",
                        null=True,
                        verbose_name="IMAP UID",
                    ),
                ),
                (
                    "message_id",
                    models.CharField(
                        db_comment="Message ID of the email",
                        editable=False,
                        help_text="Message ID of the email",
                        max_length=255,
                        verbose_name="Message-ID Header",
                    ),
                ),
                (
                    "subject",
                    models.CharField(
                        db_comment="The subject of the email.",
                        help_text="The subject of the email.",
                        max_length=255,
                        verbose_name="Subject",
                    ),
                ),
                (
                    "from_address",
                    models.EmailField(
                        db_comment="The sender's email address.",
                        help_text="The sender's email address.",
                        max_length=254,
                        verbose_name="From Address",
                    ),
                ),
                (
                    "to_address",
                    models.TextField(
                        db_comment="List of recipient email addresses, separated by commas.",
                        help_text="List of recipient email addresses.",
                        verbose_name="To Address",
                    ),
                ),
                (
                    "cc_address",
                    models.TextField(
                        blank=True,
                        db_comment="List of CC recipient email addresses, separated by commas.",
                        help_text="List of CC recipient email addresses.",
                        verbose_name="CC Address",
                    ),
                ),
                (
                    "bcc_address",
                    models.TextField(
                        blank=True,
                        db_comment="List of BCC recipient email addresses, separated by commas.",
                        help_text="List of BCC recipient email addresses.",
                        verbose_name="BCC Address",
                    ),
                ),
                (
                    "date",
                    models.DateTimeField(
                        blank=True,
                        db_comment="The date the email was sent, in ISO format.",
                        help_text="The date the email was sent.",
                        null=True,
                        verbose_name="Date",
                    ),
                ),
                ("raw", models.BinaryField(blank=True, null=True)),
                (
                    "plain_body",
                    models.TextField(
                        db_comment="The plain text body content of the email.",
                        help_text="The plain text body content of the email.",
                        verbose_name="Plain Body",
                    ),
                ),
                (
                    "html_body",
                    models.TextField(
                        db_comment="The HTML body content of the email.",
                        help_text="The HTML body content of the email.",
                        verbose_name="HTML Body",
                    ),
                ),
                ("headers", models.JSONField(default=dict)),
                (
                    "is_read",
                    models.BooleanField(
                        db_comment="Indicates whether the email has been read.",
                        default=False,
                        help_text="Indicates whether the email has been read.",
                        verbose_name="Is Read",
                    ),
                ),
                (
                    "is_flagged",
                    models.BooleanField(
                        db_comment="Indicates whether the email has been flagged.",
                        default=False,
                        help_text="Indicates whether the email has been flagged.",
                        verbose_name="Is Flagged",
                    ),
                ),
                (
                    "size",
                    models.PositiveIntegerField(
                        blank=True,
                        db_comment="Size of the email in bytes.",
                        default=0,
                        help_text="Size of the email in bytes.",
                        null=True,
                        verbose_name="Size",
                    ),
                ),
            ],
            options={
                "verbose_name": "Email Message",
                "verbose_name_plural": "Email Messages",
                "db_table": "sage_email_message",
                "db_table_comment": "Model representing an email message.",
                "ordering": ["-date"],
                "default_manager_name": "objects",
            },
        ),
        migrations.CreateModel(
            name="Flag",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        choices=[
                            ("SEEN", "Seen"),
                            ("ANSWERED", "Answered"),
                            ("FLAGGED", "Flagged"),
                            ("DELETED", "Deleted"),
                            ("DRAFT", "Draft"),
                            ("RECENT", "Recent"),
                        ],
                        max_length=20,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Archive",
            fields=[],
            options={
                "verbose_name": "Archive Email",
                "verbose_name_plural": "Archive Emails",
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("sage_mailbox.emailmessage",),
        ),
        migrations.CreateModel(
            name="Draft",
            fields=[],
            options={
                "verbose_name": "Draft Email",
                "verbose_name_plural": "Draft Emails",
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("sage_mailbox.emailmessage",),
        ),
        migrations.CreateModel(
            name="Inbox",
            fields=[],
            options={
                "verbose_name": "Inbox Email",
                "verbose_name_plural": "Inbox Emails",
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("sage_mailbox.emailmessage",),
        ),
        migrations.CreateModel(
            name="Junk",
            fields=[],
            options={
                "verbose_name": "Junk Email",
                "verbose_name_plural": "Junk Emails",
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("sage_mailbox.emailmessage",),
        ),
        migrations.CreateModel(
            name="Sent",
            fields=[],
            options={
                "verbose_name": "Sent Email",
                "verbose_name_plural": "Sent Emails",
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("sage_mailbox.emailmessage",),
        ),
        migrations.CreateModel(
            name="Trash",
            fields=[],
            options={
                "verbose_name": "Trash Email",
                "verbose_name_plural": "Trash Emails",
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("sage_mailbox.emailmessage",),
        ),
        migrations.AddField(
            model_name="emailmessage",
            name="flags",
            field=models.ManyToManyField(
                blank=True, related_name="email_flags", to="sage_mailbox.flag"
            ),
        ),
        migrations.CreateModel(
            name="Mailbox",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="Created At"),
                ),
                (
                    "modified_at",
                    models.DateTimeField(auto_now=True, verbose_name="Modified At"),
                ),
                (
                    "name",
                    models.CharField(
                        db_comment="The unique name identifying the mailbox.",
                        help_text="The unique name of the mailbox.",
                        max_length=255,
                        unique=True,
                        verbose_name="Name",
                    ),
                ),
                (
                    "slug",
                    models.SlugField(
                        allow_unicode=True,
                        db_comment="The unique slug generated from the mailbox name.",
                        help_text="The unique slug for the mailbox, generated from the name.",
                        max_length=255,
                        unique=True,
                        verbose_name="Slug",
                    ),
                ),
            ],
            options={
                "verbose_name": "Mailbox",
                "verbose_name_plural": "Mailboxes",
                "db_table": "sage_mailbox",
                "db_table_comment": "Model representing a mailbox which can be nested under another mailbox.",
                "indexes": [
                    models.Index(fields=["name"], name="idx_mailbox_name"),
                    models.Index(fields=["slug"], name="idx_mailbox_slug"),
                ],
            },
        ),
        migrations.AddField(
            model_name="emailmessage",
            name="mailbox",
            field=models.ForeignKey(
                db_comment="The mailbox to which this email belongs.",
                help_text="The mailbox to which this email belongs.",
                on_delete=django.db.models.deletion.CASCADE,
                related_name="emails",
                to="sage_mailbox.mailbox",
                verbose_name="Mailbox",
            ),
        ),
        migrations.CreateModel(
            name="Attachment",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="Created At"),
                ),
                (
                    "modified_at",
                    models.DateTimeField(auto_now=True, verbose_name="Modified At"),
                ),
                (
                    "attachment_id",
                    models.CharField(blank=True, max_length=255, null=True),
                ),
                (
                    "file",
                    models.FileField(
                        db_comment="The file attached to the email.",
                        help_text="The file attached to the email.",
                        storage=django.core.files.storage.FileSystemStorage(
                            "sage_mailbox/attachments/"
                        ),
                        upload_to="attachments/%Y/%m/%d/",
                        verbose_name="File",
                    ),
                ),
                (
                    "filename",
                    models.CharField(
                        db_comment="The original filename of the attachment.",
                        help_text="The original filename of the attachment.",
                        max_length=255,
                        verbose_name="Filename",
                    ),
                ),
                (
                    "content_type",
                    models.CharField(
                        db_comment="The MIME type of the attachment.",
                        help_text="The MIME type of the attachment.",
                        max_length=255,
                        verbose_name="Content Type",
                    ),
                ),
                ("payload", models.BinaryField()),
                ("content_id", models.CharField(blank=True, max_length=255, null=True)),
                (
                    "content_transfer_encoding",
                    models.CharField(blank=True, max_length=255, null=True),
                ),
                (
                    "email_message",
                    models.ForeignKey(
                        db_comment="The email message to which this attachment belongs.",
                        help_text="The email message to which this attachment belongs.",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="attachments",
                        to="sage_mailbox.emailmessage",
                        verbose_name="Email Message",
                    ),
                ),
            ],
            options={
                "verbose_name": "Attachment",
                "verbose_name_plural": "Attachments",
                "db_table": "sage_attachment",
                "db_table_comment": "Model representing an attachment to an email message.",
                "indexes": [
                    models.Index(fields=["filename"], name="idx_attachment_filename")
                ],
            },
        ),
        migrations.AddIndex(
            model_name="emailmessage",
            index=models.Index(fields=["subject"], name="idx_email_subject"),
        ),
        migrations.AddIndex(
            model_name="emailmessage",
            index=models.Index(fields=["from_address"], name="idx_email_from_address"),
        ),
        migrations.AddIndex(
            model_name="emailmessage",
            index=models.Index(fields=["date"], name="idx_email_date"),
        ),
    ]
