# Generated migration for referral antifraud: backlog, activity days, pending bonuses

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


class Migration(migrations.Migration):

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

    operations = [
        migrations.CreateModel(
            name='ReferralInvitedEmail',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('email', models.EmailField(db_index=True, max_length=254, unique=True, verbose_name='Email приглашённого')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Дата')),
                ('referrer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invited_emails', to=settings.AUTH_USER_MODEL, verbose_name='Реферер')),
                ('referred_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='Приглашённый пользователь')),
            ],
            options={
                'verbose_name': 'Приглашённый email',
                'verbose_name_plural': 'Бэклог приглашённых email',
                'db_table': 'referrals_invited_emails',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='UserActivityDay',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date', models.DateField(db_index=True, verbose_name='Дата')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Создано')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='activity_days', to=settings.AUTH_USER_MODEL, verbose_name='Пользователь')),
            ],
            options={
                'verbose_name': 'День активности',
                'verbose_name_plural': 'Дни активности',
                'db_table': 'referrals_user_activity_days',
                'ordering': ['-date'],
                'unique_together': {('user', 'date')},
            },
        ),
        migrations.CreateModel(
            name='PendingReferralBonus',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('referred_at', models.DateTimeField(db_index=True, verbose_name='Дата приглашения')),
                ('points', models.IntegerField(validators=[django.core.validators.MinValueValidator(0)], verbose_name='Очки к начислению')),
                ('level', models.IntegerField(default=1, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(2)], verbose_name='Уровень (1 — прямой, 2 — непрямой)')),
                ('reason', models.CharField(blank=True, max_length=255, verbose_name='Причина')),
                ('status', models.CharField(choices=[('pending', 'Ожидает'), ('paid', 'Начислено'), ('cancelled', 'Отменено')], db_index=True, default='pending', max_length=20, verbose_name='Статус')),
                ('paid_at', models.DateTimeField(blank=True, null=True, verbose_name='Дата начисления')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Создано')),
                ('referrer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pending_referral_bonuses', to=settings.AUTH_USER_MODEL, verbose_name='Реферер')),
                ('referred_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pending_bonuses_for_me', to=settings.AUTH_USER_MODEL, verbose_name='Реферал')),
            ],
            options={
                'verbose_name': 'Ожидающий бонус за реферала',
                'verbose_name_plural': 'Ожидающие бонусы за рефералов',
                'db_table': 'referrals_pending_referral_bonus',
                'ordering': ['referred_at'],
            },
        ),
        migrations.AddIndex(
            model_name='useractivityday',
            index=models.Index(fields=['user', 'date'], name='referrals_u_user_id_8b0b0d_idx'),
        ),
        migrations.AddIndex(
            model_name='pendingreferralbonus',
            index=models.Index(fields=['status', 'referred_at'], name='referrals_p_status_9c2e2a_idx'),
        ),
    ]
