"""
inventory/migrations/0002_seed_defaults.py
Seed default expense categories and the WEBSITE stock location.
"""

from django.db import migrations


EXPENSE_CATEGORIES = [
    "Transport",
    "Marketing",
    "Printing",
    "Event Costs",
    "Storage",
    "Salaries",
    "Utilities",
    "Miscellaneous",
]


def seed_data(apps, schema_editor):
    ExpenseCategory = apps.get_model("inventory", "ExpenseCategory")
    for name in EXPENSE_CATEGORIES:
        ExpenseCategory.objects.get_or_create(name=name)

    StockLocation = apps.get_model("inventory", "StockLocation")
    StockLocation.objects.get_or_create(
        code="WEBSITE",
        defaults={
            "name": "Online Store (Website)",
            "location_type": "website",
            "is_active": True,
        },
    )
    StockLocation.objects.get_or_create(
        code="MAIN-WH",
        defaults={
            "name": "Main Warehouse",
            "location_type": "warehouse",
            "is_active": True,
        },
    )


def unseed_data(apps, schema_editor):
    pass  # non-destructive reverse


class Migration(migrations.Migration):
    dependencies = [
        ("inventory", "0001_initial"),
    ]

    operations = [
        migrations.RunPython(seed_data, unseed_data),
    ]
