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

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


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name="JingleTemplate",
            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 jingle",
                        max_length=100,
                        unique=True,
                    ),
                ),
                (
                    "slug",
                    models.SlugField(
                        help_text="URL-friendly identifier for the jingle",
                        max_length=100,
                        unique=True,
                    ),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        help_text="Description of the jingle content and context",
                    ),
                ),
                (
                    "image_path",
                    models.CharField(
                        help_text="Path to the reference image file for this jingle",
                        max_length=500,
                    ),
                ),
                (
                    "similarity_threshold",
                    models.FloatField(
                        default=0.1,
                        help_text="Similarity threshold for positive detection (0.0-1.0)",
                        validators=[
                            django.core.validators.MinValueValidator(0.0),
                            django.core.validators.MaxValueValidator(1.0),
                        ],
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        db_index=True,
                        default=True,
                        help_text="Whether this jingle template is active for detection",
                    ),
                ),
                (
                    "category",
                    models.CharField(
                        choices=[
                            ("ad_start", "Advertisement Start"),
                            ("ad_end", "Advertisement End"),
                            ("program_start", "Program Start"),
                            ("program_end", "Program End"),
                            ("transition", "Transition"),
                            ("branding", "Channel Branding"),
                            ("other", "Other"),
                        ],
                        default="other",
                        help_text="Category classification for this jingle",
                        max_length=50,
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        help_text="User who uploaded this jingle template",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="jingle_templates",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Jingle Template",
                "verbose_name_plural": "Jingle Templates",
                "ordering": ["category", "name"],
            },
        ),
        migrations.CreateModel(
            name="JingleDetection",
            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,
                    ),
                ),
                (
                    "confidence_score",
                    models.FloatField(
                        help_text="Confidence level of the detection (0.0-1.0)",
                        validators=[
                            django.core.validators.MinValueValidator(0.0),
                            django.core.validators.MaxValueValidator(1.0),
                        ],
                    ),
                ),
                (
                    "frame_path",
                    models.CharField(
                        help_text="Path to the extracted frame image", max_length=500
                    ),
                ),
                (
                    "detection_time",
                    models.DateTimeField(
                        auto_now_add=True, help_text="When the detection was processed"
                    ),
                ),
                (
                    "frame_timestamp",
                    models.FloatField(
                        help_text="Timestamp within the segment where detection occurred",
                        validators=[django.core.validators.MinValueValidator(0.0)],
                    ),
                ),
                (
                    "is_confirmed",
                    models.BooleanField(
                        db_index=True,
                        default=False,
                        help_text="Whether this detection has been manually confirmed",
                    ),
                ),
                (
                    "metadata",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Additional detection metadata and analysis results",
                    ),
                ),
                (
                    "segment",
                    models.ForeignKey(
                        help_text="HLS segment containing this detection",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="jingle_detections",
                        to="streams.hlssegment",
                    ),
                ),
                (
                    "session",
                    models.ForeignKey(
                        help_text="Stream session where this detection occurred",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="jingle_detections",
                        to="streams.streamsession",
                    ),
                ),
                (
                    "template",
                    models.ForeignKey(
                        help_text="Jingle template that was matched",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="detections",
                        to="jingles.jingletemplate",
                    ),
                ),
            ],
            options={
                "verbose_name": "Jingle Detection",
                "verbose_name_plural": "Jingle Detections",
                "ordering": ["-detection_time"],
            },
        ),
        migrations.CreateModel(
            name="DetectionStatistics",
            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,
                    ),
                ),
                (
                    "total_detections",
                    models.PositiveIntegerField(
                        default=0,
                        help_text="Total number of detections for this template",
                    ),
                ),
                (
                    "confirmed_detections",
                    models.PositiveIntegerField(
                        default=0, help_text="Number of manually confirmed detections"
                    ),
                ),
                (
                    "false_positives",
                    models.PositiveIntegerField(
                        default=0,
                        help_text="Number of identified false positive detections",
                    ),
                ),
                (
                    "avg_confidence",
                    models.FloatField(
                        blank=True,
                        help_text="Average confidence score for all detections",
                        null=True,
                        validators=[
                            django.core.validators.MinValueValidator(0.0),
                            django.core.validators.MaxValueValidator(1.0),
                        ],
                    ),
                ),
                (
                    "min_confidence",
                    models.FloatField(
                        blank=True,
                        help_text="Minimum confidence score recorded",
                        null=True,
                        validators=[
                            django.core.validators.MinValueValidator(0.0),
                            django.core.validators.MaxValueValidator(1.0),
                        ],
                    ),
                ),
                (
                    "max_confidence",
                    models.FloatField(
                        blank=True,
                        help_text="Maximum confidence score recorded",
                        null=True,
                        validators=[
                            django.core.validators.MinValueValidator(0.0),
                            django.core.validators.MaxValueValidator(1.0),
                        ],
                    ),
                ),
                (
                    "detection_rate",
                    models.FloatField(
                        blank=True,
                        help_text="Number of detections per hour",
                        null=True,
                        validators=[django.core.validators.MinValueValidator(0.0)],
                    ),
                ),
                (
                    "last_detection",
                    models.DateTimeField(
                        blank=True,
                        help_text="Timestamp of the most recent detection",
                        null=True,
                    ),
                ),
                (
                    "session",
                    models.ForeignKey(
                        help_text="Stream session for these statistics",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="detection_statistics",
                        to="streams.streamsession",
                    ),
                ),
                (
                    "template",
                    models.ForeignKey(
                        help_text="Jingle template for these statistics",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="statistics",
                        to="jingles.jingletemplate",
                    ),
                ),
            ],
            options={
                "verbose_name": "Detection Statistics",
                "verbose_name_plural": "Detection Statistics",
                "ordering": ["-last_detection"],
            },
        ),
        migrations.CreateModel(
            name="AdBreak",
            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,
                    ),
                ),
                (
                    "channel_name",
                    models.CharField(
                        help_text="Channel identifier for external API integration",
                        max_length=100,
                    ),
                ),
                (
                    "region",
                    models.CharField(
                        choices=[
                            ("Netherlands", "Netherlands"),
                            ("France", "France"),
                            ("Global", "Global"),
                        ],
                        default="Global",
                        help_text="Geographic region for this ad break",
                        max_length=50,
                    ),
                ),
                (
                    "start_time",
                    models.DateTimeField(
                        help_text="When the advertisement break started"
                    ),
                ),
                (
                    "end_time",
                    models.DateTimeField(
                        blank=True,
                        help_text="When the advertisement break ended",
                        null=True,
                    ),
                ),
                (
                    "duration_seconds",
                    models.PositiveIntegerField(
                        blank=True,
                        help_text="Duration of the ad break in seconds",
                        null=True,
                        validators=[
                            django.core.validators.MinValueValidator(1),
                            django.core.validators.MaxValueValidator(3600),
                        ],
                    ),
                ),
                (
                    "is_sent_to_api",
                    models.BooleanField(
                        db_index=True,
                        default=False,
                        help_text="Whether this ad break data was sent to external API",
                    ),
                ),
                (
                    "api_response",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Response data from external API calls",
                    ),
                ),
                (
                    "notes",
                    models.TextField(
                        blank=True,
                        help_text="Additional notes or observations about this ad break",
                    ),
                ),
                (
                    "session",
                    models.ForeignKey(
                        help_text="Stream session containing this ad break",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="ad_breaks",
                        to="streams.streamsession",
                    ),
                ),
                (
                    "end_detection",
                    models.ForeignKey(
                        blank=True,
                        help_text="Jingle detection that marked the end of this ad break",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="ad_breaks_ended",
                        to="jingles.jingledetection",
                    ),
                ),
                (
                    "start_detection",
                    models.ForeignKey(
                        blank=True,
                        help_text="Jingle detection that marked the start of this ad break",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="ad_breaks_started",
                        to="jingles.jingledetection",
                    ),
                ),
            ],
            options={
                "verbose_name": "Advertisement Break",
                "verbose_name_plural": "Advertisement Breaks",
                "ordering": ["-start_time"],
                "indexes": [
                    models.Index(
                        fields=["session", "start_time"],
                        name="jingles_adb_session_644a34_idx",
                    ),
                    models.Index(
                        fields=["channel_name", "region"],
                        name="jingles_adb_channel_a8cb4d_idx",
                    ),
                    models.Index(
                        fields=["is_sent_to_api"], name="jingles_adb_is_sent_b14f94_idx"
                    ),
                    models.Index(
                        fields=["status"], name="jingles_adb_status_be1ce1_idx"
                    ),
                ],
            },
        ),
        migrations.AddIndex(
            model_name="jingletemplate",
            index=models.Index(fields=["slug"], name="jingles_jin_slug_33d2ec_idx"),
        ),
        migrations.AddIndex(
            model_name="jingletemplate",
            index=models.Index(
                fields=["is_active"], name="jingles_jin_is_acti_568562_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="jingletemplate",
            index=models.Index(
                fields=["category"], name="jingles_jin_categor_7a9b01_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="jingledetection",
            index=models.Index(
                fields=["session", "detection_time"],
                name="jingles_jin_session_16f260_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="jingledetection",
            index=models.Index(
                fields=["template", "detection_time"],
                name="jingles_jin_templat_1cb2b1_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="jingledetection",
            index=models.Index(
                fields=["is_confirmed"], name="jingles_jin_is_conf_d97304_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="jingledetection",
            index=models.Index(
                fields=["confidence_score"], name="jingles_jin_confide_a60b7d_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="detectionstatistics",
            index=models.Index(
                fields=["session", "template"], name="jingles_det_session_8fd830_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="detectionstatistics",
            index=models.Index(
                fields=["last_detection"], name="jingles_det_last_de_1414d7_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="detectionstatistics",
            unique_together={("session", "template")},
        ),
    ]
