# Generated by Django 5.2.7 on 2026-06-09 08:10

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


class Migration(migrations.Migration):

    dependencies = [
        ('restaurant', '0013_aaharordersync_is_transfer'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='CustomerWallet',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('coin_balance', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
                ('lifetime_cash_spent', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
                ('total_orders', models.IntegerField(default=0)),
                ('referral_code', models.CharField(blank=True, max_length=20, unique=True)),
                ('is_summit_vip', models.BooleanField(default=False)),
                ('summit_vip_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='loyalty_wallets', to=settings.AUTH_USER_MODEL)),
                ('referred_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='referrals_made', to=settings.AUTH_USER_MODEL)),
                ('restaurant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='customer_wallets', to='restaurant.restaurant')),
            ],
            options={
                'unique_together': {('customer', 'restaurant')},
            },
        ),
        migrations.CreateModel(
            name='LoyaltyProgram',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('program_name', models.CharField(default='Loyalty Program', max_length=200)),
                ('is_active', models.BooleanField(default=False)),
                ('coin_value_in_rupees', models.DecimalField(decimal_places=2, default=1.0, help_text='1 coin = ₹X. e.g. 1.00 means 1 coin = ₹1', max_digits=6)),
                ('redemption_cap_percent', models.DecimalField(decimal_places=2, default=50.0, help_text='Max % of bill payable by coins (Iron Law 1)', max_digits=5)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('restaurant', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='loyalty_program', to='restaurant.restaurant')),
            ],
        ),
        migrations.CreateModel(
            name='LoyaltyRule',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('rule_type', models.CharField(choices=[('WELCOME_HOOK', 'Welcome Hook (Squad Drop)'), ('REFERRAL', 'Referral (Sherpa Link)'), ('SUBSCRIPTION', 'Subscription Pass (Liquid Gold)'), ('WALLET_TOPUP', 'Wallet Top-up Bonus (Stash SIP)'), ('SOCIETY_VAULT', 'Society Vault'), ('MILESTONE_SPEND', 'Milestone Spend Bonus'), ('SUMMIT', 'Ultimate Summit (Kathmandu)'), ('DEAD_HOUR_DROP', 'Dead-Hour Drop'), ('CUSTOM', 'Custom Rule')], max_length=30)),
                ('is_active', models.BooleanField(default=True)),
                ('title', models.CharField(max_length=200)),
                ('description', models.TextField(blank=True)),
                ('trigger_config', models.JSONField(default=dict, help_text='Rule trigger parameters')),
                ('reward_coins', models.DecimalField(decimal_places=2, default=0, help_text='Coins awarded when this rule triggers', max_digits=10)),
                ('reward_expiry_hours', models.IntegerField(blank=True, help_text='Hours until awarded coins expire. Null = never expires (Iron Law 3)', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('program', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rules', to='restaurant.loyaltyprogram')),
            ],
        ),
        migrations.CreateModel(
            name='CoinTransaction',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('transaction_type', models.CharField(choices=[('EARNED', 'Earned from Order'), ('REDEEMED', 'Redeemed at Checkout'), ('EXPIRED', 'Expired'), ('REFERRAL', 'Referral Reward'), ('TOPUP_BONUS', 'Wallet Top-up Bonus'), ('ADMIN_CREDIT', 'Admin Credit'), ('ADMIN_DEBIT', 'Admin Debit')], max_length=20)),
                ('coins', models.DecimalField(decimal_places=2, max_digits=10)),
                ('expires_at', models.DateTimeField(blank=True, null=True)),
                ('is_expired', models.BooleanField(default=False)),
                ('notes', models.CharField(blank=True, max_length=255)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('source_booking', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='coin_transactions', to='restaurant.booking')),
                ('wallet', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='transactions', to='restaurant.customerwallet')),
                ('source_rule', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='restaurant.loyaltyrule')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
    ]
