# Generated by Django 5.2.1 on 2026-07-23 09:00

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('certifications', '0006_certificationapplication_discount_amount_and_more'),
        ('enrollments', '0003_enrollment_discount_amount_and_more'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='PromoCode',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(db_index=True, help_text='Students enter this code (e.g. NUST2026). Stored uppercase.', max_length=40, unique=True)),
                ('title', models.CharField(help_text='Internal label, e.g. NUST Spring Offer', max_length=200)),
                ('institute_name', models.CharField(help_text='College, university, or institute this promo is for.', max_length=200)),
                ('description', models.TextField(blank=True)),
                ('discount_type', models.CharField(choices=[('percent', 'Percentage (%)'), ('fixed', 'Fixed amount')], default='percent', max_length=20)),
                ('discount_value', models.DecimalField(decimal_places=2, help_text='Percent (e.g. 20) or fixed currency amount.', max_digits=8)),
                ('applies_to', models.CharField(choices=[('courses', 'Courses only'), ('certifications', 'Certifications only'), ('both', 'Courses & certifications')], default='both', max_length=20)),
                ('max_uses', models.PositiveIntegerField(default=0, help_text='Total redemptions allowed. 0 = unlimited.')),
                ('max_uses_per_user', models.PositiveIntegerField(default=1, help_text='How many times one student can use this code. 0 = unlimited.')),
                ('used_count', models.PositiveIntegerField(default=0)),
                ('min_amount', models.DecimalField(decimal_places=2, default=0, help_text='Minimum order amount before discount applies.', max_digits=8)),
                ('valid_from', models.DateTimeField(blank=True, null=True)),
                ('valid_until', models.DateTimeField(blank=True, null=True)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_promo_codes', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='PromoRedemption',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('scope', models.CharField(max_length=20)),
                ('original_amount', models.DecimalField(decimal_places=2, max_digits=8)),
                ('discount_amount', models.DecimalField(decimal_places=2, max_digits=8)),
                ('final_amount', models.DecimalField(decimal_places=2, max_digits=8)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('certification_application', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='promo_redemptions', to='certifications.certificationapplication')),
                ('enrollment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='promo_redemptions', to='enrollments.enrollment')),
                ('promo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='redemptions', to='promotions.promocode')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='promo_redemptions', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
    ]
