# Generated by Django 6.0.3 on 2026-05-14 19:43

import django.db.models.deletion
import uuid
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('geo', '0011_rename_geo_franchi_territo_4f740f_idx_geo_franchi_territo_f5a874_idx_and_more'),
        ('orders', '0008_payment_review_status'),
        ('products', '0011_add_hsn_code_to_product'),
    ]

    operations = [
        migrations.CreateModel(
            name='FranchisePincodeCoverage',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('pincode_code', models.CharField(db_index=True, help_text='Denormalised pincode string for fast O(1) lookup without JOIN', max_length=20)),
                ('city', models.CharField(blank=True, default='', max_length=100)),
                ('state', models.CharField(blank=True, default='', max_length=100)),
                ('is_serviceable', models.BooleanField(default=True)),
                ('assigned_date', models.DateField(auto_now_add=True)),
                ('pincode', models.ForeignKey(blank=True, help_text='FK to canonical Pincode record (optional; pincode_code is the fast-lookup field)', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='franchise_coverage', to='geo.pincode')),
                ('store', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pincode_coverage', to='geo.franchisestore')),
            ],
            options={
                'indexes': [models.Index(fields=['pincode_code', 'is_serviceable'], name='geo_franchi_pincode_33f403_idx'), models.Index(fields=['store', 'is_serviceable'], name='geo_franchi_store_i_e4b409_idx')],
                'unique_together': {('store', 'pincode_code')},
            },
        ),
        migrations.CreateModel(
            name='FranchiseStoreEarning',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('order_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('commission_percentage', models.DecimalField(decimal_places=2, max_digits=5)),
                ('commission_amount', models.DecimalField(decimal_places=2, max_digits=12)),
                ('earning_type', models.CharField(choices=[('FULFILLMENT', 'Order Fulfillment'), ('DELIVERY', 'Local Delivery'), ('PICKUP', 'Customer Pickup')], default='FULFILLMENT', max_length=20)),
                ('status', models.CharField(choices=[('PENDING', 'Pending'), ('CREDITED', 'Credited'), ('CANCELLED', 'Cancelled')], db_index=True, default='PENDING', max_length=20)),
                ('credited_at', models.DateTimeField(blank=True, null=True)),
                ('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='franchise_earnings', to='orders.order')),
                ('store', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='marketplace_earnings', to='geo.franchisestore')),
            ],
            options={
                'indexes': [models.Index(fields=['store', 'status'], name='geo_franchi_store_i_3d0dc3_idx'), models.Index(fields=['order'], name='geo_franchi_order_i_f1ab01_idx'), models.Index(fields=['status', 'created_at'], name='geo_franchi_status_241ca4_idx')],
            },
        ),
        migrations.CreateModel(
            name='FranchiseStoreInventory',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('stock', models.PositiveIntegerField(default=0)),
                ('reserved_stock', models.PositiveIntegerField(default=0)),
                ('reorder_point', models.PositiveIntegerField(default=5, help_text='Alert threshold for low-stock notifications')),
                ('max_stock_level', models.PositiveIntegerField(default=100, help_text='Maximum stock ceiling for auto-reorder calculations')),
                ('auto_reorder', models.BooleanField(default=False, help_text='Automatically create a replenishment request when below reorder_point')),
                ('last_restocked', models.DateTimeField(blank=True, null=True)),
                ('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='franchise_inventories', to='products.product')),
                ('store', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='marketplace_inventory', to='geo.franchisestore')),
            ],
            options={
                'indexes': [models.Index(fields=['store', 'product'], name='geo_franchi_store_i_e82e7a_idx'), models.Index(fields=['product', 'store'], name='geo_franchi_product_3f6d5b_idx')],
                'unique_together': {('store', 'product')},
            },
        ),
    ]
