"""
0004_pos_customer

Adds the Customer model and POS-related fields to Sale.
"""

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


class Migration(migrations.Migration):

    dependencies = [
        (
            "inventory",
            "0003_rename_inv_audit_model_obj_idx_inventory_a_model_n_740003_idx_and_more",
        ),
    ]

    operations = [
        # 1. Customer table
        migrations.CreateModel(
            name="Customer",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("name", models.CharField(max_length=255)),
                ("phone", models.CharField(max_length=20, unique=True)),
                ("email", models.EmailField(blank=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "Customer",
                "verbose_name_plural": "Customers",
                "ordering": ["name"],
            },
        ),
        # 2. FK from Sale → Customer
        migrations.AddField(
            model_name="sale",
            name="customer",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="sales",
                to="inventory.customer",
            ),
        ),
        # 3. customer_email on Sale
        migrations.AddField(
            model_name="sale",
            name="customer_email",
            field=models.EmailField(blank=True, default=""),
            preserve_default=False,
        ),
        # 4. payment_method
        migrations.AddField(
            model_name="sale",
            name="payment_method",
            field=models.CharField(
                blank=True,
                choices=[("cash", "Cash"), ("mpesa", "M-Pesa"), ("card", "Card / Bank Transfer")],
                max_length=10,
                default="",
            ),
            preserve_default=False,
        ),
        # 5. mpesa_code
        migrations.AddField(
            model_name="sale",
            name="mpesa_code",
            field=models.CharField(blank=True, max_length=20, default=""),
            preserve_default=False,
        ),
        # 6. amount_tendered
        migrations.AddField(
            model_name="sale",
            name="amount_tendered",
            field=models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True),
        ),
        # 7. receipt_sent
        migrations.AddField(
            model_name="sale",
            name="receipt_sent",
            field=models.BooleanField(default=False),
        ),
    ]
