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

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name='Agency',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('name', models.CharField(max_length=255)),
                ('contact_person', models.CharField(blank=True, max_length=255)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('phone', models.CharField(blank=True, max_length=20)),
                ('address', models.TextField(blank=True)),
                ('is_active', models.BooleanField(default=True)),
            ],
            options={
                'verbose_name_plural': 'Agencies',
                'db_table': 'agencies',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Brand',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('name', models.CharField(max_length=255)),
                ('description', models.TextField(blank=True)),
                ('logo', models.ImageField(blank=True, null=True, upload_to='brands/')),
                ('website', models.URLField(blank=True)),
                ('is_active', models.BooleanField(default=True)),
            ],
            options={
                'db_table': 'brands',
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='Campaign',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('name', models.CharField(max_length=255)),
                ('description', models.TextField(blank=True)),
                ('campaign_type', models.CharField(choices=[('standard', 'Standard'), ('premium', 'Premium'), ('sponsored', 'Sponsored')], default='standard', max_length=20)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('pending', 'Pending Approval'), ('approved', 'Approved'), ('active', 'Active'), ('paused', 'Paused'), ('completed', 'Completed'), ('cancelled', 'Cancelled')], default='draft', max_length=20)),
                ('start_date', models.DateTimeField()),
                ('end_date', models.DateTimeField()),
                ('budget', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True)),
                ('target_impressions', models.PositiveIntegerField(blank=True, null=True)),
                ('approved_at', models.DateTimeField(blank=True, null=True)),
                ('agency', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='campaigns', to='campaigns.agency')),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='approved_campaigns', to=settings.AUTH_USER_MODEL)),
                ('brand', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='campaigns', to='campaigns.brand')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_campaigns', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'campaigns',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='Creative',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('name', models.CharField(max_length=255)),
                ('creative_type', models.CharField(choices=[('video', 'Video'), ('audio', 'Audio'), ('image', 'Image'), ('text', 'Text')], max_length=20)),
                ('file', models.FileField(upload_to='creatives/')),
                ('duration', models.PositiveIntegerField(blank=True, help_text='Duration in seconds', null=True)),
                ('file_size', models.PositiveIntegerField(blank=True, help_text='File size in bytes', null=True)),
                ('width', models.PositiveIntegerField(blank=True, null=True)),
                ('height', models.PositiveIntegerField(blank=True, null=True)),
                ('bitrate', models.PositiveIntegerField(blank=True, null=True)),
                ('is_approved', models.BooleanField(default=False)),
                ('approved_at', models.DateTimeField(blank=True, null=True)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'creatives',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='AdSpot',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('name', models.CharField(max_length=255)),
                ('position', models.PositiveIntegerField(default=1, help_text='Position in the ad break')),
                ('start_time', models.DateTimeField()),
                ('end_time', models.DateTimeField()),
                ('target_demographics', models.JSONField(blank=True, default=dict)),
                ('impressions', models.PositiveIntegerField(default=0)),
                ('clicks', models.PositiveIntegerField(default=0)),
                ('is_active', models.BooleanField(default=True)),
                ('campaign', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='adspots', to='campaigns.campaign')),
                ('creative', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='adspots', to='campaigns.creative')),
                ('target_channels', models.ManyToManyField(blank=True, to='channels.channel')),
            ],
            options={
                'db_table': 'adspots',
                'ordering': ['campaign', 'position'],
            },
        ),
        migrations.CreateModel(
            name='AdBreakHistory',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('executed_at', models.DateTimeField()),
                ('duration', models.PositiveIntegerField(help_text='Actual duration in seconds')),
                ('impressions', models.PositiveIntegerField(default=0)),
                ('completion_rate', models.DecimalField(decimal_places=2, default=0, max_digits=5)),
                ('player_version', models.CharField(blank=True, max_length=50)),
                ('user_agent', models.TextField(blank=True)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('adspot', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='history', to='campaigns.adspot')),
                ('channel', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='campaign_adbreak_history', to='channels.channel')),
            ],
            options={
                'verbose_name_plural': 'Ad Break History',
                'db_table': 'adbreak_history',
                'ordering': ['-executed_at'],
            },
        ),
        migrations.CreateModel(
            name='CampaignReport',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('report_type', models.CharField(choices=[('daily', 'Daily'), ('weekly', 'Weekly'), ('monthly', 'Monthly'), ('custom', 'Custom')], max_length=20)),
                ('start_date', models.DateField()),
                ('end_date', models.DateField()),
                ('total_impressions', models.PositiveIntegerField(default=0)),
                ('total_clicks', models.PositiveIntegerField(default=0)),
                ('total_spend', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
                ('ctr', models.DecimalField(decimal_places=2, default=0, max_digits=5)),
                ('cpm', models.DecimalField(decimal_places=2, default=0, max_digits=8)),
                ('cpc', models.DecimalField(decimal_places=2, default=0, max_digits=8)),
                ('campaign', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reports', to='campaigns.campaign')),
                ('generated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'campaign_reports',
                'ordering': ['-created_at'],
                'unique_together': {('campaign', 'report_type', 'start_date', 'end_date')},
            },
        ),
    ]
