# Generated by Django 5.2.5 on 2025-08-31 19:24

import django.core.validators
import django.db.models.deletion
import django.utils.timezone
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="NotificationChannel",
            fields=[
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when this record was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when this record was last modified",
                    ),
                ),
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier for this record",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Human-readable name for the notification channel",
                        max_length=100,
                        unique=True,
                    ),
                ),
                (
                    "channel_type",
                    models.CharField(
                        choices=[
                            ("telegram", "Telegram Bot"),
                            ("email", "Email"),
                            ("webhook", "Webhook"),
                            ("slack", "Slack"),
                            ("discord", "Discord"),
                            ("sms", "SMS"),
                        ],
                        help_text="Type of notification channel",
                        max_length=20,
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        db_index=True,
                        default=True,
                        help_text="Whether this notification channel is active",
                    ),
                ),
                (
                    "configuration",
                    models.JSONField(
                        default=dict,
                        help_text="Channel-specific configuration parameters",
                    ),
                ),
                (
                    "rate_limit",
                    models.PositiveIntegerField(
                        default=30,
                        help_text="Maximum number of messages per minute",
                        validators=[
                            django.core.validators.MinValueValidator(1),
                            django.core.validators.MaxValueValidator(1000),
                        ],
                    ),
                ),
                (
                    "retry_attempts",
                    models.PositiveIntegerField(
                        default=3,
                        help_text="Number of retry attempts for failed deliveries",
                        validators=[
                            django.core.validators.MinValueValidator(0),
                            django.core.validators.MaxValueValidator(10),
                        ],
                    ),
                ),
                (
                    "timeout_seconds",
                    models.PositiveIntegerField(
                        default=30,
                        help_text="Timeout for delivery attempts in seconds",
                        validators=[
                            django.core.validators.MinValueValidator(5),
                            django.core.validators.MaxValueValidator(300),
                        ],
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        help_text="User who created this notification channel",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="notification_channels",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Notification Channel",
                "verbose_name_plural": "Notification Channels",
                "ordering": ["name"],
            },
        ),
        migrations.CreateModel(
            name="NotificationTemplate",
            fields=[
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when this record was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when this record was last modified",
                    ),
                ),
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier for this record",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Name for this notification template",
                        max_length=100,
                        unique=True,
                    ),
                ),
                (
                    "template_type",
                    models.CharField(
                        choices=[
                            ("jingle_detected", "Jingle Detected"),
                            ("ad_break_started", "Ad Break Started"),
                            ("ad_break_ended", "Ad Break Ended"),
                            ("stream_started", "Stream Started"),
                            ("stream_stopped", "Stream Stopped"),
                            ("stream_error", "Stream Error"),
                            ("system_alert", "System Alert"),
                            ("health_check", "Health Check"),
                        ],
                        help_text="Type of notification this template is designed for",
                        max_length=30,
                    ),
                ),
                (
                    "subject_template",
                    models.CharField(
                        blank=True,
                        help_text="Subject line template (used for email notifications)",
                        max_length=200,
                    ),
                ),
                (
                    "message_template",
                    models.TextField(
                        help_text="Main message content template with variable placeholders"
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        db_index=True,
                        default=True,
                        help_text="Whether this template is active for use",
                    ),
                ),
                (
                    "variables",
                    models.JSONField(
                        default=list,
                        help_text="List of available variables for this template",
                    ),
                ),
                (
                    "channel_types",
                    models.JSONField(
                        default=list,
                        help_text="List of compatible notification channel types",
                    ),
                ),
            ],
            options={
                "verbose_name": "Notification Template",
                "verbose_name_plural": "Notification Templates",
                "ordering": ["template_type", "name"],
                "indexes": [
                    models.Index(
                        fields=["template_type"], name="notificatio_templat_5e0a58_idx"
                    ),
                    models.Index(
                        fields=["is_active"], name="notificatio_is_acti_b2a982_idx"
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="NotificationRule",
            fields=[
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when this record was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when this record was last modified",
                    ),
                ),
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier for this record",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Name for this notification rule",
                        max_length=100,
                        unique=True,
                    ),
                ),
                (
                    "event_type",
                    models.CharField(
                        choices=[
                            ("jingle_detected", "Jingle Detected"),
                            ("ad_break_started", "Ad Break Started"),
                            ("ad_break_ended", "Ad Break Ended"),
                            ("stream_started", "Stream Started"),
                            ("stream_stopped", "Stream Stopped"),
                            ("stream_error", "Stream Error"),
                            ("high_error_rate", "High Error Rate"),
                            ("system_startup", "System Startup"),
                            ("system_shutdown", "System Shutdown"),
                        ],
                        help_text="Type of event that triggers this notification rule",
                        max_length=30,
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        db_index=True,
                        default=True,
                        help_text="Whether this notification rule is active",
                    ),
                ),
                (
                    "conditions",
                    models.JSONField(
                        default=dict,
                        help_text="Additional conditions that must be met for triggering",
                    ),
                ),
                (
                    "throttle_minutes",
                    models.PositiveIntegerField(
                        default=5,
                        help_text="Minimum minutes between notifications from this rule",
                        validators=[
                            django.core.validators.MinValueValidator(0),
                            django.core.validators.MaxValueValidator(1440),
                        ],
                    ),
                ),
                (
                    "last_triggered",
                    models.DateTimeField(
                        blank=True,
                        help_text="When this rule was last triggered",
                        null=True,
                    ),
                ),
                (
                    "priority",
                    models.IntegerField(
                        default=0,
                        help_text="Rule priority for ordering (higher numbers = higher priority)",
                    ),
                ),
                (
                    "channel",
                    models.ForeignKey(
                        help_text="Default notification channel for this rule",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="rules",
                        to="notifications.notificationchannel",
                    ),
                ),
                (
                    "template",
                    models.ForeignKey(
                        help_text="Default notification template for this rule",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="rules",
                        to="notifications.notificationtemplate",
                    ),
                ),
            ],
            options={
                "verbose_name": "Notification Rule",
                "verbose_name_plural": "Notification Rules",
                "ordering": ["-priority", "name"],
            },
        ),
        migrations.CreateModel(
            name="Notification",
            fields=[
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when this record was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when this record was last modified",
                    ),
                ),
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier for this record",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("active", "Active"),
                            ("inactive", "Inactive"),
                            ("pending", "Pending"),
                            ("processing", "Processing"),
                            ("completed", "Completed"),
                            ("failed", "Failed"),
                            ("cancelled", "Cancelled"),
                        ],
                        db_index=True,
                        default="pending",
                        help_text="Current status of this record",
                        max_length=20,
                    ),
                ),
                (
                    "recipient",
                    models.CharField(
                        help_text="Target recipient identifier (email, chat ID, etc.)",
                        max_length=200,
                    ),
                ),
                (
                    "subject",
                    models.CharField(
                        blank=True,
                        help_text="Notification subject line",
                        max_length=200,
                    ),
                ),
                ("message", models.TextField(help_text="Notification message content")),
                (
                    "context_data",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Variables used for template rendering",
                    ),
                ),
                (
                    "scheduled_at",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        help_text="When this notification should be sent",
                    ),
                ),
                (
                    "sent_at",
                    models.DateTimeField(
                        blank=True,
                        help_text="When this notification was actually sent",
                        null=True,
                    ),
                ),
                (
                    "delivery_attempts",
                    models.PositiveIntegerField(
                        default=0, help_text="Number of delivery attempts made"
                    ),
                ),
                (
                    "error_message",
                    models.TextField(
                        blank=True, help_text="Last error message if delivery failed"
                    ),
                ),
                (
                    "external_id",
                    models.CharField(
                        blank=True,
                        help_text="External service message ID for tracking",
                        max_length=100,
                    ),
                ),
                (
                    "channel",
                    models.ForeignKey(
                        help_text="Notification channel to use for delivery",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="notifications",
                        to="notifications.notificationchannel",
                    ),
                ),
                (
                    "template",
                    models.ForeignKey(
                        blank=True,
                        help_text="Template used to generate this notification",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="notifications",
                        to="notifications.notificationtemplate",
                    ),
                ),
            ],
            options={
                "verbose_name": "Notification",
                "verbose_name_plural": "Notifications",
                "ordering": ["-scheduled_at"],
            },
        ),
        migrations.AddIndex(
            model_name="notificationchannel",
            index=models.Index(
                fields=["channel_type"], name="notificatio_channel_e00152_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="notificationchannel",
            index=models.Index(
                fields=["is_active"], name="notificatio_is_acti_06813e_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="notificationrule",
            index=models.Index(
                fields=["event_type"], name="notificatio_event_t_d00530_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="notificationrule",
            index=models.Index(
                fields=["is_active"], name="notificatio_is_acti_52a6a1_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="notificationrule",
            index=models.Index(
                fields=["priority"], name="notificatio_priorit_055737_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="notification",
            index=models.Index(
                fields=["channel", "status"], name="notificatio_channel_dff6f6_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="notification",
            index=models.Index(
                fields=["scheduled_at"], name="notificatio_schedul_21ac35_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="notification",
            index=models.Index(
                fields=["sent_at"], name="notificatio_sent_at_265656_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="notification",
            index=models.Index(fields=["status"], name="notificatio_status_d92267_idx"),
        ),
    ]
