from datetime import date

from django.core.management import BaseCommand
from django.db import transaction

from gaehsnitz.models import Drink, Payment

PAYMENTS = [
    # purpose, date, amount
    ("Toiletten", date(2026, 5, 6), 210.01),
    ("Anzahlung Getränke+Kühlschrank+Bänke", date(2026, 6, 8), 400.00),
    ("Baumarkt", date(2026, 5, 23), 194.00),
    ("Band: Six Good Years", date(2026, 6, 12), 150.00),
    ("Band: Melo-Komplott", date(2026, 6, 12), 100.00),
    ("Band: Mörtel", date(2026, 6, 12), 150.00),
    ("Band: Kotpiloten", date(2026, 6, 13), 150.00),
    ("Band: Knast", date(2026, 6, 13), 150.00),
    ("Band: Quast", date(2026, 6, 13), 300.00),
]

DRINKS = [
    # name, category, crates, btl/crate, size, price/crate, deposit/crate, sale/btl
    ("Sternburg Export", "beer", 12, 20, 0.5, 9.49, 3.10, 2.00),
    ("Ur-Krostitzer", "beer", 5, 20, 0.5, 16.49, 3.10, 2.50),
    ("Budweiser", "beer", 5, 20, 0.5, 20.99, 3.10, 2.50),
    ("Altenburger Helles", "beer", 5, 20, 0.5, 13.99, 4.50, 2.50),
    ("Feldschl. Radler", "radler", 2, 20, 0.5, 14.99, 3.10, 2.50),
    ("Lübzer Grapef. 0,0", "alc_free_radler", 1, 20, 0.5, 17.99, 3.10, 2.50),
    ("Freiberger 0,0", "alc_free_beer", 4, 20, 0.5, 15.49, 3.10, 2.50),
    ("Club Mate", "soft", 2, 20, 0.5, 17.49, 4.50, 2.50),
    ("Vita Cola", "soft", 2, 12, 1.0, 10.99, 3.30, 2.50),
    ("Paulaner Spezi", "soft", 2, 20, 0.5, 17.99, 3.10, 2.50),
    ("Wasser", "water", 10, 12, 1.0, 5.99, 3.30, 1.50),
    ("Sekty Drink", "sekt", 0, 1, 0.33, 0.00, 0.00, 3.50),
]


class Command(BaseCommand):
    help = "Seed Drink and Payment rows for the 2026 festival."

    @transaction.atomic
    def handle(self, *args, **options):
        for purpose, day, amount in PAYMENTS:
            obj, created = Payment.objects.update_or_create(
                purpose=purpose,
                date=day,
                defaults={"amount": amount},
            )
            self.stdout.write(f"{'created' if created else 'updated'}: {obj.purpose} ({obj.date})")

        for name, category, crates, btl, size, price, deposit, sale in DRINKS:
            obj, created = Drink.objects.update_or_create(
                name=name,
                year=2026,
                defaults={
                    "category": category,
                    "crates_ordered": crates,
                    "crates_purchased": crates,
                    "crates_returned": 0,
                    "purchase_price_per_crate": price,
                    "deposit_per_crate": deposit,
                    "bottles_per_crate": btl,
                    "bottle_size": size,
                    "sale_price_per_bottle": sale,
                },
            )
            self.stdout.write(f"{'created' if created else 'updated'}: {obj.name}")
