from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="LeadSettings",
            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)),
                ("enable_public_forms", models.BooleanField(default=True)),
                ("enable_admin_notifications", models.BooleanField(default=True)),
                ("enable_user_auto_reply", models.BooleanField(default=True)),
                (
                    "admin_notification_emails",
                    models.TextField(blank=True, help_text="Comma-separated emails for lead notifications."),
                ),
                ("export_enabled", models.BooleanField(default=True)),
            ],
            options={"verbose_name": "Lead Settings", "verbose_name_plural": "Lead Settings"},
        ),
        migrations.CreateModel(
            name="LeadSubmission",
            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)),
                (
                    "lead_type",
                    models.CharField(
                        choices=[
                            ("newsletter_subscriber", "Newsletter Subscriber"),
                            ("waitlist_registration", "Waitlist Registration"),
                            ("general_enquiry", "General Enquiry"),
                            ("product_enquiry", "Product Enquiry"),
                            ("service_enquiry", "Service Enquiry"),
                            ("partner_application", "Partner Application"),
                            ("vendor_registration", "Vendor Registration"),
                            ("volunteer_application", "Volunteer Application"),
                            ("contact_message", "Contact Message"),
                            ("early_access_request", "Early Access Request"),
                        ],
                        db_index=True,
                        max_length=40,
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("new", "New"),
                            ("contacted", "Contacted"),
                            ("interested", "Interested"),
                            ("follow_up", "Follow-up"),
                            ("converted", "Converted"),
                            ("closed", "Closed"),
                            ("spam", "Spam"),
                        ],
                        db_index=True,
                        default="new",
                        max_length=20,
                    ),
                ),
                ("full_name", models.CharField(blank=True, max_length=160)),
                ("email", models.EmailField(blank=True, db_index=True, max_length=254)),
                ("mobile_number", models.CharField(blank=True, db_index=True, max_length=20)),
                ("city", models.CharField(blank=True, max_length=120)),
                ("interested_category", models.CharField(blank=True, max_length=160)),
                ("subject", models.CharField(blank=True, max_length=255)),
                ("message", models.TextField(blank=True)),
                ("notes", models.TextField(blank=True)),
                ("source_page_url", models.CharField(blank=True, max_length=500)),
                ("source_page_name", models.CharField(blank=True, db_index=True, max_length=255)),
                ("source_page_type", models.CharField(blank=True, db_index=True, max_length=100)),
                ("campaign_source", models.CharField(blank=True, db_index=True, max_length=120)),
                ("referral_source", models.CharField(blank=True, max_length=255)),
                ("ip_address", models.GenericIPAddressField(blank=True, null=True)),
                ("user_agent", models.TextField(blank=True)),
                ("device_info", models.CharField(blank=True, max_length=120)),
                ("payload", models.JSONField(blank=True, default=dict)),
                ("is_spam", models.BooleanField(db_index=True, default=False)),
                ("honeypot", models.CharField(blank=True, max_length=255)),
                ("admin_remarks", models.TextField(blank=True)),
                ("contacted_at", models.DateTimeField(blank=True, null=True)),
                ("converted_at", models.DateTimeField(blank=True, null=True)),
                ("closed_at", models.DateTimeField(blank=True, null=True)),
                (
                    "assigned_to",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="assigned_public_leads",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={"ordering": ["-created_at"]},
        ),
        migrations.AddIndex(
            model_name="leadsubmission",
            index=models.Index(fields=["lead_type", "status", "created_at"], name="lead_type_status_idx"),
        ),
        migrations.AddIndex(
            model_name="leadsubmission",
            index=models.Index(fields=["email", "lead_type", "created_at"], name="lead_email_type_idx"),
        ),
        migrations.AddIndex(
            model_name="leadsubmission",
            index=models.Index(fields=["source_page_name", "created_at"], name="lead_source_page_idx"),
        ),
    ]
