# Generated by Django 6.0.3 on 2026-03-17 10:54

from decimal import Decimal

from django.db import migrations, models


def seed_referral_program_defaults(apps, schema_editor):
    ReferralCommission = apps.get_model('referrals', 'ReferralCommission')
    ReferralProgramSettings = apps.get_model('referrals', 'ReferralProgramSettings')

    ReferralProgramSettings.objects.get_or_create(
        id=1,
        defaults={
            'referrer_bonus_percentage': Decimal('10.00'),
            'referred_user_bonus_percentage': Decimal('5.00'),
            'minimum_deposit_amount': Decimal('300.00'),
            'maximum_deposit_amount': Decimal('5000.00'),
        },
    )

    default_levels = (
        (1, 5, Decimal('250.00')),
        (2, 25, Decimal('500.00')),
        (3, 100, Decimal('1000.00')),
        (4, 200, Decimal('2000.00')),
        (5, 500, Decimal('5000.00')),
    )

    for level, required_members, bonus_amount in default_levels:
        ReferralCommission.objects.update_or_create(
            level=level,
            defaults={
                'required_members': required_members,
                'bonus_amount': bonus_amount,
                'percentage': Decimal('0.00'),
                'is_active': True,
            },
        )


class Migration(migrations.Migration):

    dependencies = [
        ('referrals', '0002_referralearning_deposit_referralearning_earning_type_and_more'),
    ]

    operations = [
        migrations.CreateModel(
            name='ReferralProgramSettings',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('referrer_bonus_percentage', models.DecimalField(decimal_places=2, default=10.0, max_digits=5)),
                ('referred_user_bonus_percentage', models.DecimalField(decimal_places=2, default=5.0, max_digits=5)),
                ('minimum_deposit_amount', models.DecimalField(decimal_places=2, default=300.0, max_digits=15)),
                ('maximum_deposit_amount', models.DecimalField(decimal_places=2, default=5000.0, max_digits=15)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'verbose_name': 'Referral Program Setting',
                'verbose_name_plural': 'Referral Program Settings',
            },
        ),
        migrations.AlterModelOptions(
            name='referralcommission',
            options={'ordering': ['level'], 'verbose_name': 'Referral Level', 'verbose_name_plural': 'Referral Levels'},
        ),
        migrations.AddField(
            model_name='referralcommission',
            name='bonus_amount',
            field=models.DecimalField(decimal_places=2, default=250.0, max_digits=15),
        ),
        migrations.AddField(
            model_name='referralcommission',
            name='required_members',
            field=models.PositiveIntegerField(default=5),
        ),
        migrations.AlterField(
            model_name='referralcommission',
            name='percentage',
            field=models.DecimalField(decimal_places=2, default=0.0, max_digits=5),
        ),
        migrations.RunPython(seed_referral_program_defaults, migrations.RunPython.noop),
    ]
