# Generated by Django 5.2.4 on 2025-08-28 18:16

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('dispatcharr_channels', '0024_alter_channelgroupm3uaccount_channel_group'),
        ('m3u', '0016_m3uaccount_priority'),
    ]

    operations = [
        migrations.CreateModel(
            name='Movie',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('name', models.CharField(max_length=255)),
                ('description', models.TextField(blank=True, null=True)),
                ('year', models.IntegerField(blank=True, null=True)),
                ('rating', models.CharField(blank=True, max_length=10, null=True)),
                ('genre', models.CharField(blank=True, max_length=255, null=True)),
                ('duration_secs', models.IntegerField(blank=True, help_text='Duration in seconds', null=True)),
                ('tmdb_id', models.CharField(blank=True, help_text='TMDB ID for metadata', max_length=50, null=True, unique=True)),
                ('imdb_id', models.CharField(blank=True, help_text='IMDB ID for metadata', max_length=50, null=True, unique=True)),
                ('custom_properties', models.JSONField(blank=True, help_text='Additional metadata and properties for the movie', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('logo', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='movie', to='dispatcharr_channels.logo')),
            ],
            options={
                'verbose_name': 'Movie',
                'verbose_name_plural': 'Movies',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Series',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('name', models.CharField(max_length=255)),
                ('description', models.TextField(blank=True, null=True)),
                ('year', models.IntegerField(blank=True, null=True)),
                ('rating', models.CharField(blank=True, max_length=10, null=True)),
                ('genre', models.CharField(blank=True, max_length=255, null=True)),
                ('tmdb_id', models.CharField(blank=True, help_text='TMDB ID for metadata', max_length=50, null=True, unique=True)),
                ('imdb_id', models.CharField(blank=True, help_text='IMDB ID for metadata', max_length=50, null=True, unique=True)),
                ('custom_properties', models.JSONField(blank=True, help_text='Additional metadata and properties for the series', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('logo', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='series', to='dispatcharr_channels.logo')),
            ],
            options={
                'verbose_name': 'Series',
                'verbose_name_plural': 'Series',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Episode',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('name', models.CharField(max_length=255)),
                ('description', models.TextField(blank=True, null=True)),
                ('air_date', models.DateField(blank=True, null=True)),
                ('rating', models.CharField(blank=True, max_length=10, null=True)),
                ('duration_secs', models.IntegerField(blank=True, help_text='Duration in seconds', null=True)),
                ('season_number', models.IntegerField(blank=True, null=True)),
                ('episode_number', models.IntegerField(blank=True, null=True)),
                ('tmdb_id', models.CharField(blank=True, db_index=True, help_text='TMDB ID for metadata', max_length=50, null=True)),
                ('imdb_id', models.CharField(blank=True, db_index=True, help_text='IMDB ID for metadata', max_length=50, null=True)),
                ('custom_properties', models.JSONField(blank=True, help_text='Custom properties for this episode', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('series', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='episodes', to='vod.series')),
            ],
            options={
                'verbose_name': 'Episode',
                'verbose_name_plural': 'Episodes',
                'ordering': ['series__name', 'season_number', 'episode_number'],
            },
        ),
        migrations.CreateModel(
            name='VODCategory',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=255)),
                ('category_type', models.CharField(choices=[('movie', 'Movie'), ('series', 'Series')], default='movie', help_text='Type of content this category contains', max_length=10)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': 'VOD Category',
                'verbose_name_plural': 'VOD Categories',
                'ordering': ['name'],
                'unique_together': {('name', 'category_type')},
            },
        ),
        migrations.CreateModel(
            name='M3UVODCategoryRelation',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('enabled', models.BooleanField(default=False, help_text='Set to false to deactivate this category for the M3U account')),
                ('custom_properties', models.JSONField(blank=True, help_text='Provider-specific data like quality, language, etc.', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('m3u_account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='category_relations', to='m3u.m3uaccount')),
                ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='m3u_relations', to='vod.vodcategory')),
            ],
            options={
                'verbose_name': 'M3U VOD Category Relation',
                'verbose_name_plural': 'M3U VOD Category Relations',
            },
        ),
        migrations.CreateModel(
            name='M3USeriesRelation',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('external_series_id', models.CharField(help_text='External series ID from M3U provider', max_length=255)),
                ('custom_properties', models.JSONField(blank=True, help_text='Provider-specific data', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('last_episode_refresh', models.DateTimeField(blank=True, help_text='Last time episodes were refreshed', null=True)),
                ('m3u_account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='series_relations', to='m3u.m3uaccount')),
                ('series', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='m3u_relations', to='vod.series')),
                ('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='vod.vodcategory')),
            ],
            options={
                'verbose_name': 'M3U Series Relation',
                'verbose_name_plural': 'M3U Series Relations',
            },
        ),
        migrations.CreateModel(
            name='M3UMovieRelation',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('stream_id', models.CharField(help_text='External stream ID from M3U provider', max_length=255)),
                ('container_extension', models.CharField(blank=True, max_length=10, null=True)),
                ('custom_properties', models.JSONField(blank=True, help_text='Provider-specific data like quality, language, etc.', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('last_advanced_refresh', models.DateTimeField(blank=True, help_text='Last time advanced data was fetched from provider', null=True)),
                ('m3u_account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='movie_relations', to='m3u.m3uaccount')),
                ('movie', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='m3u_relations', to='vod.movie')),
                ('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='vod.vodcategory')),
            ],
            options={
                'verbose_name': 'M3U Movie Relation',
                'verbose_name_plural': 'M3U Movie Relations',
            },
        ),
        migrations.CreateModel(
            name='M3UEpisodeRelation',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('stream_id', models.CharField(help_text='External stream ID from M3U provider', max_length=255)),
                ('container_extension', models.CharField(blank=True, max_length=10, null=True)),
                ('custom_properties', models.JSONField(blank=True, help_text='Provider-specific data like quality, language, etc.', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('episode', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='m3u_relations', to='vod.episode')),
                ('m3u_account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='episode_relations', to='m3u.m3uaccount')),
            ],
            options={
                'verbose_name': 'M3U Episode Relation',
                'verbose_name_plural': 'M3U Episode Relations',
                'unique_together': {('m3u_account', 'stream_id')},
            },
        ),
        migrations.AddConstraint(
            model_name='movie',
            constraint=models.UniqueConstraint(condition=models.Q(('tmdb_id__isnull', True), ('imdb_id__isnull', True)), fields=('name', 'year'), name='unique_movie_name_year_no_external_id'),
        ),
        migrations.AddConstraint(
            model_name='series',
            constraint=models.UniqueConstraint(condition=models.Q(('tmdb_id__isnull', True), ('imdb_id__isnull', True)), fields=('name', 'year'), name='unique_series_name_year_no_external_id'),
        ),
        migrations.AlterUniqueTogether(
            name='episode',
            unique_together={('series', 'season_number', 'episode_number')},
        ),
        migrations.AlterUniqueTogether(
            name='m3uvodcategoryrelation',
            unique_together={('m3u_account', 'category')},
        ),
        migrations.AlterUniqueTogether(
            name='m3useriesrelation',
            unique_together={('m3u_account', 'external_series_id')},
        ),
        migrations.AlterUniqueTogether(
            name='m3umovierelation',
            unique_together={('m3u_account', 'stream_id')},
        ),
    ]
