# Generated migration for Discount model and discount-related updates

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('shop', '0015_product_barcode_product_qr_code'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        # Add Discount model
        migrations.CreateModel(
            name='Discount',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('description', models.TextField(blank=True)),
                ('code', models.CharField(blank=True, help_text='Optional promotional code (e.g., SAVE20)', max_length=50, unique=True)),
                ('discount_type', models.CharField(choices=[('percentage', 'Percentage (%)'), ('fixed', 'Fixed Amount')], default='percentage', max_length=20)),
                ('discount_value', models.DecimalField(decimal_places=2, help_text='Discount value (% or fixed amount)', max_digits=10)),
                ('min_purchase', models.DecimalField(decimal_places=2, default=0, help_text='Minimum purchase amount required', max_digits=10)),
                ('is_active', models.BooleanField(default=True)),
                ('start_date', models.DateTimeField()),
                ('end_date', models.DateTimeField()),
                ('usage_limit', models.PositiveIntegerField(blank=True, help_text='Total number of times this discount can be used', null=True)),
                ('usage_count', models.PositiveIntegerField(default=0, editable=False)),
                ('usage_limit_per_user', models.PositiveIntegerField(blank=True, help_text='Max times one user can use this discount', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('categories', models.ManyToManyField(blank=True, help_text='Leave empty to apply to all categories', related_name='discounts', to='shop.Category')),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_discounts', to=settings.AUTH_USER_MODEL)),
                ('products', models.ManyToManyField(blank=True, help_text='Leave empty to apply to all products', related_name='discounts', to='shop.Product')),
            ],
            options={
                'verbose_name': 'Discount',
                'verbose_name_plural': 'Discounts',
                'ordering': ['-created_at'],
            },
        ),
        # Add discount fields to Order model
        migrations.AddField(
            model_name='order',
            name='discount',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to='shop.discount'),
        ),
        migrations.AddField(
            model_name='order',
            name='subtotal',
            field=models.DecimalField(decimal_places=2, default=0, max_digits=10),
        ),
        migrations.AddField(
            model_name='order',
            name='discount_amount',
            field=models.DecimalField(decimal_places=2, default=0, max_digits=10),
        ),
    ]
