# Generated by Django 5.2.10 on 2026-01-11 20:42

import apps.core.choices.fields
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("support", "0005_alter_report_report_type_alter_report_status"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="EmailThread",
            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)),
                (
                    "message_id",
                    models.CharField(blank=True, help_text="Email message ID for threading", max_length=255),
                ),
                ("from_email", models.EmailField(help_text="Sender email address", max_length=254)),
                ("to_email", models.EmailField(help_text="Recipient email address", max_length=254)),
                ("subject", models.CharField(max_length=255)),
                ("body_text", models.TextField(help_text="Plain text email body")),
                (
                    "direction",
                    apps.core.choices.fields.RichChoiceField(
                        allow_deprecated=False,
                        choice_group="email_directions",
                        choices=[("inbound", "Inbound"), ("outbound", "Outbound")],
                        domain="support",
                        help_text="Whether email is inbound or outbound",
                        max_length=10,
                    ),
                ),
            ],
            options={
                "verbose_name": "Email Thread",
                "verbose_name_plural": "Email Threads",
                "ordering": ["created_at"],
                "abstract": False,
            },
        ),
        migrations.AddField(
            model_name="ticket",
            name="admin_notes",
            field=models.TextField(blank=True, help_text="Internal notes for administrators"),
        ),
        migrations.AddField(
            model_name="ticket",
            name="archived_at",
            field=models.DateTimeField(blank=True, help_text="When the ticket was archived", null=True),
        ),
        migrations.AddField(
            model_name="ticket",
            name="archived_by",
            field=models.ForeignKey(
                blank=True,
                help_text="Staff member who archived this ticket",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="archived_tickets",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="ticket",
            name="assigned_to",
            field=models.ForeignKey(
                blank=True,
                help_text="Staff member assigned to this ticket",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="assigned_tickets",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="ticket",
            name="name",
            field=models.CharField(
                blank=True, help_text="Name of the submitter (for anonymous tickets)", max_length=255
            ),
        ),
        migrations.AddField(
            model_name="ticket",
            name="resolved_at",
            field=models.DateTimeField(blank=True, help_text="When the ticket was resolved", null=True),
        ),
        migrations.AddField(
            model_name="ticket",
            name="resolved_by",
            field=models.ForeignKey(
                blank=True,
                help_text="Staff member who resolved this ticket",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="resolved_tickets",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="ticket",
            name="ticket_number",
            field=models.CharField(blank=True, help_text="Human-readable ticket number", max_length=20, unique=True),
        ),
        migrations.AddIndex(
            model_name="ticket",
            index=models.Index(fields=["status", "created_at"], name="support_tic_status_d0b46e_idx"),
        ),
        migrations.AddIndex(
            model_name="ticket",
            index=models.Index(fields=["ticket_number"], name="support_tic_ticket__d87f40_idx"),
        ),
        migrations.AddIndex(
            model_name="ticket",
            index=models.Index(fields=["archived_at"], name="support_tic_archive_8fe8c5_idx"),
        ),
        migrations.AddField(
            model_name="emailthread",
            name="sent_by",
            field=models.ForeignKey(
                blank=True,
                help_text="Staff member who sent this email (for outbound)",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="sent_email_threads",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="emailthread",
            name="ticket",
            field=models.ForeignKey(
                help_text="Associated support ticket",
                on_delete=django.db.models.deletion.CASCADE,
                related_name="email_threads",
                to="support.ticket",
            ),
        ),
    ]
