# Generated by Django 4.2.13 on 2025-08-12 10:30

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('channels', '0001_initial'),
        ('campaigns', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='Playlists',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Timestamp when this object was created', verbose_name='Created At')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='Timestamp when this object was last modified', verbose_name='Updated At')),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='Unique identifier for this object', primary_key=True, serialize=False)),
                ('is_deleted', models.BooleanField(default=False, help_text='Whether this object has been soft-deleted', verbose_name='Is Deleted')),
                ('deleted_at', models.DateTimeField(blank=True, help_text='Timestamp when this object was soft-deleted', null=True, verbose_name='Deleted At')),
                ('version', models.IntegerField(default=1, help_text='Version identifier for playlist versioning', validators=[django.core.validators.MinValueValidator(0)])),
                ('broadcast_date', models.DateField(blank=True, db_index=True, help_text='Scheduled broadcast date', null=True)),
                ('start_date', models.DateTimeField(blank=True, help_text='Start datetime for playlist broadcast', null=True)),
                ('end_date', models.DateTimeField(blank=True, help_text='End datetime for playlist broadcast', null=True)),
                ('xml_file', models.FileField(blank=True, help_text='Generated XML schedule file for this playlist', null=True, upload_to=apps.playlists.utils.playlist_xml_upload_path)),
                ('is_draft', models.BooleanField(db_index=True, default=True, help_text='Draft status flag (True=draft, False=published)')),
                ('draft_version', models.IntegerField(help_text='Version number for draft management', validators=[django.core.validators.MinValueValidator(0)])),
                ('channel', models.ForeignKey(blank=True, db_column='channel', help_text='The channel this playlist belongs to', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='playlists', to='channels.channel')),
                ('created_by', models.ForeignKey(blank=True, help_text='User who created this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created', to=settings.AUTH_USER_MODEL, verbose_name='Created By')),
                ('deleted_by', models.ForeignKey(blank=True, help_text='User who soft-deleted this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_deleted', to=settings.AUTH_USER_MODEL, verbose_name='Deleted By')),
                ('updated_by', models.ForeignKey(blank=True, help_text='User who last modified this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated', to=settings.AUTH_USER_MODEL, verbose_name='Updated By')),
                ('zone_channel', models.ForeignKey(blank=True, db_column='zone_channel', help_text='Specific zone within the channel (optional)', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='playlists', to='channels.channelzone')),
            ],
            options={
                'verbose_name': 'Playlist',
                'verbose_name_plural': 'Playlists',
                'db_table': 'Playlists',
                'ordering': ['-created_at', '-id'],
            },
        ),
        migrations.CreateModel(
            name='Windows',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Timestamp when this object was created', verbose_name='Created At')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='Timestamp when this object was last modified', verbose_name='Updated At')),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='Unique identifier for this object', primary_key=True, serialize=False)),
                ('is_deleted', models.BooleanField(default=False, help_text='Whether this object has been soft-deleted', verbose_name='Is Deleted')),
                ('deleted_at', models.DateTimeField(blank=True, help_text='Timestamp when this object was soft-deleted', null=True, verbose_name='Deleted At')),
                ('window_start', models.TimeField(blank=True, db_index=True, help_text='Start time of the advertising window', null=True, verbose_name='Window Start')),
                ('window_end', models.TimeField(blank=True, help_text='End time of the advertising window', null=True, verbose_name='Window End')),
                ('window_duration', models.DurationField(blank=True, help_text='Duration of the advertising window', null=True, verbose_name='Window Duration')),
                ('created_by', models.ForeignKey(blank=True, help_text='User who created this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created', to=settings.AUTH_USER_MODEL, verbose_name='Created By')),
                ('deleted_by', models.ForeignKey(blank=True, help_text='User who soft-deleted this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_deleted', to=settings.AUTH_USER_MODEL, verbose_name='Deleted By')),
                ('playlist', models.ForeignKey(blank=True, db_column='playlist', help_text='The playlist this window belongs to', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='windows', to='playlists.playlists', verbose_name='Playlist')),
                ('updated_by', models.ForeignKey(blank=True, help_text='User who last modified this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated', to=settings.AUTH_USER_MODEL, verbose_name='Updated By')),
            ],
            options={
                'verbose_name': 'Advertising Window',
                'verbose_name_plural': 'Advertising Windows',
                'db_table': 'Windows',
                'ordering': ['window_start'],
            },
        ),
        migrations.CreateModel(
            name='Verifs',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Timestamp when this object was created', verbose_name='Created At')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='Timestamp when this object was last modified', verbose_name='Updated At')),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='Unique identifier for this object', primary_key=True, serialize=False)),
                ('is_deleted', models.BooleanField(default=False, help_text='Whether this object has been soft-deleted', verbose_name='Is Deleted')),
                ('deleted_at', models.DateTimeField(blank=True, help_text='Timestamp when this object was soft-deleted', null=True, verbose_name='Deleted At')),
                ('networkname', models.CharField(db_index=True, help_text='Name of the broadcasting network', max_length=255, verbose_name='Network Name')),
                ('zonename', models.CharField(db_index=True, help_text='Name of the broadcasting zone', max_length=255, verbose_name='Zone Name')),
                ('broadcast_date', models.DateField(db_index=True, help_text='Date when the advertisement was broadcast', verbose_name='Broadcast Date')),
                ('trafficId', models.IntegerField(db_index=True, help_text='Traffic system identifier for the advertisement', verbose_name='Traffic ID')),
                ('spotId', models.CharField(db_index=True, help_text='Unique identifier for the advertisement spot', max_length=255, verbose_name='Spot ID')),
                ('air_time', models.TimeField(db_index=True, help_text='Time when the advertisement was aired', verbose_name='Air Time')),
                ('air_length', models.DurationField(help_text='Duration of the aired advertisement', verbose_name='Air Length')),
                ('airStatuscode', models.CharField(db_index=True, help_text='Status code indicating broadcast result', max_length=255, verbose_name='Air Status Code')),
                ('revision', models.IntegerField(db_index=True, default=1, help_text='Revision number for the verification record', validators=[django.core.validators.MinValueValidator(1)], verbose_name='Revision')),
                ('vercomplete', models.CharField(blank=True, db_column='verComplete', db_index=True, help_text='Verification completion status', max_length=50, null=True, verbose_name='Verification Complete')),
                ('created_by', models.ForeignKey(blank=True, help_text='User who created this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created', to=settings.AUTH_USER_MODEL, verbose_name='Created By')),
                ('deleted_by', models.ForeignKey(blank=True, help_text='User who soft-deleted this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_deleted', to=settings.AUTH_USER_MODEL, verbose_name='Deleted By')),
                ('updated_by', models.ForeignKey(blank=True, help_text='User who last modified this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated', to=settings.AUTH_USER_MODEL, verbose_name='Updated By')),
            ],
            options={
                'verbose_name': 'Advertisement Verification',
                'verbose_name_plural': 'Advertisement Verifications',
                'db_table': 'Verifs',
                'ordering': ['-broadcast_date', '-air_time', '-revision'],
            },
        ),
        migrations.CreateModel(
            name='Avails',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Timestamp when this object was created', verbose_name='Created At')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='Timestamp when this object was last modified', verbose_name='Updated At')),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='Unique identifier for this object', primary_key=True, serialize=False)),
                ('is_deleted', models.BooleanField(default=False, help_text='Whether this object has been soft-deleted', verbose_name='Is Deleted')),
                ('deleted_at', models.DateTimeField(blank=True, help_text='Timestamp when this object was soft-deleted', null=True, verbose_name='Deleted At')),
                ('avail_start', models.TimeField(blank=True, db_index=True, help_text='Start time of the available advertising slot', null=True, verbose_name='Avail Start')),
                ('availinwindow', models.IntegerField(blank=True, db_column='availInWindow', help_text='Position or identifier of avail within the window', null=True, verbose_name='Avail in Window')),
                ('created_by', models.ForeignKey(blank=True, help_text='User who created this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created', to=settings.AUTH_USER_MODEL, verbose_name='Created By')),
                ('deleted_by', models.ForeignKey(blank=True, help_text='User who soft-deleted this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_deleted', to=settings.AUTH_USER_MODEL, verbose_name='Deleted By')),
                ('updated_by', models.ForeignKey(blank=True, help_text='User who last modified this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated', to=settings.AUTH_USER_MODEL, verbose_name='Updated By')),
                ('window', models.ForeignKey(blank=True, db_column='window', help_text='The advertising window this avail belongs to', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='avails', to='playlists.windows', verbose_name='Window')),
            ],
            options={
                'verbose_name': 'Available Slot',
                'verbose_name_plural': 'Available Slots',
                'db_table': 'Avails',
                'ordering': ['avail_start', 'availinwindow'],
            },
        ),
        migrations.CreateModel(
            name='AdspotsInAvail',
            fields=[
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Timestamp when this object was created', verbose_name='Created At')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='Timestamp when this object was last modified', verbose_name='Updated At')),
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='Unique identifier for this object', primary_key=True, serialize=False)),
                ('is_deleted', models.BooleanField(default=False, help_text='Whether this object has been soft-deleted', verbose_name='Is Deleted')),
                ('deleted_at', models.DateTimeField(blank=True, help_text='Timestamp when this object was soft-deleted', null=True, verbose_name='Deleted At')),
                ('positioninavail', models.IntegerField(blank=True, db_column='positionInAvail', db_index=True, help_text='Position of the ad spot within the avail (1-based)', null=True, validators=[django.core.validators.MinValueValidator(1)], verbose_name='Position in Avail')),
                ('trafficid', models.IntegerField(blank=True, db_column='trafficId', db_index=True, help_text='Traffic system identifier for the placement', null=True, verbose_name='Traffic ID')),
                ('adspot', models.ForeignKey(blank=True, db_column='adspot', help_text='The advertisement spot being placed', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='placements_in_avail', to='campaigns.adspots', verbose_name='Ad Spot')),
                ('avail', models.ForeignKey(blank=True, db_column='avail', help_text='The available slot where this ad spot is placed', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='adspots_in_avail', to='playlists.avails', verbose_name='Avail')),
                ('created_by', models.ForeignKey(blank=True, help_text='User who created this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created', to=settings.AUTH_USER_MODEL, verbose_name='Created By')),
                ('deleted_by', models.ForeignKey(blank=True, help_text='User who soft-deleted this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_deleted', to=settings.AUTH_USER_MODEL, verbose_name='Deleted By')),
                ('updated_by', models.ForeignKey(blank=True, help_text='User who last modified this object', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated', to=settings.AUTH_USER_MODEL, verbose_name='Updated By')),
            ],
            options={
                'verbose_name': 'Ad Spot Placement',
                'verbose_name_plural': 'Ad Spot Placements',
                'db_table': 'Adspots_in_avail',
                'ordering': ['positioninavail', 'id'],
            },
        ),
        migrations.AddIndex(
            model_name='windows',
            index=models.Index(fields=['playlist', 'window_start'], name='window_playlist_start_idx'),
        ),
        migrations.AddIndex(
            model_name='windows',
            index=models.Index(fields=['window_start'], name='window_start_idx'),
        ),
        migrations.AddConstraint(
            model_name='windows',
            constraint=models.CheckConstraint(check=models.Q(('window_start__lt', models.F('window_end')), ('window_start__isnull', True), ('window_end__isnull', True), _connector='OR'), name='window_valid_time_range'),
        ),
        migrations.AddIndex(
            model_name='verifs',
            index=models.Index(fields=['networkname', 'zonename'], name='verif_network_zone_idx'),
        ),
        migrations.AddIndex(
            model_name='verifs',
            index=models.Index(fields=['broadcast_date', 'air_time'], name='verif_broadcast_air_idx'),
        ),
        migrations.AddIndex(
            model_name='verifs',
            index=models.Index(fields=['trafficId', 'revision'], name='verif_traffic_revision_idx'),
        ),
        migrations.AddIndex(
            model_name='verifs',
            index=models.Index(fields=['spotId', 'broadcast_date'], name='verif_spot_date_idx'),
        ),
        migrations.AddIndex(
            model_name='verifs',
            index=models.Index(fields=['airStatuscode'], name='verif_status_idx'),
        ),
        migrations.AddIndex(
            model_name='verifs',
            index=models.Index(fields=['vercomplete'], name='verif_complete_idx'),
        ),
        migrations.AddConstraint(
            model_name='verifs',
            constraint=models.UniqueConstraint(fields=('trafficId', 'spotId', 'revision'), name='unique_verif_per_traffic_spot_revision'),
        ),
        migrations.AddIndex(
            model_name='playlists',
            index=models.Index(fields=['channel', 'broadcast_date'], name='playlist_channel_date_idx'),
        ),
        migrations.AddIndex(
            model_name='playlists',
            index=models.Index(fields=['start_date', 'end_date'], name='playlist_datetime_range_idx'),
        ),
        migrations.AddIndex(
            model_name='playlists',
            index=models.Index(fields=['is_draft', 'created_at'], name='playlist_draft_created_idx'),
        ),
        migrations.AddIndex(
            model_name='playlists',
            index=models.Index(fields=['version'], name='playlist_version_idx'),
        ),
        migrations.AddIndex(
            model_name='playlists',
            index=models.Index(fields=['zone_channel'], name='playlist_zone_idx'),
        ),
        migrations.AddConstraint(
            model_name='playlists',
            constraint=models.UniqueConstraint(fields=('channel', 'broadcast_date', 'version'), name='unique_playlist_version_per_channel_date'),
        ),
        migrations.AddConstraint(
            model_name='playlists',
            constraint=models.CheckConstraint(check=models.Q(('start_date__lt', models.F('end_date')), ('start_date__isnull', True), ('end_date__isnull', True), _connector='OR'), name='playlist_valid_date_range'),
        ),
        migrations.AddIndex(
            model_name='avails',
            index=models.Index(fields=['window', 'avail_start'], name='avail_window_start_idx'),
        ),
        migrations.AddIndex(
            model_name='avails',
            index=models.Index(fields=['availinwindow'], name='avail_position_idx'),
        ),
        migrations.AddIndex(
            model_name='adspotsinavail',
            index=models.Index(fields=['avail', 'positioninavail'], name='adspot_avail_position_idx'),
        ),
        migrations.AddIndex(
            model_name='adspotsinavail',
            index=models.Index(fields=['adspot'], name='adspot_spot_idx'),
        ),
        migrations.AddIndex(
            model_name='adspotsinavail',
            index=models.Index(fields=['trafficid'], name='adspot_traffic_idx'),
        ),
        migrations.AddConstraint(
            model_name='adspotsinavail',
            constraint=models.UniqueConstraint(condition=models.Q(('positioninavail__isnull', False)), fields=('avail', 'positioninavail'), name='unique_adspot_position_per_avail'),
        ),
    ]
