# Generated by Django 5.2 on 2025-05-08 21:53

import django.contrib.postgres.indexes
import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('country', '0005_alter_country_alpha_2_alter_country_alpha_3_and_more'),
        ('order', '0009_alter_order_customer_notes_alter_order_floor_and_more'),
        ('pay_way', '0006_alter_payway_sort_order'),
        ('product', '0021_alter_historicalproduct_seo_description_and_more'),
        ('region', '0005_alter_region_sort_order'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='OrderHistory',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated At')),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('change_type', models.CharField(choices=[('STATUS', 'Status Change'), ('PAYMENT', 'Payment Update'), ('SHIPPING', 'Shipping Update'), ('CUSTOMER', 'Customer Info Update'), ('ITEMS', 'Items Update'), ('ADDRESS', 'Address Update'), ('NOTE', 'Note Added'), ('REFUND', 'Refund Processed'), ('OTHER', 'Other Change')], max_length=20, verbose_name='Change Type')),
                ('previous_value', models.JSONField(blank=True, help_text='Previous value of the changed field(s).', null=True, verbose_name='Previous Value')),
                ('new_value', models.JSONField(blank=True, help_text='New value of the changed field(s).', null=True, verbose_name='New Value')),
                ('description', models.TextField(blank=True, default='', help_text='Description of what changed.', verbose_name='Description')),
                ('ip_address', models.GenericIPAddressField(blank=True, help_text='IP address from which the change was made.', null=True, verbose_name='IP Address')),
                ('user_agent', models.TextField(blank=True, help_text='User agent of the browser/client that made the change.', verbose_name='User Agent')),
            ],
            options={
                'verbose_name': 'Order History',
                'verbose_name_plural': 'Order History',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='OrderItemHistory',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated At')),
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('change_type', models.CharField(choices=[('QUANTITY', 'Quantity Change'), ('PRICE', 'Price Update'), ('REFUND', 'Item Refund'), ('OTHER', 'Other Change')], max_length=20, verbose_name='Change Type')),
                ('previous_value', models.JSONField(blank=True, help_text='Previous value of the changed field(s).', null=True, verbose_name='Previous Value')),
                ('new_value', models.JSONField(blank=True, help_text='New value of the changed field(s).', null=True, verbose_name='New Value')),
                ('description', models.TextField(blank=True, default='', help_text='Description of what changed.', verbose_name='Description')),
            ],
            options={
                'verbose_name': 'Order Item History',
                'verbose_name_plural': 'Order Item History',
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddField(
            model_name='order',
            name='payment_id',
            field=models.CharField(blank=True, default='', max_length=255, verbose_name='Payment ID'),
        ),
        migrations.AddField(
            model_name='order',
            name='payment_method',
            field=models.CharField(blank=True, default='', max_length=50, verbose_name='Payment Method'),
        ),
        migrations.AddField(
            model_name='order',
            name='payment_status',
            field=models.CharField(blank=True, choices=[('PENDING', 'Pending'), ('PROCESSING', 'Processing'), ('COMPLETED', 'Completed'), ('FAILED', 'Failed'), ('REFUNDED', 'Refunded'), ('PARTIALLY_REFUNDED', 'Partially Refunded'), ('CANCELED', 'Canceled')], default='PENDING', max_length=50, verbose_name='Payment Status'),
        ),
        migrations.AddField(
            model_name='order',
            name='shipping_carrier',
            field=models.CharField(blank=True, default='', max_length=255, verbose_name='Shipping Carrier'),
        ),
        migrations.AddField(
            model_name='order',
            name='status_updated_at',
            field=models.DateTimeField(blank=True, null=True, verbose_name='Status Updated At'),
        ),
        migrations.AddField(
            model_name='order',
            name='tracking_number',
            field=models.CharField(blank=True, default='', max_length=255, verbose_name='Tracking Number'),
        ),
        migrations.AddField(
            model_name='orderitem',
            name='is_refunded',
            field=models.BooleanField(default=False, verbose_name='Is Refunded'),
        ),
        migrations.AddField(
            model_name='orderitem',
            name='notes',
            field=models.TextField(blank=True, default='', verbose_name='Notes'),
        ),
        migrations.AddField(
            model_name='orderitem',
            name='original_quantity',
            field=models.IntegerField(blank=True, null=True, verbose_name='Original Quantity'),
        ),
        migrations.AddField(
            model_name='orderitem',
            name='refunded_quantity',
            field=models.IntegerField(default=0, verbose_name='Refunded Quantity'),
        ),
        migrations.AlterField(
            model_name='order',
            name='document_type',
            field=models.CharField(choices=[('RECEIPT', 'Receipt'), ('INVOICE', 'Invoice'), ('PROFORMA', 'Proforma Invoice'), ('SHIPPING_LABEL', 'Shipping Label'), ('RETURN_LABEL', 'Return Label'), ('CREDIT_NOTE', 'Credit Note')], default='RECEIPT', max_length=100, verbose_name='Document Type'),
        ),
        migrations.AlterField(
            model_name='order',
            name='status',
            field=models.CharField(choices=[('PENDING', 'Pending'), ('PROCESSING', 'Processing'), ('SHIPPED', 'Shipped'), ('DELIVERED', 'Delivered'), ('COMPLETED', 'Completed'), ('CANCELED', 'Canceled'), ('RETURNED', 'Returned'), ('REFUNDED', 'Refunded')], default='PENDING', max_length=20, verbose_name='Status'),
        ),
        migrations.AddIndex(
            model_name='order',
            index=django.contrib.postgres.indexes.BTreeIndex(fields=['status_updated_at'], name='order_order_status__c9f5b7_btree'),
        ),
        migrations.AddIndex(
            model_name='order',
            index=django.contrib.postgres.indexes.BTreeIndex(fields=['payment_status'], name='order_order_payment_c12f17_btree'),
        ),
        migrations.AddIndex(
            model_name='orderitem',
            index=models.Index(fields=['product'], name='order_order_product_ed1645_idx'),
        ),
        migrations.AddIndex(
            model_name='orderitem',
            index=models.Index(fields=['is_refunded'], name='order_order_is_refu_38a302_idx'),
        ),
        migrations.AddField(
            model_name='orderhistory',
            name='order',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='history', to='order.order'),
        ),
        migrations.AddField(
            model_name='orderhistory',
            name='user',
            field=models.ForeignKey(blank=True, help_text='User who made the change, if applicable.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='order_changes', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='orderitemhistory',
            name='order_item',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='history', to='order.orderitem'),
        ),
        migrations.AddField(
            model_name='orderitemhistory',
            name='user',
            field=models.ForeignKey(blank=True, help_text='User who made the change, if applicable.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='order_item_changes', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddIndex(
            model_name='orderhistory',
            index=django.contrib.postgres.indexes.BTreeIndex(fields=['created_at'], name='orderhistory_created_at_idx'),
        ),
        migrations.AddIndex(
            model_name='orderhistory',
            index=django.contrib.postgres.indexes.BTreeIndex(fields=['updated_at'], name='orderhistory_updated_at_idx'),
        ),
        migrations.AddIndex(
            model_name='orderhistory',
            index=models.Index(fields=['order', 'change_type'], name='order_order_order_i_4345b0_idx'),
        ),
        migrations.AddIndex(
            model_name='orderhistory',
            index=models.Index(fields=['order', '-created_at'], name='order_order_order_i_5a04bb_idx'),
        ),
        migrations.AddIndex(
            model_name='orderitemhistory',
            index=django.contrib.postgres.indexes.BTreeIndex(fields=['created_at'], name='orderitemhistory_created_at_idx'),
        ),
        migrations.AddIndex(
            model_name='orderitemhistory',
            index=django.contrib.postgres.indexes.BTreeIndex(fields=['updated_at'], name='orderitemhistory_updated_at_idx'),
        ),
        migrations.AddIndex(
            model_name='orderitemhistory',
            index=models.Index(fields=['order_item', '-created_at'], name='order_order_order_i_b122c2_idx'),
        ),
    ]
