# USE THIS ON AN EMPTY DATABASE TO GENERATE DEMO DATA
import asyncio
from datetime import date
from decimal import Decimal

import sys

from src.ezgg_lan_manager import init_services
from src.ezgg_lan_manager.types.CateringMenuItem import CateringMenuItemCategory
from src.ezgg_lan_manager.types.News import News

DEMO_USERS = [
    {"user_name": "manfred", "user_mail": "manfred@demomail.com", "password_clear_text": "manfred"},  # Gast
    {"user_name": "gustav", "user_mail": "gustav@demomail.com", "password_clear_text": "gustav"},  # Gast + Ticket(NORMAL)
    {"user_name": "jason", "user_mail": "juergen@demomail.com", "password_clear_text": "jason"},  # Gast + Ticket(NORMAL) + Sitzplatz
    {"user_name": "lisa", "user_mail": "lisa@demomail.com", "password_clear_text": "lisa"},  # Teamler
    {"user_name": "thomas", "user_mail": "thomas@demomail.com", "password_clear_text": "thomas"}  # Teamler + Admin
]


async def run() -> None:
    services = init_services()
    await services[3].init_db_pool()
    catering_service = services[1]
    user_service = services[8]
    accounting_service = services[0]
    ticket_service = services[7]
    seating_service = services[6]
    news_service = services[5]

    if input("Generate seating table? (y/N): ").lower() == "y":
        sys.exit("This part of the script is currently being reworked... :(")

    if not input("Generate users? (Y/n): ").lower() == "n":
        # MANFRED
        manfred = await user_service.create_user(DEMO_USERS[0]["user_name"], DEMO_USERS[0]["user_mail"],
                                                 DEMO_USERS[0]["password_clear_text"])

        # GUSTAV
        gustav = await user_service.create_user(DEMO_USERS[1]["user_name"], DEMO_USERS[1]["user_mail"],
                                                DEMO_USERS[1]["password_clear_text"])
        await accounting_service.add_balance(gustav.user_id, Decimal("1000.00"), "DEMO EINZAHLUNG")
        await ticket_service.purchase_ticket(gustav.user_id, "NORMAL")

        # JASON
        jason = await user_service.create_user(DEMO_USERS[2]["user_name"], DEMO_USERS[2]["user_mail"],
                                               DEMO_USERS[2]["password_clear_text"])
        await accounting_service.add_balance(jason.user_id, Decimal("1000.00"), "DEMO EINZAHLUNG")
        await ticket_service.purchase_ticket(jason.user_id, "NORMAL")

        # LISA
        lisa = await user_service.create_user(DEMO_USERS[3]["user_name"], DEMO_USERS[3]["user_mail"],
                                              DEMO_USERS[3]["password_clear_text"])
        await accounting_service.add_balance(lisa.user_id, Decimal("1000.00"), "DEMO EINZAHLUNG")
        lisa.is_team_member = True
        await user_service.update_user(lisa)

        # THOMAS
        thomas = await user_service.create_user(DEMO_USERS[4]["user_name"], DEMO_USERS[4]["user_mail"],
                                                DEMO_USERS[4]["password_clear_text"])
        await accounting_service.add_balance(thomas.user_id, Decimal("1000.00"), "DEMO EINZAHLUNG")
        thomas.is_team_member = True
        thomas.is_admin = True
        await user_service.update_user(thomas)

    if not input("Generate catering menu? (Y/n): ").lower() == "n":
        # MAIN_COURSE
        await catering_service.add_menu_item("Schnitzel Wiener Art", "mit Pommes", Decimal("10.00"),
                                             CateringMenuItemCategory.MAIN_COURSE)
        await catering_service.add_menu_item("Jäger Schnitzel mit Champignonrahm Sauce", "mit Pommes", Decimal("11.50"),
                                             CateringMenuItemCategory.MAIN_COURSE)
        await catering_service.add_menu_item("Tortellini in Käsesauce mit Fleischfüllung", "", Decimal("10.50"),
                                             CateringMenuItemCategory.MAIN_COURSE)
        await catering_service.add_menu_item("Tortellini in Käsesauce ohne Fleischfüllung", "Vegetarisch", Decimal("10.50"),
                                             CateringMenuItemCategory.MAIN_COURSE)

        # SNACK
        await catering_service.add_menu_item("Käse Schinken Wrap", "", Decimal("5.00"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Puten Paprika Wrap", "", Decimal("7.00"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Tomate Mozzarella Wrap", "", Decimal("6.00"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Portion Pommes", "", Decimal("4.00"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Rinds-Currywurst", "", Decimal("4.50"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Rinds-Currywurst mit Pommes", "", Decimal("6.50"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Nudelsalat", "", Decimal("4.50"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Nudelsalat mit Bockwurst", "", Decimal("6.00"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Kartoffelsalat", "", Decimal("4.50"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Kartoffelsalat mit Bockwurst", "", Decimal("6.00"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Sandwichtoast - Schinken", "", Decimal("1.80"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Sandwichtoast - Käse", "", Decimal("1.80"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Sandwichtoast - Schinken/Käse", "", Decimal("2.10"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Sandwichtoast - Salami", "", Decimal("1.80"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Sandwichtoast - Salami/Käse", "", Decimal("2.10"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Chips - Western Style", "", Decimal("1.30"), CateringMenuItemCategory.SNACK)
        await catering_service.add_menu_item("Nachos - Salted", "", Decimal("1.30"), CateringMenuItemCategory.SNACK)

        # DESSERT
        await catering_service.add_menu_item("Panna Cotta mit Erdbeersauce", "", Decimal("7.00"), CateringMenuItemCategory.DESSERT)
        await catering_service.add_menu_item("Panna Cotta mit Blaubeersauce", "", Decimal("7.00"), CateringMenuItemCategory.DESSERT)
        await catering_service.add_menu_item("Mousse au Chocolat", "", Decimal("7.00"), CateringMenuItemCategory.DESSERT)

        # BREAKFAST
        await catering_service.add_menu_item("Fruit Loops", "", Decimal("1.50"), CateringMenuItemCategory.BREAKFAST)
        await catering_service.add_menu_item("Smacks", "", Decimal("1.50"), CateringMenuItemCategory.BREAKFAST)
        await catering_service.add_menu_item("Knuspermüsli", "Schoko", Decimal("2.00"), CateringMenuItemCategory.BREAKFAST)
        await catering_service.add_menu_item("Cini Minis", "", Decimal("2.50"), CateringMenuItemCategory.BREAKFAST)
        await catering_service.add_menu_item("Brötchen - Schinken", "mit Margarine", Decimal("1.20"),
                                             CateringMenuItemCategory.BREAKFAST)
        await catering_service.add_menu_item("Brötchen - Käse", "mit Margarine", Decimal("1.20"),
                                             CateringMenuItemCategory.BREAKFAST)
        await catering_service.add_menu_item("Brötchen - Schinken/Käse", "mit Margarine", Decimal("1.40"),
                                             CateringMenuItemCategory.BREAKFAST)
        await catering_service.add_menu_item("Brötchen - Salami", "mit Margarine", Decimal("1.20"),
                                             CateringMenuItemCategory.BREAKFAST)
        await catering_service.add_menu_item("Brötchen - Salami/Käse", "mit Margarine", Decimal("1.40"),
                                             CateringMenuItemCategory.BREAKFAST)
        await catering_service.add_menu_item("Brötchen - Nutella", "mit Margarine", Decimal("1.20"),
                                             CateringMenuItemCategory.BREAKFAST)

        # BEVERAGE_NON_ALCOHOLIC
        await catering_service.add_menu_item("Wasser - Still", "1L Flasche", Decimal("2.00"),
                                             CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
        await catering_service.add_menu_item("Wasser - Medium", "1L Flasche", Decimal("2.00"),
                                             CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
        await catering_service.add_menu_item("Wasser - Spritzig", "1L Flasche", Decimal("2.00"),
                                             CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
        await catering_service.add_menu_item("Coca-Cola", "1L Flasche", Decimal("2.00"),
                                             CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
        await catering_service.add_menu_item("Coca-Cola Zero", "1L Flasche", Decimal("2.00"),
                                             CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
        await catering_service.add_menu_item("Fanta", "1L Flasche", Decimal("2.00"),
                                             CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
        await catering_service.add_menu_item("Sprite", "1L Flasche", Decimal("2.00"),
                                             CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
        await catering_service.add_menu_item("Spezi", "von Paulaner, 0,5L Flasche", Decimal("1.50"),
                                             CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
        await catering_service.add_menu_item("Red Bull", "", Decimal("2.00"), CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
        await catering_service.add_menu_item("Energy", "Hausmarke", Decimal("1.50"),
                                             CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)

        # BEVERAGE_ALCOHOLIC
        await catering_service.add_menu_item("Pils", "0,33L Flasche", Decimal("1.90"), CateringMenuItemCategory.BEVERAGE_ALCOHOLIC)
        await catering_service.add_menu_item("Radler", "0,33L Flasche", Decimal("1.90"),
                                             CateringMenuItemCategory.BEVERAGE_ALCOHOLIC)
        await catering_service.add_menu_item("Diesel", "0,33L Flasche", Decimal("1.90"),
                                             CateringMenuItemCategory.BEVERAGE_ALCOHOLIC)
        await catering_service.add_menu_item("Apfelwein Pur", "0,33L Flasche", Decimal("1.90"),
                                             CateringMenuItemCategory.BEVERAGE_ALCOHOLIC)
        await catering_service.add_menu_item("Apfelwein Sauer", "0,33L Flasche", Decimal("1.90"),
                                             CateringMenuItemCategory.BEVERAGE_ALCOHOLIC)
        await catering_service.add_menu_item("Apfelwein Cola", "0,33L Flasche", Decimal("1.90"),
                                             CateringMenuItemCategory.BEVERAGE_ALCOHOLIC)

        # BEVERAGE_COCKTAIL
        await catering_service.add_menu_item("Vodka Energy", "", Decimal("4.00"), CateringMenuItemCategory.BEVERAGE_COCKTAIL)
        await catering_service.add_menu_item("Vodka O-Saft", "", Decimal("4.00"), CateringMenuItemCategory.BEVERAGE_COCKTAIL)
        await catering_service.add_menu_item("Whiskey Cola", "mit Bourbon", Decimal("4.00"),
                                             CateringMenuItemCategory.BEVERAGE_COCKTAIL)
        await catering_service.add_menu_item("Jägermeister Energy", "", Decimal("4.00"), CateringMenuItemCategory.BEVERAGE_COCKTAIL)
        await catering_service.add_menu_item("Sex on the Beach", "", Decimal("5.50"), CateringMenuItemCategory.BEVERAGE_COCKTAIL)
        await catering_service.add_menu_item("Long Island Ice Tea", "", Decimal("5.50"), CateringMenuItemCategory.BEVERAGE_COCKTAIL)
        await catering_service.add_menu_item("Caipirinha", "", Decimal("5.50"), CateringMenuItemCategory.BEVERAGE_COCKTAIL)

        # BEVERAGE_SHOT
        await catering_service.add_menu_item("Jägermeister", "", Decimal("2.00"), CateringMenuItemCategory.BEVERAGE_SHOT)
        await catering_service.add_menu_item("Tequila", "", Decimal("2.00"), CateringMenuItemCategory.BEVERAGE_SHOT)
        await catering_service.add_menu_item("PfEZzi", "Getunter Pfefferminz-Schnaps", Decimal("1.99"),
                                             CateringMenuItemCategory.BEVERAGE_SHOT)

        # NON_FOOD
        await catering_service.add_menu_item("Zigaretten", "Elixyr", Decimal("8.00"), CateringMenuItemCategory.NON_FOOD)
        await catering_service.add_menu_item("Mentholfilter", "passend für Elixyr", Decimal("1.20"),
                                             CateringMenuItemCategory.NON_FOOD)

    if not input("Generate default new post? (Y/n): ").lower() == "n":
        loops = 0
        user = None
        while loops < 1000:
            user = await user_service.get_user(loops)
            if user is not None:
                break
            loops += 1

        if user is None:
            sys.exit("Database does not contain users! Exiting...")

        await news_service.add_news(News(
            news_id=None,
            title="Der EZGG LAN Manager",
            subtitle="Eine Software des EZ GG e.V.",
            content="Dies ist eine WIP-Version des EZGG LAN Managers. Diese Software soll uns helfen in Zukunft die LAN "
                    "Parties des EZ GG e.V.'s zu organisieren. Wer Fehler findet darf sie behalten. (Oder er meldet "
                    "sie)",
            author=user,
            news_date=date.today()
        ))


if __name__ == "__main__":
    with asyncio.Runner() as loop:
        loop.run(run())
