# Generated by Django 6.0.4 on 2026-05-08 13:51

from django.db import migrations, models


def create_default_output_profiles(apps, schema_editor):
    OutputProfile = apps.get_model('core', 'OutputProfile')
    OutputProfile.objects.get_or_create(
        name='Media Server (AC3 Audio)',
        defaults={
            'command': 'ffmpeg',
            'parameters': (
                '-fflags +discardcorrupt+genpts+nobuffer '
                '-i pipe:0 '
                '-map 0 '
                '-c:v copy '
                '-c:a ac3 '
                '-b:a 384k '
                '-max_muxing_queue_size 4096 '
                '-mpegts_flags +pat_pmt_at_frames+resend_headers+initial_discontinuity '
                '-f mpegts pipe:1'
            ),
            'locked': True,
            'is_active': True,
        },
    )
    OutputProfile.objects.get_or_create(
        name='Web Player (AAC Audio)',
        defaults={
            'command': 'ffmpeg',
            'parameters': (
                '-fflags +discardcorrupt+genpts+nobuffer '
                '-i pipe:0 '
                '-map 0 '
                '-c:v copy '
                '-c:a aac '
                '-b:a 192k '
                '-max_muxing_queue_size 4096 '
                '-mpegts_flags +pat_pmt_at_frames+resend_headers+initial_discontinuity '
                '-f mpegts pipe:1'
            ),
            'locked': True,
            'is_active': True,
        },
    )


def remove_default_output_profiles(apps, schema_editor):
    OutputProfile = apps.get_model('core', 'OutputProfile')
    OutputProfile.objects.filter(
        name__in=['Media Server (AC3 Audio)', 'Web Player (AAC Audio)'],
        locked=True,
    ).delete()


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0023_alter_systemevent_event_type'),
    ]

    operations = [
        migrations.CreateModel(
            name='OutputProfile',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(help_text='Display name for this output profile', max_length=255, unique=True)),
                ('command', models.CharField(help_text="Executable to run (e.g. 'ffmpeg')", max_length=255)),
                ('parameters', models.TextField(help_text='Command-line parameters. Must read from pipe:0 (stdin) and write to pipe:1 (stdout).')),
                ('locked', models.BooleanField(default=False, help_text="Protected - can't be deleted or modified")),
                ('is_active', models.BooleanField(default=True, help_text='Whether this profile is available for use')),
            ],
        ),
        migrations.RunPython(
            create_default_output_profiles,
            remove_default_output_profiles,
        ),
    ]
