# Generated by Django 4.2.7 on 2025-07-08 12:25

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('playlists', '0001_initial'),
        ('campaigns', '0001_initial'),
        ('channels', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='VastRequest',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('request_id', models.CharField(max_length=255, unique=True)),
                ('user_agent', models.TextField(blank=True, null=True)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('referrer', models.URLField(blank=True, null=True)),
                ('width', models.IntegerField(blank=True, null=True)),
                ('height', models.IntegerField(blank=True, null=True)),
                ('duration', models.IntegerField(blank=True, null=True)),
                ('response_status', models.CharField(default='pending', max_length=50)),
                ('response_time_ms', models.IntegerField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('channel', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='channels.channel')),
                ('playlist', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='playlists.playlist')),
                ('selected_adspot', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='campaigns.adspot')),
            ],
            options={
                'verbose_name': 'VAST Request',
                'verbose_name_plural': 'VAST Requests',
                'db_table': 'vast_requests',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='VastTemplate',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=255)),
                ('ad_type', models.CharField(choices=[('linear', 'Linear Video Ad'), ('nonlinear', 'Non-Linear Ad'), ('companion', 'Companion Ad')], max_length=20)),
                ('template_xml', models.TextField()),
                ('description', models.TextField(blank=True, null=True)),
                ('variables', models.JSONField(default=list, help_text='List of variables that can be replaced in template')),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'verbose_name': 'VAST Template',
                'verbose_name_plural': 'VAST Templates',
                'db_table': 'vast_templates',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='VastResponse',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('vast_xml', models.TextField()),
                ('impression_url', models.URLField(blank=True, null=True)),
                ('click_url', models.URLField(blank=True, null=True)),
                ('start_url', models.URLField(blank=True, null=True)),
                ('firstquartile_url', models.URLField(blank=True, null=True)),
                ('midpoint_url', models.URLField(blank=True, null=True)),
                ('thirdquartile_url', models.URLField(blank=True, null=True)),
                ('complete_url', models.URLField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('adspot', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='campaigns.adspot')),
                ('campaign', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='campaigns.campaign')),
                ('request', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='response', to='vast.vastrequest')),
            ],
            options={
                'verbose_name': 'VAST Response',
                'verbose_name_plural': 'VAST Responses',
                'db_table': 'vast_responses',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='AdDecisionEngine',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=255)),
                ('decision_type', models.CharField(choices=[('round_robin', 'Round Robin'), ('weighted', 'Weighted Random'), ('priority', 'Priority Based'), ('frequency_cap', 'Frequency Capping'), ('daypart', 'Daypart Targeting')], max_length=20)),
                ('configuration', models.JSONField(default=dict)),
                ('is_active', models.BooleanField(default=True)),
                ('priority', models.IntegerField(default=0)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('campaigns', models.ManyToManyField(blank=True, to='campaigns.campaign')),
                ('channels', models.ManyToManyField(blank=True, to='channels.channel')),
            ],
            options={
                'verbose_name': 'Ad Decision Engine',
                'verbose_name_plural': 'Ad Decision Engines',
                'db_table': 'ad_decision_engines',
                'ordering': ['-priority', 'name'],
            },
        ),
        migrations.CreateModel(
            name='VastTracking',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('event_type', models.CharField(choices=[('impression', 'Impression'), ('start', 'Start'), ('firstQuartile', 'First Quartile'), ('midpoint', 'Midpoint'), ('thirdQuartile', 'Third Quartile'), ('complete', 'Complete'), ('click', 'Click'), ('pause', 'Pause'), ('resume', 'Resume'), ('mute', 'Mute'), ('unmute', 'Unmute'), ('fullscreen', 'Fullscreen'), ('exitFullscreen', 'Exit Fullscreen'), ('error', 'Error')], max_length=20)),
                ('user_agent', models.TextField(blank=True, null=True)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('timestamp', models.DateTimeField(default=django.utils.timezone.now)),
                ('video_position', models.IntegerField(blank=True, null=True)),
                ('error_code', models.CharField(blank=True, max_length=10, null=True)),
                ('error_message', models.TextField(blank=True, null=True)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('request', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tracking_events', to='vast.vastrequest')),
            ],
            options={
                'verbose_name': 'VAST Tracking Event',
                'verbose_name_plural': 'VAST Tracking Events',
                'db_table': 'vast_tracking',
                'ordering': ['-timestamp'],
                'indexes': [models.Index(fields=['request', 'event_type'], name='vast_tracki_request_c44ee1_idx'), models.Index(fields=['timestamp'], name='vast_tracki_timesta_d5bbca_idx')],
            },
        ),
    ]
