from decimal import Decimal

from django.db import migrations


def seed_demo_pos(apps, schema_editor):
    Table = apps.get_model("core", "Table")
    Product = apps.get_model("core", "Product")

    tables = [
        ("Mesa 1", 2, "Terraza"),
        ("Mesa 2", 4, "Salón"),
        ("Mesa 3", 4, "Salón"),
        ("Mesa 4", 6, "Ventana"),
        ("Mesa 5", 2, "Barra"),
        ("Mesa 6", 4, "Terraza"),
        ("Mesa 7", 4, "Privado"),
        ("Mesa 8", 6, "Salón"),
    ]
    for name, seats, area in tables:
        Table.objects.get_or_create(name=name, defaults={"seats": seats, "area": area})

    products = [
        ("Burger clásica", "Platos", Decimal("12.50"), "Cocina"),
        ("Pasta de trufa", "Platos", Decimal("15.00"), "Cocina"),
        ("Ensalada César", "Entradas", Decimal("9.50"), "Cocina"),
        ("Papas bravas", "Entradas", Decimal("7.00"), "Cocina"),
        ("Limonada artesanal", "Bebidas", Decimal("4.50"), "Bar"),
        ("Té helado", "Bebidas", Decimal("3.80"), "Bar"),
    ]
    for name, category, price, station in products:
        Product.objects.get_or_create(
            name=name,
            defaults={"category": category, "price": price, "station": station, "is_available": True},
        )


def remove_demo_pos(apps, schema_editor):
    Table = apps.get_model("core", "Table")
    Product = apps.get_model("core", "Product")
    Table.objects.filter(name__in=[f"Mesa {idx}" for idx in range(1, 9)]).delete()
    Product.objects.filter(name__in=[
        "Burger clásica",
        "Pasta de trufa",
        "Ensalada César",
        "Papas bravas",
        "Limonada artesanal",
        "Té helado",
    ]).delete()


class Migration(migrations.Migration):

    dependencies = [
        ("core", "0001_initial"),
    ]

    operations = [
        migrations.RunPython(seed_demo_pos, remove_demo_pos),
    ]
