# 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 = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="AudioConfiguration",
            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 audio configuration",
                        max_length=50,
                        unique=True,
                    ),
                ),
                (
                    "codec",
                    models.CharField(
                        choices=[("aac", "AAC"), ("mp3", "MP3"), ("opus", "Opus")],
                        default="aac",
                        help_text="Audio codec to use for encoding",
                        max_length=20,
                    ),
                ),
                (
                    "bitrate",
                    models.CharField(
                        default="128k",
                        help_text="Audio bitrate (e.g., '128k', '256k')",
                        max_length=20,
                    ),
                ),
                (
                    "sample_rate",
                    models.PositiveIntegerField(
                        choices=[
                            (8000, "8 kHz"),
                            (16000, "16 kHz"),
                            (22050, "22.05 kHz"),
                            (44100, "44.1 kHz"),
                            (48000, "48 kHz"),
                            (96000, "96 kHz"),
                        ],
                        default=48000,
                        help_text="Audio sample rate in Hz",
                    ),
                ),
                (
                    "channels",
                    models.PositiveIntegerField(
                        choices=[(1, "Mono"), (2, "Stereo"), (6, "5.1 Surround")],
                        default=2,
                        help_text="Number of audio channels",
                    ),
                ),
                (
                    "normalize",
                    models.BooleanField(
                        default=True,
                        help_text="Apply audio normalization (loudnorm filter)",
                    ),
                ),
            ],
            options={
                "verbose_name": "Audio Configuration",
                "verbose_name_plural": "Audio Configurations",
                "ordering": ["name"],
            },
        ),
        migrations.CreateModel(
            name="VideoConfiguration",
            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 video configuration",
                        max_length=50,
                        unique=True,
                    ),
                ),
                (
                    "resolution",
                    models.CharField(
                        default="1280x720",
                        help_text="Video resolution (width x height)",
                        max_length=20,
                    ),
                ),
                (
                    "aspect_ratio",
                    models.CharField(
                        default="16:9", help_text="Video aspect ratio", max_length=10
                    ),
                ),
                (
                    "frame_rate",
                    models.PositiveIntegerField(
                        default=25,
                        help_text="Video frame rate in frames per second",
                        validators=[
                            django.core.validators.MinValueValidator(1),
                            django.core.validators.MaxValueValidator(120),
                        ],
                    ),
                ),
                (
                    "min_bitrate",
                    models.CharField(
                        default="2000k",
                        help_text="Minimum video bitrate (e.g., '2000k')",
                        max_length=20,
                    ),
                ),
                (
                    "max_bitrate",
                    models.CharField(
                        default="4000k",
                        help_text="Maximum video bitrate (e.g., '4000k')",
                        max_length=20,
                    ),
                ),
                (
                    "codec",
                    models.CharField(
                        choices=[("h264", "H.264"), ("h265", "H.265"), ("vp9", "VP9")],
                        default="h264",
                        help_text="Video codec to use for encoding",
                        max_length=20,
                    ),
                ),
                (
                    "preset",
                    models.CharField(
                        choices=[
                            ("ultrafast", "Ultra Fast"),
                            ("superfast", "Super Fast"),
                            ("veryfast", "Very Fast"),
                            ("faster", "Faster"),
                            ("fast", "Fast"),
                            ("medium", "Medium"),
                            ("slow", "Slow"),
                            ("slower", "Slower"),
                            ("veryslow", "Very Slow"),
                        ],
                        default="medium",
                        help_text="Encoding preset for speed/quality trade-off",
                        max_length=20,
                    ),
                ),
                (
                    "profile",
                    models.CharField(
                        choices=[
                            ("baseline", "Baseline"),
                            ("main", "Main"),
                            ("high", "High"),
                        ],
                        default="main",
                        help_text="Video profile setting",
                        max_length=20,
                    ),
                ),
                (
                    "level",
                    models.CharField(
                        default="3.1",
                        help_text="Video level setting (e.g., '3.1', '4.0')",
                        max_length=10,
                    ),
                ),
            ],
            options={
                "verbose_name": "Video Configuration",
                "verbose_name_plural": "Video Configurations",
                "ordering": ["name"],
            },
        ),
        migrations.CreateModel(
            name="Channel",
            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 channel",
                        max_length=100,
                        unique=True,
                    ),
                ),
                (
                    "slug",
                    models.SlugField(
                        help_text="URL-friendly identifier for the channel",
                        max_length=100,
                        unique=True,
                    ),
                ),
                (
                    "hls_url",
                    models.URLField(
                        help_text="Source HLS stream URL to capture", max_length=500
                    ),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        help_text="Optional description of the channel content",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        db_index=True,
                        default=True,
                        help_text="Whether this channel is currently active",
                    ),
                ),
                (
                    "output_directory",
                    models.CharField(
                        help_text="Directory path for stream output files",
                        max_length=200,
                    ),
                ),
                (
                    "segment_duration",
                    models.PositiveIntegerField(
                        default=6,
                        help_text="Duration of each HLS segment in seconds",
                        validators=[
                            django.core.validators.MinValueValidator(1),
                            django.core.validators.MaxValueValidator(60),
                        ],
                    ),
                ),
                (
                    "max_segments",
                    models.PositiveIntegerField(
                        default=10,
                        help_text="Maximum number of segments to keep in playlist",
                        validators=[
                            django.core.validators.MinValueValidator(1),
                            django.core.validators.MaxValueValidator(100),
                        ],
                    ),
                ),
                (
                    "retry_attempts",
                    models.PositiveIntegerField(
                        default=5,
                        help_text="Number of retry attempts on capture failure",
                        validators=[
                            django.core.validators.MinValueValidator(1),
                            django.core.validators.MaxValueValidator(20),
                        ],
                    ),
                ),
                (
                    "retry_interval",
                    models.PositiveIntegerField(
                        default=10,
                        help_text="Seconds to wait between retry attempts",
                        validators=[
                            django.core.validators.MinValueValidator(1),
                            django.core.validators.MaxValueValidator(300),
                        ],
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        help_text="User who created this channel",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="channels",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Channel",
                "verbose_name_plural": "Channels",
                "ordering": ["name"],
            },
        ),
        migrations.CreateModel(
            name="StreamSession",
            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,
                    ),
                ),
                (
                    "started_at",
                    models.DateTimeField(
                        blank=True,
                        help_text="When the stream capture started",
                        null=True,
                    ),
                ),
                (
                    "ended_at",
                    models.DateTimeField(
                        blank=True, help_text="When the stream capture ended", null=True
                    ),
                ),
                (
                    "segments_processed",
                    models.PositiveIntegerField(
                        default=0, help_text="Number of segments successfully processed"
                    ),
                ),
                (
                    "errors_count",
                    models.PositiveIntegerField(
                        default=0,
                        help_text="Number of errors encountered during processing",
                    ),
                ),
                (
                    "last_error",
                    models.TextField(
                        blank=True, help_text="Last error message encountered"
                    ),
                ),
                (
                    "process_id",
                    models.CharField(
                        blank=True,
                        help_text="System process ID for monitoring",
                        max_length=50,
                    ),
                ),
                (
                    "statistics",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Additional statistics and metadata",
                    ),
                ),
                (
                    "audio_config",
                    models.ForeignKey(
                        blank=True,
                        help_text="Audio configuration used for this session",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="streams.audioconfiguration",
                    ),
                ),
                (
                    "channel",
                    models.ForeignKey(
                        help_text="Channel this session belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="sessions",
                        to="streams.channel",
                    ),
                ),
                (
                    "video_config",
                    models.ForeignKey(
                        blank=True,
                        help_text="Video configuration used for this session",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="streams.videoconfiguration",
                    ),
                ),
            ],
            options={
                "verbose_name": "Stream Session",
                "verbose_name_plural": "Stream Sessions",
                "ordering": ["-started_at"],
            },
        ),
        migrations.CreateModel(
            name="HLSSegment",
            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,
                    ),
                ),
                (
                    "filename",
                    models.CharField(
                        help_text="Name of the segment file", max_length=200
                    ),
                ),
                (
                    "file_path",
                    models.CharField(
                        help_text="Full path to the segment file", max_length=500
                    ),
                ),
                (
                    "sequence_number",
                    models.PositiveIntegerField(
                        help_text="Sequence number in the HLS playlist"
                    ),
                ),
                (
                    "duration",
                    models.FloatField(
                        help_text="Duration of the segment in seconds",
                        validators=[
                            django.core.validators.MinValueValidator(0.1),
                            django.core.validators.MaxValueValidator(60.0),
                        ],
                    ),
                ),
                (
                    "file_size",
                    models.PositiveBigIntegerField(
                        blank=True,
                        help_text="Size of the segment file in bytes",
                        null=True,
                    ),
                ),
                (
                    "processed_at",
                    models.DateTimeField(
                        auto_now_add=True, help_text="When the segment was processed"
                    ),
                ),
                (
                    "is_available",
                    models.BooleanField(
                        db_index=True,
                        default=True,
                        help_text="Whether the segment file is currently available",
                    ),
                ),
                (
                    "session",
                    models.ForeignKey(
                        help_text="Stream session this segment belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="segments",
                        to="streams.streamsession",
                    ),
                ),
            ],
            options={
                "verbose_name": "HLS Segment",
                "verbose_name_plural": "HLS Segments",
                "ordering": ["session", "sequence_number"],
            },
        ),
        migrations.AddIndex(
            model_name="channel",
            index=models.Index(fields=["slug"], name="streams_cha_slug_acfc87_idx"),
        ),
        migrations.AddIndex(
            model_name="channel",
            index=models.Index(
                fields=["is_active"], name="streams_cha_is_acti_d5e6f4_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="channel",
            index=models.Index(
                fields=["created_at"], name="streams_cha_created_2d0498_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="hlssegment",
            index=models.Index(
                fields=["session", "sequence_number"],
                name="streams_hls_session_88fff8_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="hlssegment",
            index=models.Index(
                fields=["processed_at"], name="streams_hls_process_c66196_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="hlssegment",
            index=models.Index(
                fields=["is_available"], name="streams_hls_is_avai_48584a_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="hlssegment",
            unique_together={("session", "sequence_number")},
        ),
        migrations.AddIndex(
            model_name="streamsession",
            index=models.Index(
                fields=["channel", "status"], name="streams_str_channel_daa7a9_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="streamsession",
            index=models.Index(
                fields=["started_at"], name="streams_str_started_1fdea0_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="streamsession",
            index=models.Index(fields=["status"], name="streams_str_status_b56c2c_idx"),
        ),
    ]
