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


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("accounts", "0001_initial"),
        ("projects", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="Notification",
            fields=[
                ("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "notification_type",
                    models.CharField(
                        choices=[("task", "Task"), ("team", "Team"), ("billing", "Billing"), ("system", "System")],
                        default="system",
                        max_length=24,
                    ),
                ),
                (
                    "priority",
                    models.CharField(
                        choices=[("ok", "OK"), ("warn", "Warn"), ("err", "Error"), ("info", "Info")],
                        default="info",
                        max_length=24,
                    ),
                ),
                ("title", models.CharField(max_length=200)),
                ("brief", models.CharField(blank=True, max_length=300)),
                ("body", models.TextField(blank=True)),
                ("source", models.CharField(blank=True, max_length=120)),
                ("stage", models.CharField(blank=True, max_length=120)),
                ("owner_label", models.CharField(blank=True, max_length=120)),
                ("cost_label", models.CharField(blank=True, max_length=64)),
                ("related_url", models.CharField(blank=True, max_length=300)),
                ("dedupe_key", models.CharField(blank=True, max_length=160)),
                ("is_read", models.BooleanField(default=False)),
                ("read_at", models.DateTimeField(blank=True, null=True)),
                ("archived_at", models.DateTimeField(blank=True, null=True)),
                ("metadata", models.JSONField(blank=True, default=dict)),
                (
                    "project",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="notifications",
                        to="projects.project",
                    ),
                ),
                (
                    "recipient",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="notifications",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "team",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="notifications",
                        to="accounts.team",
                    ),
                ),
            ],
            options={
                "ordering": ["-created_at"],
            },
        ),
        migrations.AddIndex(
            model_name="notification",
            index=models.Index(fields=["team", "recipient", "is_read", "-created_at"], name="ops_notific_team_id_17a7ca_idx"),
        ),
        migrations.AddIndex(
            model_name="notification",
            index=models.Index(fields=["team", "archived_at", "-created_at"], name="ops_notific_team_id_691eaf_idx"),
        ),
        migrations.AddIndex(
            model_name="notification",
            index=models.Index(fields=["team", "dedupe_key"], name="ops_notific_team_id_8acdf4_idx"),
        ),
        migrations.AddConstraint(
            model_name="notification",
            constraint=models.UniqueConstraint(
                condition=~models.Q(dedupe_key=""),
                fields=("team", "dedupe_key"),
                name="ops_notification_team_dedupe_key_unique",
            ),
        ),
    ]
