# Generated by Django 5.1 on 2024-08-17 19:32

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='PayoutMethod',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('method', models.CharField(choices=[('wise', 'Wise'), ('crypto', 'Crypto')], max_length=10)),
                ('payment_address', models.CharField(help_text='Payment address (email or solana wallet)', max_length=100)),
            ],
        ),
        migrations.CreateModel(
            name='ReferralProgram',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('name', models.CharField(max_length=255, unique=True)),
                ('commission_rate', models.DecimalField(decimal_places=2, help_text='Commission rate as a percentage', max_digits=5, validators=[django.core.validators.MinValueValidator(Decimal('0.01'))])),
                ('is_active', models.BooleanField(default=True, help_text='Indicates if this is the currently active referral program')),
                ('min_withdrawal_balance', models.DecimalField(decimal_places=2, default=0.0, help_text='Minimum balance required to withdraw earnings', max_digits=10)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='Promoter',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('referral_token', models.CharField(blank=True, help_text='Referral token', max_length=256, null=True, unique=True)),
                ('referral_link', models.CharField(blank=True, help_text='Referral link', max_length=256, null=True, unique=True)),
                ('link_clicked', models.IntegerField(default=0)),
                ('min_withdrawal_balance', models.DecimalField(decimal_places=2, default=0.0, help_text='Custom minimum balance required to withdraw earnings', max_digits=10)),
                ('active_payout_method', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='referrals.payoutmethod')),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='promoter', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='PromoterPayout',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('amount', models.IntegerField()),
                ('payout_method', models.CharField(choices=[('wise', 'Wise'), ('crypto', 'Crypto')], max_length=10)),
                ('tx_signature', models.CharField(blank=True, max_length=255, null=True)),
                ('promoter', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='promoter_payouts', to='referrals.promoter')),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='Referral',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('invitation_method', models.CharField(choices=[('email', 'Email'), ('link', 'Link')], max_length=10)),
                ('status', models.CharField(choices=[('signup', 'Signup'), ('active', 'Active'), ('refund', 'Refund')], max_length=10)),
                ('commission_rate', models.DecimalField(decimal_places=2, default=0.0, help_text='Commission rate at the moment of creating the referral', max_digits=5)),
                ('promoter', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='referrals', to='referrals.promoter')),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='referral', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='PromoterCommission',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('amount', models.IntegerField(null=True)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('paid', 'Paid'), ('failed', 'Failed'), ('refund', 'Refund')], default='pending', max_length=10)),
                ('failure_reason', models.TextField(blank=True, null=True)),
                ('invoice_external_id', models.CharField(blank=True, help_text='Chargebee invoice ID', max_length=255, null=True)),
                ('promoter', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='promoter_commission', to='referrals.promoter')),
                ('referral', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='referral_commission', to='referrals.referral')),
            ],
            options={
                'abstract': False,
            },
        ),
    ]
