# Generated by Django 5.0.14 on 2025-10-29 15:09

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


class Migration(migrations.Migration):

    dependencies = [
        ("django_affiliate_system", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.AlterModelOptions(
            name="commissionrule",
            options={"ordering": ["-priority", "id"]},
        ),
        migrations.RenameIndex(
            model_name="referralaction",
            new_name="affiliates__referra_ae9256_idx",
            old_name="django_affi_referra_0889de_idx",
        ),
        migrations.RenameIndex(
            model_name="referralaction",
            new_name="affiliates__tenant__cb1abf_idx",
            old_name="django_affi_tenant__81903a_idx",
        ),
        migrations.RemoveField(
            model_name="tenant",
            name="api_key",
        ),
        migrations.AddField(
            model_name="commissionrule",
            name="priority",
            field=models.PositiveIntegerField(
                default=0, help_text="Higher priority rules are evaluated first"
            ),
        ),
        migrations.AddField(
            model_name="referrallink",
            name="campaign_name",
            field=models.CharField(
                blank=True, help_text="Optional campaign identifier", max_length=255
            ),
        ),
        migrations.AddField(
            model_name="referrallink",
            name="notes",
            field=models.TextField(blank=True, help_text="Internal notes about this link"),
        ),
        migrations.AlterField(
            model_name="affiliate",
            name="balance",
            field=models.DecimalField(
                decimal_places=2,
                default=0.0,
                help_text="Current unpaid commission balance",
                max_digits=10,
            ),
        ),
        migrations.AlterField(
            model_name="affiliate",
            name="code",
            field=models.CharField(db_index=True, max_length=50, unique=True),
        ),
        migrations.AlterField(
            model_name="affiliate",
            name="payout_details",
            field=models.JSONField(
                default=dict, help_text="Payment method details (encrypted in production)"
            ),
        ),
        migrations.AlterField(
            model_name="affiliate",
            name="payout_method",
            field=models.CharField(
                blank=True, help_text="e.g., stripe, paypal, bank_transfer", max_length=50
            ),
        ),
        migrations.AlterField(
            model_name="affiliate",
            name="payout_threshold",
            field=models.DecimalField(
                decimal_places=2,
                default=50.0,
                help_text="Minimum balance required to request payout",
                max_digits=10,
            ),
        ),
        migrations.AlterField(
            model_name="affiliate",
            name="tenant",
            field=models.ForeignKey(
                blank=True,
                help_text="Optional: Associate affiliate with a specific tenant",
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="affiliates",
                to="django_affiliate_system.tenant",
            ),
        ),
        migrations.AlterField(
            model_name="affiliate",
            name="user",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="affiliates",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AlterField(
            model_name="commission",
            name="rate",
            field=models.DecimalField(
                decimal_places=2,
                help_text="Commission rate at time of action (if percentage-based)",
                max_digits=5,
            ),
        ),
        migrations.AlterField(
            model_name="commission",
            name="status",
            field=models.CharField(
                choices=[
                    ("pending", "Pending"),
                    ("approved", "Approved"),
                    ("rejected", "Rejected"),
                    ("paid", "Paid"),
                ],
                db_index=True,
                default="pending",
                max_length=20,
            ),
        ),
        migrations.AlterField(
            model_name="commissionrule",
            name="action_type",
            field=models.CharField(
                choices=[
                    ("click", "CLICK"),
                    ("page_view", "PAGE_VIEW"),
                    ("signup", "SIGNUP"),
                    ("purchase", "PURCHASE"),
                    ("other", "OTHER"),
                ],
                max_length=20,
            ),
        ),
        migrations.AlterField(
            model_name="commissionrule",
            name="is_percentage",
            field=models.BooleanField(
                default=True, help_text="True for percentage-based, False for flat amount"
            ),
        ),
        migrations.AlterField(
            model_name="commissionrule",
            name="max_value",
            field=models.DecimalField(
                blank=True,
                decimal_places=2,
                help_text="Maximum commission amount (for percentage-based)",
                max_digits=10,
                null=True,
            ),
        ),
        migrations.AlterField(
            model_name="commissionrule",
            name="min_value",
            field=models.DecimalField(
                blank=True,
                decimal_places=2,
                help_text="Minimum commission amount (for percentage-based)",
                max_digits=10,
                null=True,
            ),
        ),
        migrations.AlterField(
            model_name="commissionrule",
            name="tenant",
            field=models.ForeignKey(
                blank=True,
                help_text="Optional: Tenant-specific rules. Leave blank for global rules.",
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="commission_rules",
                to="django_affiliate_system.tenant",
            ),
        ),
        migrations.AlterField(
            model_name="commissionrule",
            name="value",
            field=models.DecimalField(
                decimal_places=2,
                help_text="Percentage (e.g., 10.00 for 10%) or flat amount",
                max_digits=10,
            ),
        ),
        migrations.AlterField(
            model_name="payout",
            name="reference",
            field=models.CharField(
                blank=True, help_text="External payment reference ID", max_length=255
            ),
        ),
        migrations.AlterField(
            model_name="payout",
            name="status",
            field=models.CharField(
                choices=[
                    ("pending", "Pending"),
                    ("processing", "Processing"),
                    ("paid", "Paid"),
                    ("failed", "Failed"),
                ],
                db_index=True,
                default="pending",
                max_length=20,
            ),
        ),
        migrations.AlterField(
            model_name="payout",
            name="tenant",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="payouts",
                to="django_affiliate_system.tenant",
            ),
        ),
        migrations.AlterField(
            model_name="referralaction",
            name="action_type",
            field=models.CharField(
                choices=[
                    ("click", "CLICK"),
                    ("page_view", "PAGE_VIEW"),
                    ("signup", "SIGNUP"),
                    ("purchase", "PURCHASE"),
                    ("other", "OTHER"),
                ],
                max_length=20,
            ),
        ),
        migrations.AlterField(
            model_name="referralaction",
            name="conversion_value",
            field=models.DecimalField(
                blank=True,
                decimal_places=2,
                help_text="Monetary value of the conversion",
                max_digits=10,
                null=True,
            ),
        ),
        migrations.AlterField(
            model_name="referralaction",
            name="is_converted",
            field=models.BooleanField(db_index=True, default=False),
        ),
        migrations.AlterField(
            model_name="referralaction",
            name="metadata",
            field=models.JSONField(
                default=dict, help_text="Additional tracking data (UTM params, device info, etc.)"
            ),
        ),
        migrations.AlterField(
            model_name="referralaction",
            name="referring_url",
            field=models.URLField(blank=True, max_length=500),
        ),
        migrations.AlterField(
            model_name="referralaction",
            name="session_id",
            field=models.CharField(
                blank=True,
                help_text="Optional session ID for multi-touch attribution",
                max_length=100,
            ),
        ),
        migrations.AlterField(
            model_name="referralaction",
            name="tenant",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                to="django_affiliate_system.tenant",
            ),
        ),
        migrations.AlterField(
            model_name="referralaction",
            name="timestamp",
            field=models.DateTimeField(auto_now_add=True, db_index=True),
        ),
        migrations.AlterField(
            model_name="referrallink",
            name="destination_url",
            field=models.URLField(help_text="Where to redirect users who click this link"),
        ),
        migrations.AlterField(
            model_name="referralsession",
            name="is_converted",
            field=models.BooleanField(db_index=True, default=False),
        ),
        migrations.AlterField(
            model_name="referralsession",
            name="session_id",
            field=models.CharField(db_index=True, max_length=100, unique=True),
        ),
        migrations.AlterField(
            model_name="tenant",
            name="cookie_duration_days",
            field=models.PositiveIntegerField(
                default=30, help_text="How long to track referrals via cookies"
            ),
        ),
        migrations.AlterField(
            model_name="tenant",
            name="default_commission_rate",
            field=models.DecimalField(
                decimal_places=2,
                default=10.0,
                help_text="Default commission rate percentage",
                max_digits=5,
            ),
        ),
        migrations.AlterField(
            model_name="tenant",
            name="destination_url",
            field=models.URLField(blank=True),
        ),
        migrations.AlterField(
            model_name="tenant",
            name="owner",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.PROTECT,
                related_name="owned_tenants",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AlterField(
            model_name="tenant",
            name="subdomain",
            field=models.CharField(blank=True, max_length=255, null=True, unique=True),
        ),
        migrations.AddIndex(
            model_name="affiliate",
            index=models.Index(fields=["code"], name="affiliates__code_829718_idx"),
        ),
        migrations.AddIndex(
            model_name="affiliate",
            index=models.Index(fields=["user", "is_active"], name="affiliates__user_id_9d9242_idx"),
        ),
        migrations.AddIndex(
            model_name="commission",
            index=models.Index(
                fields=["affiliate", "status"], name="affiliates__affilia_c2b19a_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="commission",
            index=models.Index(fields=["calculated_at"], name="affiliates__calcula_ff9be9_idx"),
        ),
        migrations.AddIndex(
            model_name="commissionrule",
            index=models.Index(
                fields=["tenant", "action_type", "is_active"], name="affiliates__tenant__b1b254_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="payout",
            index=models.Index(
                fields=["affiliate", "status"], name="affiliates__affilia_350b30_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="payout",
            index=models.Index(fields=["created_at"], name="affiliates__created_831b5c_idx"),
        ),
        migrations.AddIndex(
            model_name="referralaction",
            index=models.Index(fields=["timestamp"], name="affiliates__timesta_228967_idx"),
        ),
        migrations.AddIndex(
            model_name="referralaction",
            index=models.Index(fields=["session_id"], name="affiliates__session_2518d2_idx"),
        ),
        migrations.AddIndex(
            model_name="referrallink",
            index=models.Index(fields=["slug"], name="affiliates__slug_1eed18_idx"),
        ),
        migrations.AddIndex(
            model_name="referrallink",
            index=models.Index(
                fields=["affiliate", "is_active"], name="affiliates__affilia_ad5c7e_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="referralsession",
            index=models.Index(fields=["session_id"], name="affiliates__session_6c57db_idx"),
        ),
        migrations.AddIndex(
            model_name="referralsession",
            index=models.Index(
                fields=["affiliate", "is_converted"], name="affiliates__affilia_6e4f22_idx"
            ),
        ),
        migrations.AlterModelTable(
            name="affiliate",
            table="affiliates_affiliate",
        ),
        migrations.AlterModelTable(
            name="commission",
            table="affiliates_commission",
        ),
        migrations.AlterModelTable(
            name="commissionrule",
            table="affiliates_commissionrule",
        ),
        migrations.AlterModelTable(
            name="payout",
            table="affiliates_payout",
        ),
        migrations.AlterModelTable(
            name="referralaction",
            table="affiliates_referralaction",
        ),
        migrations.AlterModelTable(
            name="referrallink",
            table="affiliates_referrallink",
        ),
        migrations.AlterModelTable(
            name="tenant",
            table="affiliates_tenant",
        ),
    ]
