from django.db import migrations

SEED_BRANCHES = [
    {
        "city": "Hyderabad",
        "state": "Telangana",
        "address": "Road No. 12, Banjara Hills",
        "phone": "+91 8500105345",
        "email": "",
        "branch_type": "Head Office",
        "working_hours": "Mon-Sat, 10 AM - 6 PM",
        "is_active": True,
        "sort_order": 0,
    },
    {
        "city": "Mumbai",
        "state": "Maharashtra",
        "address": "Andheri West, Link Road",
        "phone": "+91 9876543210",
        "email": "",
        "branch_type": "Branch",
        "working_hours": "Mon-Sat, 10 AM - 6 PM",
        "is_active": True,
        "sort_order": 1,
    },
    {
        "city": "Delhi",
        "state": "Delhi NCR",
        "address": "Connaught Place, Block A",
        "phone": "+91 9876543211",
        "email": "",
        "branch_type": "Branch",
        "working_hours": "Mon-Sat, 10 AM - 6 PM",
        "is_active": True,
        "sort_order": 2,
    },
    {
        "city": "Bangalore",
        "state": "Karnataka",
        "address": "MG Road, Brigade Gateway",
        "phone": "+91 9876543212",
        "email": "",
        "branch_type": "Branch",
        "working_hours": "Mon-Sat, 10 AM - 6 PM",
        "is_active": True,
        "sort_order": 3,
    },
    {
        "city": "Chennai",
        "state": "Tamil Nadu",
        "address": "T. Nagar, Usman Road",
        "phone": "+91 9876543213",
        "email": "",
        "branch_type": "Branch",
        "working_hours": "Mon-Sat, 10 AM - 6 PM",
        "is_active": True,
        "sort_order": 4,
    },
    {
        "city": "Kolkata",
        "state": "West Bengal",
        "address": "Park Street, Block C",
        "phone": "+91 9876543214",
        "email": "",
        "branch_type": "Branch",
        "working_hours": "Mon-Sat, 10 AM - 6 PM",
        "is_active": True,
        "sort_order": 5,
    },
]


def seed_branches(apps, schema_editor):
    Branch = apps.get_model('settings', 'Branch')
    if Branch.objects.exists():
        return
    for b in SEED_BRANCHES:
        Branch.objects.create(**b)


def unseed_branches(apps, schema_editor):
    Branch = apps.get_model('settings', 'Branch')
    Branch.objects.all().delete()


class Migration(migrations.Migration):

    dependencies = [
        ('settings', '0003_branch'),
    ]

    operations = [
        migrations.RunPython(seed_branches, reverse_code=unseed_branches),
    ]
